Skip to content

Instantly share code, notes, and snippets.

@obsd
Last active February 10, 2020 19:40
Show Gist options
  • Save obsd/5e86f6ab96d2246de33c8d5afb31adff to your computer and use it in GitHub Desktop.
Save obsd/5e86f6ab96d2246de33c8d5afb31adff to your computer and use it in GitHub Desktop.
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