Last active
February 10, 2020 19:40
-
-
Save obsd/5e86f6ab96d2246de33c8d5afb31adff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const middlewares = []; | |
const mockStoreFactory = configureStore(middlewares); | |
const store = mockStoreFactory([]); | |
let discoverAssetsComponent: DashboardDiscoverAssetsWidgetComponent; | |
describe('select_actions', () => { | |
beforeEach(() => { | |
TestBed.configureTestingModule({ | |
imports: [... ], | |
providers: [... ] | |
}).compileComponents(); | |
fixture = TestBed.createComponent(DashboardDiscoverAssetsWidgetComponent); | |
discoverAssetsComponent = fixture.debugElement.componentInstance; | |
routerSpy = jest.spyOn(discoverAssetsComponent.router, 'navigate').mockImplementation((...args) => args); | |
discoverAssetsComponent.dashboardFilters = MOCK_DASHBOARD_FILTERS; | |
store.clearActions(); | |
}); | |
// action test | |
it('Dispatches the correct action and payload', () => { | |
const eventValue = {value: 2, name: 'Section 2'}; | |
discoverAssetsComponent.onChartClicked(eventValue); | |
// so easy to get mock store actions | |
const action = store.getActions()[0]; | |
// test actions values | |
expect(action.payload.filters.length).toEqual(2); // should be 2 filters | |
expect(action.payload.filters.filter(param => param.lookup === 'gte').length).toEqual(1); | |
expect(action.payload.filters.filter(param => param.fieldName === 'class_type').length).toEqual(1); | |
// test navigation to the right page | |
expect(routerSpy).toHaveBeenCalledWith(['/the-new-page']); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment