Commits

Jens Vannerum authored 3e09653f0b4
97049: Nest before each statements
No tags

src/app/shared/search/search-filters/search-filter/search-hierarchy-filter/search-hierarchy-filter.component.spec.ts

Modified
80 80 schemas: [NO_ERRORS_SCHEMA],
81 81 }).compileComponents();
82 82 });
83 83
84 84 function init() {
85 85 fixture = TestBed.createComponent(SearchHierarchyFilterComponent);
86 86 fixture.detectChanges();
87 87 showVocabularyTreeLink = fixture.debugElement.query(By.css('a#show-test-search-filter-tree'));
88 88 }
89 89
90 - afterEach(() => {
91 - fixture.destroy();
92 - });
93 -
94 90 describe('if the vocabulary doesn\'t exist', () => {
95 91
96 92 beforeEach(() => {
97 93 spyOn(vocabularyService, 'searchTopEntries').and.returnValue(observableOf(new RemoteData(
98 94 undefined, 0, 0, RequestEntryState.Error, undefined, undefined, 404
99 95 )));
100 96 init();
101 97 });
102 98
103 - it('should not show the vocabulary tree link', (done) => {
99 + it('should not show the vocabulary tree link', () => {
104 100 expect(showVocabularyTreeLink).toBeNull();
105 - done();
106 101 });
107 102 });
108 103
109 104 describe('if the vocabulary exists', () => {
110 105
111 106 beforeEach(() => {
112 107 spyOn(vocabularyService, 'searchTopEntries').and.returnValue(observableOf(new RemoteData(
113 108 undefined, 0, 0, RequestEntryState.Success, undefined, buildPaginatedList(new PageInfo(), []), 200
114 109 )));
115 110 init();
116 111 });
117 112
118 - it('should show the vocabulary tree link', (done) => {
113 + it('should show the vocabulary tree link', () => {
119 114 expect(showVocabularyTreeLink).toBeTruthy();
120 - done();
121 115 });
122 116
123 117 describe('when clicking the vocabulary tree link', () => {
124 118
119 + const alreadySelectedValues = [
120 + 'already-selected-value-1',
121 + 'already-selected-value-2',
122 + ];
123 + const newSelectedValue = 'new-selected-value';
124 +
125 125 beforeEach(async () => {
126 126 showVocabularyTreeLink.nativeElement.click();
127 + fixture.componentInstance.selectedValues$ = observableOf(
128 + alreadySelectedValues.map(value => Object.assign(new FacetValue(), { value }))
129 + );
130 + VocabularyTreeViewComponent.select.emit(Object.assign(new VocabularyEntryDetail(), {
131 + value: newSelectedValue,
132 + }));
127 133 });
128 134
129 - it('should open the vocabulary tree modal', (done) => {
135 + it('should open the vocabulary tree modal', () => {
130 136 expect(ngbModal.open).toHaveBeenCalled();
131 - done();
132 137 });
133 138
134 139 describe('when selecting a value from the vocabulary tree', () => {
135 140
136 - const alreadySelectedValues = [
137 - 'already-selected-value-1',
138 - 'already-selected-value-2',
139 - ];
140 - const newSelectedValue = 'new-selected-value';
141 -
142 - beforeEach(() => {
143 - fixture.componentInstance.selectedValues$ = observableOf(
144 - alreadySelectedValues.map(value => Object.assign(new FacetValue(), { value }))
145 - );
146 - VocabularyTreeViewComponent.select.emit(Object.assign(new VocabularyEntryDetail(), {
147 - value: newSelectedValue,
148 - }));
149 - });
150 -
151 141 it('should add a new search filter to the existing search filters', () => {
152 142 waitForAsync(() => expect(router.navigate).toHaveBeenCalledWith([testSearchLink], {
153 143 queryParams: {
154 144 [`f.${testSearchFilter}`]: [
155 145 ...alreadySelectedValues,
156 146 newSelectedValue,
157 147 ].map((value => `${value},equals`)),
158 148 },
159 149 queryParamsHandling: 'merge',
160 150 }));

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut