Skip to content

Commit

Permalink
101127: Add multiSelect tests in VocabularyTreeviewComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
nona-luypaert committed Apr 21, 2023
1 parent f0d0cb5 commit 7f7ed17
Showing 1 changed file with 53 additions and 7 deletions.
Expand Up @@ -12,21 +12,23 @@ 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';
import { VocabularyEntry } from '../../../core/submission/vocabularies/models/vocabulary-entry.model';
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', () => {

let comp: VocabularyTreeviewComponent;
let compAsAny: any;
let fixture: ComponentFixture<VocabularyTreeviewComponent>;
let initialState;
let de;

const item = new VocabularyEntryDetail();
item.id = 'node1';
Expand Down Expand Up @@ -87,6 +89,12 @@ describe('VocabularyTreeviewComponent test suite', () => {
});
}));

afterEach(() => {
fixture.destroy();
comp = null;
compAsAny = null;
});

describe('', () => {
let testComp: TestComponent;
let testFixture: ComponentFixture<TestComponent>;
Expand Down Expand Up @@ -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([]);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7f7ed17

Please sign in to comment.