forked from help-me-mom/ng-mocks
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(a16): supporting required inputs help-me-mom#5350
- Loading branch information
Showing
27 changed files
with
2,467 additions
and
10,199 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
import { Input } from '@angular/core'; | ||
|
||
import { AnyType } from './core.types'; | ||
import { AnyType, DirectiveIo } from './core.types'; | ||
import funcDirectiveIoBuild from './func.directive-io-build'; | ||
import funcDirectiveIoParse from './func.directive-io-parse'; | ||
|
||
// Looks like an A9 bug, that queries from @Component are not processed. | ||
// Also we have to pass prototype, not the class. | ||
// Also, we have to pass prototype, not the class. | ||
// The same issue happens with outputs, but time to time | ||
// (when I restart tests with refreshing browser manually). | ||
// https://github.com/help-me-mom/ng-mocks/issues/109 | ||
export default (cls: AnyType<any>, inputs?: string[], exclude?: string[]) => { | ||
export default (cls: AnyType<any>, inputs?: Array<DirectiveIo>, exclude?: string[]) => { | ||
// istanbul ignore else | ||
if (inputs) { | ||
for (const input of inputs) { | ||
const [key, alias] = input.split(': '); | ||
if (exclude && exclude.indexOf(key) !== -1) { | ||
const { name, alias, required } = funcDirectiveIoParse(input); | ||
if (exclude && exclude.indexOf(name) !== -1) { | ||
continue; | ||
} | ||
Input(alias)(cls.prototype, key); | ||
Input(funcDirectiveIoBuild({ name, alias, required }, true) as never)(cls.prototype, name); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import { Output } from '@angular/core'; | ||
|
||
import { AnyType } from './core.types'; | ||
import { AnyType, DirectiveIo } from './core.types'; | ||
import funcDirectiveIoBuild from './func.directive-io-build'; | ||
import funcDirectiveIoParse from './func.directive-io-parse'; | ||
|
||
// Looks like an A9 bug, that queries from @Component are not processed. | ||
// Also we have to pass prototype, not the class. | ||
// Also, we have to pass prototype, not the class. | ||
// The same issue happens with outputs, but time to time | ||
// (when I restart tests with refreshing browser manually). | ||
// https://github.com/help-me-mom/ng-mocks/issues/109 | ||
export default (cls: AnyType<any>, outputs?: string[]) => { | ||
export default (cls: AnyType<any>, outputs?: Array<DirectiveIo>) => { | ||
// istanbul ignore else | ||
if (outputs) { | ||
for (const output of outputs) { | ||
const [key, alias] = output.split(': '); | ||
Output(alias)(cls.prototype, key); | ||
const { name, alias, required } = funcDirectiveIoParse(output); | ||
Output(funcDirectiveIoBuild({ name, alias, required }, true) as never)(cls.prototype, name); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { DirectiveIo, DirectiveIoParsed } from './core.types'; | ||
|
||
export default function ({ name, alias, required }: DirectiveIoParsed, skipName = false): DirectiveIo { | ||
if (required) { | ||
return { name, alias, required }; | ||
} | ||
if (!alias || name === alias) { | ||
return skipName ? '' : name; | ||
} | ||
|
||
return skipName ? alias : `${name}:${alias}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { DirectiveIo, DirectiveIoParsed } from './core.types'; | ||
|
||
export default function (param: DirectiveIo): DirectiveIoParsed { | ||
if (typeof param === 'string') { | ||
const [name, alias] = param.split(':').map(v => v.trim()); | ||
|
||
if (name === alias || !alias) { | ||
return { name }; | ||
} | ||
|
||
return { name, alias }; | ||
} | ||
|
||
return param; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
libs/ng-mocks/src/lib/mock-helper/crawl/func.parse-inputs-and-requires-attributes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.