Skip to content

Commit 7043b73

Browse files
authored
[ENG-9973] Unit tests: Admin institutions (#837)
1 parent fd005ab commit 7043b73

File tree

16 files changed

+2517
-1311
lines changed

16 files changed

+2517
-1311
lines changed

jest.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ module.exports = {
5454
extensionsToTreatAsEsm: ['.ts'],
5555
coverageThreshold: {
5656
global: {
57-
branches: 31.0,
58-
functions: 35.0,
59-
lines: 64.0,
60-
statements: 64.0,
57+
branches: 34.8,
58+
functions: 38.0,
59+
lines: 65.5,
60+
statements: 66.0,
6161
},
6262
},
6363
watchPathIgnorePatterns: [

package-lock.json

Lines changed: 1246 additions & 1222 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/core/components/forbidden-page/forbidden-page.component.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
}
88

99
.container {
10-
position: relative;
1110
background: var(--white);
1211
border-radius: 0.75rem;
1312
box-shadow: 0 2px 4px var(--grey-outline);
Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,116 @@
1+
import { Store } from '@ngxs/store';
2+
13
import { MockComponents } from 'ng-mocks';
24

35
import { ComponentFixture, TestBed } from '@angular/core/testing';
46

57
import { FilterChipsComponent } from '@osf/shared/components/filter-chips/filter-chips.component';
68
import { SearchFiltersComponent } from '@osf/shared/components/search-filters/search-filters.component';
9+
import { DiscoverableFilter, FilterOption } from '@osf/shared/models/search/discaverable-filter.model';
10+
import {
11+
ClearFilterSearchResults,
12+
FetchResources,
13+
GlobalSearchSelectors,
14+
LoadFilterOptions,
15+
LoadFilterOptionsWithSearch,
16+
LoadMoreFilterOptions,
17+
UpdateSelectedFilterOption,
18+
} from '@shared/stores/global-search';
719

820
import { FiltersSectionComponent } from './filters-section.component';
921

10-
describe.skip('FiltersSectionComponent', () => {
22+
import { OSFTestingModule } from '@testing/osf.testing.module';
23+
import { provideMockStore } from '@testing/providers/store-provider.mock';
24+
25+
describe('FiltersSectionComponent', () => {
1126
let component: FiltersSectionComponent;
1227
let fixture: ComponentFixture<FiltersSectionComponent>;
28+
let store: Store;
29+
30+
const mockFilters = [{ key: 'filter1', label: 'Filter 1' }] as DiscoverableFilter[];
31+
const mockSelectedOptions = { filter1: [{ value: 'option1', label: 'Option 1' }] as FilterOption[] };
32+
const mockFilterSearchCache = { filter1: [] };
1333

1434
beforeEach(async () => {
1535
await TestBed.configureTestingModule({
16-
imports: [FiltersSectionComponent, ...MockComponents(FilterChipsComponent, SearchFiltersComponent)],
36+
imports: [
37+
FiltersSectionComponent,
38+
OSFTestingModule,
39+
...MockComponents(FilterChipsComponent, SearchFiltersComponent),
40+
],
41+
providers: [
42+
provideMockStore({
43+
signals: [
44+
{ selector: GlobalSearchSelectors.getFilters, value: mockFilters },
45+
{ selector: GlobalSearchSelectors.getSelectedOptions, value: mockSelectedOptions },
46+
{ selector: GlobalSearchSelectors.getFilterSearchCache, value: mockFilterSearchCache },
47+
{ selector: GlobalSearchSelectors.getResourcesLoading, value: false },
48+
],
49+
}),
50+
],
1751
}).compileComponents();
1852

1953
fixture = TestBed.createComponent(FiltersSectionComponent);
2054
component = fixture.componentInstance;
55+
store = TestBed.inject(Store);
2156
fixture.detectChanges();
2257
});
2358

2459
it('should create', () => {
2560
expect(component).toBeTruthy();
2661
});
62+
63+
it('should dispatch UpdateSelectedFilterOption and FetchResources when filter options change', () => {
64+
const filter = mockFilters[0];
65+
const filterOption = [{ value: 'option2', label: 'Option 2' }] as FilterOption[];
66+
67+
component.onSelectedFilterOptionsChanged({ filter, filterOption });
68+
69+
expect(store.dispatch).toHaveBeenCalledWith(new UpdateSelectedFilterOption(filter.key, filterOption));
70+
expect(store.dispatch).toHaveBeenCalledWith(new FetchResources());
71+
});
72+
73+
it('should dispatch LoadFilterOptions when loading filter options', () => {
74+
const filter = mockFilters[0];
75+
76+
component.onLoadFilterOptions(filter);
77+
78+
expect(store.dispatch).toHaveBeenCalledWith(new LoadFilterOptions(filter.key));
79+
});
80+
81+
it('should dispatch LoadMoreFilterOptions when loading more filter options', () => {
82+
const filter = mockFilters[0];
83+
84+
component.onLoadMoreFilterOptions(filter);
85+
86+
expect(store.dispatch).toHaveBeenCalledWith(new LoadMoreFilterOptions(filter.key));
87+
});
88+
89+
it('should dispatch LoadFilterOptionsWithSearch when searching with text', () => {
90+
const filter = mockFilters[0];
91+
const searchText = 'test';
92+
93+
component.onSearchFilterOptions({ searchText, filter });
94+
95+
expect(store.dispatch).toHaveBeenCalledWith(new LoadFilterOptionsWithSearch(filter.key, searchText));
96+
});
97+
98+
it('should dispatch ClearFilterSearchResults when searching with empty text', () => {
99+
const filter = mockFilters[0];
100+
const searchText = ' ';
101+
102+
component.onSearchFilterOptions({ searchText, filter });
103+
104+
expect(store.dispatch).toHaveBeenCalledWith(new ClearFilterSearchResults(filter.key));
105+
});
106+
107+
it('should dispatch UpdateSelectedFilterOption and FetchResources when filter chip is removed', () => {
108+
const filterKey = 'filter1';
109+
const optionRemoved = mockSelectedOptions.filter1[0];
110+
111+
component.onFilterChipRemoved({ filterKey, optionRemoved });
112+
113+
expect(store.dispatch).toHaveBeenCalledWith(new UpdateSelectedFilterOption(filterKey, []));
114+
expect(store.dispatch).toHaveBeenCalledWith(new FetchResources());
115+
});
27116
});

src/app/features/admin-institutions/components/filters-section/filters-section.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
LoadMoreFilterOptions,
2121
SetDefaultFilterValue,
2222
UpdateSelectedFilterOption,
23-
} from '@shared/stores/global-search';
23+
} from '@osf/shared/stores/global-search';
2424

2525
@Component({
2626
selector: 'osf-institution-resource-table-filters',
@@ -70,7 +70,7 @@ export class FiltersSectionComponent {
7070

7171
onFilterChipRemoved(event: { filterKey: string; optionRemoved: FilterOption }): void {
7272
const updatedOptions = this.selectedFilterOptions()[event.filterKey].filter(
73-
(option) => option.value === event.optionRemoved.value
73+
(option) => option.value !== event.optionRemoved.value
7474
);
7575
this.actions.updateSelectedFilterOption(event.filterKey, updatedOptions);
7676
this.actions.fetchResources();

0 commit comments

Comments
 (0)