Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ module.exports = {
extensionsToTreatAsEsm: ['.ts'],
coverageThreshold: {
global: {
branches: 31.0,
functions: 35.0,
lines: 64.0,
statements: 64.0,
branches: 34.8,
functions: 38.0,
lines: 65.5,
statements: 66.0,
},
},
watchPathIgnorePatterns: [
Expand Down
2,468 changes: 1,246 additions & 1,222 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
}

.container {
position: relative;
background: var(--white);
border-radius: 0.75rem;
box-shadow: 0 2px 4px var(--grey-outline);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,116 @@
import { Store } from '@ngxs/store';

import { MockComponents } from 'ng-mocks';

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

import { FilterChipsComponent } from '@osf/shared/components/filter-chips/filter-chips.component';
import { SearchFiltersComponent } from '@osf/shared/components/search-filters/search-filters.component';
import { DiscoverableFilter, FilterOption } from '@osf/shared/models/search/discaverable-filter.model';
import {
ClearFilterSearchResults,
FetchResources,
GlobalSearchSelectors,
LoadFilterOptions,
LoadFilterOptionsWithSearch,
LoadMoreFilterOptions,
UpdateSelectedFilterOption,
} from '@shared/stores/global-search';

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

describe.skip('FiltersSectionComponent', () => {
import { OSFTestingModule } from '@testing/osf.testing.module';
import { provideMockStore } from '@testing/providers/store-provider.mock';

describe('FiltersSectionComponent', () => {
let component: FiltersSectionComponent;
let fixture: ComponentFixture<FiltersSectionComponent>;
let store: Store;

const mockFilters = [{ key: 'filter1', label: 'Filter 1' }] as DiscoverableFilter[];
const mockSelectedOptions = { filter1: [{ value: 'option1', label: 'Option 1' }] as FilterOption[] };
const mockFilterSearchCache = { filter1: [] };

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [FiltersSectionComponent, ...MockComponents(FilterChipsComponent, SearchFiltersComponent)],
imports: [
FiltersSectionComponent,
OSFTestingModule,
...MockComponents(FilterChipsComponent, SearchFiltersComponent),
],
providers: [
provideMockStore({
signals: [
{ selector: GlobalSearchSelectors.getFilters, value: mockFilters },
{ selector: GlobalSearchSelectors.getSelectedOptions, value: mockSelectedOptions },
{ selector: GlobalSearchSelectors.getFilterSearchCache, value: mockFilterSearchCache },
{ selector: GlobalSearchSelectors.getResourcesLoading, value: false },
],
}),
],
}).compileComponents();

fixture = TestBed.createComponent(FiltersSectionComponent);
component = fixture.componentInstance;
store = TestBed.inject(Store);
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should dispatch UpdateSelectedFilterOption and FetchResources when filter options change', () => {
const filter = mockFilters[0];
const filterOption = [{ value: 'option2', label: 'Option 2' }] as FilterOption[];

component.onSelectedFilterOptionsChanged({ filter, filterOption });

expect(store.dispatch).toHaveBeenCalledWith(new UpdateSelectedFilterOption(filter.key, filterOption));
expect(store.dispatch).toHaveBeenCalledWith(new FetchResources());
});

it('should dispatch LoadFilterOptions when loading filter options', () => {
const filter = mockFilters[0];

component.onLoadFilterOptions(filter);

expect(store.dispatch).toHaveBeenCalledWith(new LoadFilterOptions(filter.key));
});

it('should dispatch LoadMoreFilterOptions when loading more filter options', () => {
const filter = mockFilters[0];

component.onLoadMoreFilterOptions(filter);

expect(store.dispatch).toHaveBeenCalledWith(new LoadMoreFilterOptions(filter.key));
});

it('should dispatch LoadFilterOptionsWithSearch when searching with text', () => {
const filter = mockFilters[0];
const searchText = 'test';

component.onSearchFilterOptions({ searchText, filter });

expect(store.dispatch).toHaveBeenCalledWith(new LoadFilterOptionsWithSearch(filter.key, searchText));
});

it('should dispatch ClearFilterSearchResults when searching with empty text', () => {
const filter = mockFilters[0];
const searchText = ' ';

component.onSearchFilterOptions({ searchText, filter });

expect(store.dispatch).toHaveBeenCalledWith(new ClearFilterSearchResults(filter.key));
});

it('should dispatch UpdateSelectedFilterOption and FetchResources when filter chip is removed', () => {
const filterKey = 'filter1';
const optionRemoved = mockSelectedOptions.filter1[0];

component.onFilterChipRemoved({ filterKey, optionRemoved });

expect(store.dispatch).toHaveBeenCalledWith(new UpdateSelectedFilterOption(filterKey, []));
expect(store.dispatch).toHaveBeenCalledWith(new FetchResources());
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
LoadMoreFilterOptions,
SetDefaultFilterValue,
UpdateSelectedFilterOption,
} from '@shared/stores/global-search';
} from '@osf/shared/stores/global-search';

@Component({
selector: 'osf-institution-resource-table-filters',
Expand Down Expand Up @@ -70,7 +70,7 @@ export class FiltersSectionComponent {

onFilterChipRemoved(event: { filterKey: string; optionRemoved: FilterOption }): void {
const updatedOptions = this.selectedFilterOptions()[event.filterKey].filter(
(option) => option.value === event.optionRemoved.value
(option) => option.value !== event.optionRemoved.value
);
this.actions.updateSelectedFilterOption(event.filterKey, updatedOptions);
this.actions.fetchResources();
Expand Down
Loading