Skip to content

Commit dd3dba9

Browse files
authored
fix(migrations): duplicate card actions migrations (#13009)
1 parent 0c2956a commit dd3dba9

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

projects/igniteui-angular/migrations/update-15_1_0/index.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,36 @@ describe(`Update to ${version}`, () => {
218218
);
219219
});
220220

221+
it('shouldn\'t append igxStart and igxEnd directives to the child elements of the igx-card-actions if already applied', async () => {
222+
appTree.create(`/testSrc/appPrefix/component/test.component.html`,
223+
`
224+
<igx-card-actions>
225+
<span igxButton igxStart>Span</span>
226+
<button igxButton igxStart>Button</button>
227+
<button igxButton="icon" igxEnd>
228+
<igx-icon>favorite</igx-icon>
229+
</button>
230+
<igx-icon igxEnd>drag_indicator</igx-icon>
231+
</igx-card-actions>
232+
`
233+
);
234+
235+
const tree = await schematicRunner.runSchematic(migrationName, { shouldInvokeLS: false }, appTree);
236+
237+
expect(tree.readContent('/testSrc/appPrefix/component/test.component.html')).toEqual(
238+
`
239+
<igx-card-actions>
240+
<span igxButton igxStart>Span</span>
241+
<button igxButton igxStart>Button</button>
242+
<button igxButton="icon" igxEnd>
243+
<igx-icon>favorite</igx-icon>
244+
</button>
245+
<igx-icon igxEnd>drag_indicator</igx-icon>
246+
</igx-card-actions>
247+
`
248+
);
249+
});
250+
221251
it('should rename the $size property to the $scrollbar-size', async () => {
222252
appTree.create(
223253
`/testSrc/appPrefix/component/test.component.scss`,

projects/igniteui-angular/migrations/update-15_1_0/index.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default (options: Options): Rule => async (host: Tree, context: Schematic
2020
const CARD_ACTIONS = ['igx-card-actions'];
2121
const prop = ['igxButton'];
2222
const changes = new Map<string, FileChange[]>();
23-
23+
2424
const applyChanges = () => {
2525
for (const [path, change] of changes.entries()) {
2626
let buffer = host.read(path).toString();
@@ -57,25 +57,34 @@ export default (options: Options): Rule => async (host: Tree, context: Schematic
5757
const icons: any[] = [];
5858
getChildren(card_action_elem, buttons, icons);
5959

60-
icons.map(node =>getSourceOffset(node as Element))
60+
icons.map(node => getSourceOffset(node as Element))
6161
.forEach(offset => {
62-
const { startTag, file } = offset;
63-
addChange(file.url, new FileChange(startTag.end - 1, ' igxEnd'));
62+
const { startTag, file, node } = offset;
63+
const end = getAttribute(node, 'igxEnd')[0];
64+
65+
if (!end) {
66+
addChange(file.url, new FileChange(startTag.end - 1, ' igxEnd'));
67+
}
6468
})
65-
69+
6670
buttons.map(node => getSourceOffset(node as Element))
6771
.forEach(offset => {
6872
const { startTag, file, node } = offset;
6973
const { value } = getAttribute(node, prop)[0];
70-
if (value === 'icon') {
71-
addChange(file.url, new FileChange(startTag.end - 1, ' igxEnd'));
72-
} else {
74+
const start = getAttribute(node, 'igxStart')[0];
75+
const end = getAttribute(node, 'igxEnd')[0];
76+
77+
if (!start && value !== 'icon') {
7378
addChange(file.url, new FileChange(startTag.end - 1, ' igxStart'));
7479
}
80+
81+
if (!end && value === 'icon') {
82+
addChange(file.url, new FileChange(startTag.end - 1, ' igxEnd'));
83+
}
7584
});
7685
});
7786
}
78-
87+
7988
update.shouldInvokeLS = options['shouldInvokeLS'];
8089
update.addValueTransform('roundShape_is_deprecated', (args: BoundPropertyObject): void => {
8190
args.bindingType = InputPropertyType.STRING;

0 commit comments

Comments
 (0)