From 7f7ed17d6e54e965b899f472ffa9689fc3665af9 Mon Sep 17 00:00:00 2001 From: Nona Luypaert Date: Fri, 21 Apr 2023 09:11:28 +0200 Subject: [PATCH] 101127: Add multiSelect tests in VocabularyTreeviewComponent --- .../vocabulary-treeview.component.spec.ts | 60 ++++++++++++++++--- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.spec.ts b/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.spec.ts index 043ff9ea56..29e80cfc94 100644 --- a/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.spec.ts +++ b/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.spec.ts @@ -12,7 +12,7 @@ import { createTestComponent } from '../../testing/utils.test'; import { VocabularyTreeviewComponent } from './vocabulary-treeview.component'; import { VocabularyTreeviewService } from './vocabulary-treeview.service'; import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/models/vocabulary-entry-detail.model'; -import { TreeviewFlatNode } from './vocabulary-treeview-node.model'; +import { TreeviewFlatNode, TreeviewNode } from './vocabulary-treeview-node.model'; import { FormFieldMetadataValueObject } from '../builder/models/form-field-metadata-value.model'; import { VocabularyOptions } from '../../../core/submission/vocabularies/models/vocabulary-options.model'; import { PageInfo } from '../../../core/shared/page-info.model'; @@ -20,6 +20,7 @@ import { VocabularyEntry } from '../../../core/submission/vocabularies/models/vo import { AuthTokenInfo } from '../../../core/auth/models/auth-token-info.model'; import { authReducer } from '../../../core/auth/auth.reducer'; import { storeModuleConfig } from '../../../app.reducer'; +import { By } from '@angular/platform-browser'; describe('VocabularyTreeviewComponent test suite', () => { @@ -27,6 +28,7 @@ describe('VocabularyTreeviewComponent test suite', () => { let compAsAny: any; let fixture: ComponentFixture; let initialState; + let de; const item = new VocabularyEntryDetail(); item.id = 'node1'; @@ -87,6 +89,12 @@ describe('VocabularyTreeviewComponent test suite', () => { }); })); + afterEach(() => { + fixture.destroy(); + comp = null; + compAsAny = null; + }); + describe('', () => { let testComp: TestComponent; let testFixture: ComponentFixture; @@ -120,12 +128,6 @@ describe('VocabularyTreeviewComponent test suite', () => { comp.selectedItems = []; }); - afterEach(() => { - fixture.destroy(); - comp = null; - compAsAny = null; - }); - it('should should init component properly', () => { fixture.detectChanges(); expect(comp.dataSource.data).toEqual([]); @@ -229,6 +231,50 @@ describe('VocabularyTreeviewComponent test suite', () => { expect(vocabularyTreeviewServiceStub.cleanTree).toHaveBeenCalled(); }); }); + + describe('', () => { + beforeEach(() => { + vocabularyTreeviewServiceStub.getData.and.returnValue(observableOf([ + { + 'item': { + 'id': 'srsc:SCB11', + 'display': 'HUMANITIES and RELIGION' + } + } as TreeviewNode, + { + 'item': { + 'id': 'srsc:SCB12', + 'display': 'LAW/JURISPRUDENCE' + } + } as TreeviewNode, + { + 'item': { + 'id': 'srsc:SCB13', + 'display': 'SOCIAL SCIENCES' + } + } as TreeviewNode, + ])); + fixture = TestBed.createComponent(VocabularyTreeviewComponent); + comp = fixture.componentInstance; + compAsAny = comp; + comp.vocabularyOptions = vocabularyOptions; + comp.selectedItems = []; + de = fixture.debugElement; + }); + + it('should not display checkboxes by default', async () => { + fixture.detectChanges(); + expect(de.query(By.css('input[checkbox]'))).toBeNull(); + expect(de.queryAll(By.css('cdk-tree-node')).length).toEqual(3); + }); + + it('should display checkboxes if multiSelect is true', async () => { + comp.multiSelect = true; + fixture.detectChanges(); + expect(de.queryAll(By.css('#leaf-node-checkbox')).length).toEqual(3); + expect(de.queryAll(By.css('cdk-tree-node')).length).toEqual(3); + }); + }); }); // declare a test component