Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNT-24082] fix aspect overwriting from dialog #9390

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('AspectListComponent', () => {
spyOn(aspectListService, 'getCustomAspects').and.returnValue(of(customAspectListMock));
spyOn(aspectListService, 'getVisibleAspects').and.returnValue(['frs:AspectOne']);
nodeService = TestBed.inject(NodesApiService);
spyOn(nodeService, 'getNode').and.returnValue(of({ id: 'fake-node-id', aspectNames: ['frs:AspectOne'] } as any));
spyOn(nodeService, 'getNode').and.returnValue(of({ id: 'fake-node-id', aspectNames: ['frs:AspectOne', 'stored:aspect'] } as any));
component.nodeId = 'fake-node-id';
loader = TestbedHarnessEnvironment.loader(fixture);
});
Expand Down Expand Up @@ -187,69 +187,71 @@ describe('AspectListComponent', () => {
expect(noNameAspect.innerText).toBe('cst:nonamedAspect');
});

it('should show the details when a row is clicked', async () => {
it('should show aspect`s properties in expanded aspect panel', async () => {
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();
expect(await panel.getDescription()).not.toBeNull();

const table = await panel.getHarness(MatTableHarness);
const [row1, row2] = await table.getRows();
const [r1c1, r1c2, r1c3] = await row1.getCells();
const [r2c1, r2c2, r2c3] = await row2.getCells();
expect(await r1c1.getText()).toBe('channelPassword');
expect(await r1c2.getText()).toBe('The authenticated channel password');
expect(await r1c3.getText()).toBe('d:propA');

const [r2c1, r2c2, r2c3] = await row2.getCells();
expect(await r2c1.getText()).toBe('channelUsername');
expect(await r2c2.getText()).toBe('The authenticated channel username');
expect(await r2c3.getText()).toBe('d:propB');
});

it('should show as checked the node properties', async () => {
it('should show node aspects as checked', async () => {
const panel = await loader.getHarness(MatExpansionPanelHarness);
await panel.expand();

const checkbox = await panel.getHarness(MatCheckboxHarness);
expect(await checkbox.isChecked()).toBe(true);
});

it('should remove aspects unchecked', async () => {
const panel = await loader.getAllHarnesses(MatExpansionPanelHarness);
await panel[1].expand();

const checkbox = await panel[1].getHarness(MatCheckboxHarness);
it('should add checked and remove unchecked aspects', async () => {
const panel = (await loader.getAllHarnesses(MatExpansionPanelHarness))[1];
const checkbox = await panel.getHarness(MatCheckboxHarness);
expect(await checkbox.isChecked()).toBe(false);

await checkbox.toggle();

expect(component.nodeAspects.length).toBe(2);
expect(component.nodeAspects[1]).toBe('frs:SecondAspect');

await checkbox.toggle();

expect(component.nodeAspects.length).toBe(1);
expect(component.nodeAspects[0]).toBe('frs:AspectOne');
});

it('should reset the properties on reset', async () => {
const panel = await loader.getAllHarnesses(MatExpansionPanelHarness);
await panel[1].expand();

const checkbox = await panel[1].getHarness(MatCheckboxHarness);
it('should reset aspects on reset', async () => {
const panel = (await loader.getAllHarnesses(MatExpansionPanelHarness))[1];
const checkbox = await panel.getHarness(MatCheckboxHarness);
expect(await checkbox.isChecked()).toBe(false);

await checkbox.toggle();

expect(component.nodeAspects.length).toBe(2);

component.reset();
expect(component.nodeAspects.length).toBe(1);
});

it('should clear all the properties on clear', async () => {
it('should clear all aspects on clear', async () => {
expect(component.nodeAspects.length).toBe(1);
component.clear();
expect(component.nodeAspects.length).toBe(0);
});

it('should store not listed aspects and emit all aspects on value change', async () => {
const storedAspect = ['stored:aspect'];
expect(component.notDisplayedAspects).toEqual(storedAspect);

spyOn(component.valueChanged, 'emit');
const panel = (await loader.getAllHarnesses(MatExpansionPanelHarness))[1];
const checkbox = await panel.getHarness(MatCheckboxHarness);
await checkbox.toggle();
fixture.detectChanges();
expect(component.valueChanged.emit).toHaveBeenCalledWith(['frs:AspectOne', 'frs:SecondAspect', ...storedAspect]);
});
});

describe('with excluded aspects', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class AspectListComponent implements OnInit, OnDestroy {
aspects$: Observable<AspectEntry[]> = null;
nodeAspects: string[] = [];
nodeAspectStatus: string[] = [];
notDisplayedAspects: string[] = [];
hasEqualAspect: boolean = true;

private onDestroy$ = new Subject<boolean>();
Expand All @@ -71,7 +72,8 @@ export class AspectListComponent implements OnInit, OnDestroy {
tap(([node, customAspects]) => {
this.nodeAspects = node.aspectNames.filter((aspect) => this.aspectListService.getVisibleAspects().includes(aspect) || customAspects.includes(aspect));
this.nodeAspectStatus = [ ...this.nodeAspects ];
this.valueChanged.emit(this.nodeAspects);
this.notDisplayedAspects = node.aspectNames.filter((aspect) => !this.aspectListService.getVisibleAspects().includes(aspect) && !customAspects.includes(aspect));
this.valueChanged.emit([...this.nodeAspects, ...this.notDisplayedAspects]);
}),
concatMap(() => this.aspectListService.getAspects()),
takeUntil(this.onDestroy$));
Expand All @@ -94,14 +96,14 @@ export class AspectListComponent implements OnInit, OnDestroy {
this.nodeAspects.splice(this.nodeAspects.indexOf(prefixedName), 1);
}
this.updateEqualityOfAspectList();
this.valueChanged.emit(this.nodeAspects);
this.valueChanged.emit([...this.nodeAspects, ...this.notDisplayedAspects]);
}

reset() {
if (this.nodeAspectStatus && this.nodeAspectStatus.length > 0) {
this.nodeAspects.splice(0, this.nodeAspects.length, ...this.nodeAspectStatus);
this.hasEqualAspect = true;
this.valueChanged.emit(this.nodeAspects);
this.valueChanged.emit([...this.nodeAspects, ...this.notDisplayedAspects]);
} else {
this.clear();
}
Expand All @@ -110,7 +112,7 @@ export class AspectListComponent implements OnInit, OnDestroy {
clear() {
this.nodeAspects = [];
this.updateEqualityOfAspectList();
this.valueChanged.emit(this.nodeAspects);
this.valueChanged.emit([...this.nodeAspects, ...this.notDisplayedAspects]);
}

getId(aspect: any): string {
Expand Down
Loading