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

* [MNT-24082] fix aspect overwriting from dialog

* [MNT-24028] address comments, improve unit tests
This commit is contained in:
Grzegorz Jaśkowski
2024-03-04 11:45:41 +01:00
committed by GitHub
parent ca892fc8fa
commit 9e4569d7ca
2 changed files with 30 additions and 26 deletions

View File

@@ -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);
});
@@ -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', () => {

View File

@@ -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>();
@@ -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$));
@@ -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();
}
@@ -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 {