Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions api-goldens/element-ng/split/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class SiSplitPartComponent {
readonly collapseLabel: _angular_core.InputSignal<TranslatableString>;
readonly collapseOthers: _angular_core.InputSignalWithTransform<boolean, unknown>;
readonly collapseToMinSize: _angular_core.InputSignalWithTransform<boolean, unknown>;
readonly collapsible: _angular_core.InputSignal<CollapseTo>;
readonly collapsible: _angular_core.InputSignal<CollapseTo | undefined>;
readonly expanded: _angular_core.InputSignalWithTransform<boolean, unknown>;
readonly headerTemplate: _angular_core.InputSignal<TemplateRef<{
$implicit: SiSplitPartComponent;
Expand All @@ -65,7 +65,6 @@ export class SiSplitPartComponent {
readonly minSize: _angular_core.InputSignalWithTransform<number, unknown>;
readonly removeContentOnCollapse: _angular_core.InputSignalWithTransform<boolean, unknown>;
readonly scale: _angular_core.InputSignal<Scale>;
readonly showCollapseButton: _angular_core.InputSignalWithTransform<boolean, unknown>;
readonly showHeader: _angular_core.InputSignalWithTransform<boolean, unknown>;
readonly size: _angular_core.InputSignalWithTransform<number, string | number>;
readonly stateChange: _angular_core.OutputEmitterRef<PartState>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
scale="none"
unit="fr"
[size]="splitSizes()[0]"
[showCollapseButton]="false"
[showHeader]="false"
[minSize]="minListSize()"
[stateId]="listStateId()"
Expand All @@ -20,7 +19,6 @@
scale="auto"
unit="fr"
[size]="splitSizes()[1]"
[showCollapseButton]="false"
[showHeader]="false"
[minSize]="minDetailsSize()"
[stateId]="detailsStateId()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
scale="none"
unit="fr"
[size]="splitSizes[0]"
[showCollapseButton]="false"
[showHeader]="false"
[minSize]="minMainSize()"
[stateId]="mainStateId()"
Expand All @@ -22,7 +21,6 @@
scale="auto"
unit="fr"
[size]="splitSizes[1]"
[showCollapseButton]="false"
[showHeader]="false"
[minSize]="minDetailSize()"
[stateId]="detailStateId()"
Expand Down
156 changes: 130 additions & 26 deletions projects/element-ng/schematics/ng-update/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const appConfig: ApplicationConfig = {

@Component({
selector: 'app-split',
template: \`<si-split [sizes]="[20, 60, 20]">
template: \`<si-split [sizes]="[20, 60, 30]">
<si-split-part>Left</si-split-part>
<si-split-part>Center</si-split-part>
<si-split-part>Right</si-split-part>
Expand All @@ -108,9 +108,9 @@ export class SplitComponent {}`
const modifiedContent = tree.readContent('/projects/app/src/split.component.ts');

expect(modifiedContent).not.toContain('[sizes]');
expect(modifiedContent).toContain('<si-split-part size="20" unit="fr">Left</si-split-part>');
expect(modifiedContent).toContain('<si-split-part size="60" unit="fr">Center</si-split-part>');
expect(modifiedContent).toContain('<si-split-part size="20" unit="fr">Right</si-split-part>');
expect(modifiedContent).toContain('<si-split-part size="20" unit="fr"');
expect(modifiedContent).toContain('<si-split-part size="60" unit="fr"');
expect(modifiedContent).toContain('<si-split-part size="30" unit="fr"');
});

it('should move expression split sizes to external split parts', async () => {
Expand All @@ -132,12 +132,8 @@ export class SplitComponent {}`,
const modifiedContent = tree.readContent('/projects/app/src/split.component.html');

expect(modifiedContent).not.toContain('[sizes]');
expect(modifiedContent).toContain(
'<si-split-part [size]="panelSizes[0]" unit="fr">Left</si-split-part>'
);
expect(modifiedContent).toContain(
'<si-split-part [size]="panelSizes[1]" unit="fr">Right</si-split-part>'
);
expect(modifiedContent).toContain('<si-split-part [size]="panelSizes[0]" unit="fr"');
expect(modifiedContent).toContain('<si-split-part [size]="panelSizes[1]" unit="fr"');
});

it('should pass options to sub-migrations', async () => {
Expand Down Expand Up @@ -168,8 +164,8 @@ export class SplitComponent {}`
const tree = await runner.runSchematic('migration-v51', {}, appTree);
const modifiedContent = tree.readContent('/projects/app/src/split.component.ts');

expect(modifiedContent).toContain('<si-split-part size="300" unit="px">Left</si-split-part>');
expect(modifiedContent).toContain('<si-split-part size="200" unit="px">Right</si-split-part>');
expect(modifiedContent).toContain('<si-split-part size="300" unit="px"');
expect(modifiedContent).toContain('<si-split-part size="200" unit="px"');
});

it('should add unit="px" to a split part with a bound size but no unit (external template)', async () => {
Expand All @@ -190,12 +186,8 @@ export class SplitComponent {}`,
const tree = await runner.runSchematic('migration-v51', {}, appTree);
const modifiedContent = tree.readContent('/projects/app/src/split.component.html');

expect(modifiedContent).toContain(
'<si-split-part [size]="leftSize" unit="px">Left</si-split-part>'
);
expect(modifiedContent).toContain(
'<si-split-part [size]="rightSize" unit="px">Right</si-split-part>'
);
expect(modifiedContent).toContain('<si-split-part [size]="leftSize" unit="px"');
expect(modifiedContent).toContain('<si-split-part [size]="rightSize" unit="px"');
});

it('should not add unit="px" when unit is already present', async () => {
Expand All @@ -209,10 +201,8 @@ export class SplitComponent {}`,
const tree = await runner.runSchematic('migration-v51', {}, appTree);
const modifiedContent = tree.readContent('/projects/app/src/split.component.html');

expect(modifiedContent).toContain('<si-split-part size="20" unit="fr">Left</si-split-part>');
expect(modifiedContent).toContain(
'<si-split-part [size]="rightSize" [unit]="unitVal">Right</si-split-part>'
);
expect(modifiedContent).toContain('<si-split-part size="20" unit="fr"');
expect(modifiedContent).toContain('<si-split-part [size]="rightSize" [unit]="unitVal"');
});

it('should add unit="fr" when converting [sizes] and not duplicate with unit="px"', async () => {
Expand All @@ -234,8 +224,8 @@ export class SplitComponent {}`,
const modifiedContent = tree.readContent('/projects/app/src/split.component.html');

expect(modifiedContent).not.toContain('[sizes]');
expect(modifiedContent).toContain('<si-split-part size="30" unit="fr">Left</si-split-part>');
expect(modifiedContent).toContain('<si-split-part size="70" unit="fr">Right</si-split-part>');
expect(modifiedContent).toContain('<si-split-part size="30" unit="fr"');
expect(modifiedContent).toContain('<si-split-part size="70" unit="fr"');
expect(modifiedContent).not.toContain('unit="px"');
});

Expand All @@ -257,8 +247,8 @@ export class SplitComponent {}`,
const tree = await runner.runSchematic('migration-v51', {}, appTree);
const modifiedContent = tree.readContent('/projects/app/src/split.component.html');

expect(modifiedContent).toContain('<si-split-part size="400" heading="Left" unit="px"/>');
expect(modifiedContent).toContain('<si-split-part size="200" heading="Right" unit="px"/>');
expect(modifiedContent).toContain('<si-split-part size="400" heading="Left" unit="px"');
expect(modifiedContent).toContain('<si-split-part size="200" heading="Right" unit="px"');
});

it('should rename split collapse bindings and CollapseTo literals', async () => {
Expand Down Expand Up @@ -303,4 +293,118 @@ export class ExternalSplitComponent {}`,
expect(template).toContain('<si-split-part collapsible="to-end" />');
expect(template).toContain('<div collapseDirection="start"></div>');
});

it('should add the former default collapse direction to collapsible split parts', async () => {
addTestFiles(appTree, {
'/projects/app/src/split.component.ts': `import { Component } from '@angular/core';

@Component({
selector: 'app-split',
template: \`<si-split-part />
<si-split-part showCollapseButton />
<si-split-part showCollapseButton="true" />
<si-split-part [showCollapseButton]="true" />\`
})
export class SplitComponent {}`
});

const tree = await runner.runSchematic('migration-v51', {}, appTree);
const component = tree.readContent('/projects/app/src/split.component.ts');

expect(component).not.toContain('showCollapseButton');
expect(component.match(/collapsible="to-start"/g)).toHaveLength(4);
});

it('should remove false collapse buttons and their legacy directions', async () => {
addTestFiles(appTree, {
'/projects/app/src/split.component.ts': `import { Component } from '@angular/core';

@Component({
selector: 'app-split',
template: \`<si-split-part showCollapseButton="false" collapseDirection="start" />
<si-split-part [showCollapseButton]="'false'" [collapseDirection]="'end'" />
<si-split-part showCollapseButton="false" />\`
})
export class SplitComponent {}`,
'/projects/app/src/external-split.component.ts': `import { Component } from '@angular/core';

@Component({
selector: 'app-external-split',
templateUrl: './split.component.html'
})
export class ExternalSplitComponent {}`,
'/projects/app/src/split.component.html': `<si-split-part
heading="Details"
[showCollapseButton]="false"
[collapseDirection]="'end'"
>
<p>Content</p>
</si-split-part>`
});

const tree = await runner.runSchematic('migration-v51', {}, appTree);
const component = tree.readContent('/projects/app/src/split.component.ts');
const template = tree.readContent('/projects/app/src/split.component.html');

expect(component).not.toContain('showCollapseButton');
expect(component).not.toContain('collapseDirection');
expect(component).not.toContain('collapsible');
expect(template).toBe(`<si-split-part
heading="Details"
>
<p>Content</p>
</si-split-part>`);
});

it('should conditionally migrate dynamic collapse button bindings', async () => {
addTestFiles(appTree, {
'/projects/app/src/split.component.ts': `import { Component } from '@angular/core';

@Component({
selector: 'app-split',
template: \`<si-split-part [showCollapseButton]="canCollapse" />
<si-split-part [showCollapseButton]="canCollapse" collapseDirection="end" />
<si-split-part [showCollapseButton]="canCollapse" [collapseDirection]="direction" />
<div [showCollapseButton]="canCollapse"></div>\`
})
export class SplitComponent {
readonly canCollapse = false;
readonly direction = 'end';
}`
});

const tree = await runner.runSchematic('migration-v51', {}, appTree);
const component = tree.readContent('/projects/app/src/split.component.ts');

const condition = `![false, null, undefined, 'false'].includes($any(canCollapse))`;
expect(component).toContain(`[collapsible]="${condition} ? 'to-start' : undefined"`);
expect(component).toContain(`[collapsible]="${condition} ? 'to-end' : undefined"`);
expect(component).toContain(`[collapsible]="${condition} ? (direction) : undefined"`);
expect(component).toContain('<div [showCollapseButton]="canCollapse"></div>');
expect(component.match(/showCollapseButton/g)).toHaveLength(1);
expect(component).not.toContain('collapseDirection');
});

it('should preserve an explicit collapsible input when removing showCollapseButton=false', async () => {
addTestFiles(appTree, {
'/projects/app/src/split.component.ts': `import { Component } from '@angular/core';

@Component({
selector: 'app-split',
template: \`<si-split-part showCollapseButton="false" collapsible="to-end" />\`
})
export class SplitComponent {}`
});

const tree = await runner.runSchematic('migration-v51', {}, appTree);
const component = tree.readContent('/projects/app/src/split.component.ts');

expect(component).toBe(`import { Component } from '@angular/core';

@Component({
selector: 'app-split',
template: \`<si-split-part collapsible="to-end" />\`
})
export class SplitComponent {}`);
});
});
Loading
Loading