fleet/frontend/components/queries/QueryPageWrapper/QueryPageWrapper.tests.jsx
Mike Stone d747a471af Refactor API client (#1335)
* Isolate each API entity
* Improve code structure in API client and request mocks
* Standardize on a request mock structure
* Use helper for creating request mocks
* Adds Request class to handle API requests
2017-03-02 17:07:01 -05:00

58 lines
1.6 KiB
JavaScript

import expect, { spyOn, restoreSpies } from 'expect';
import { mount } from 'enzyme';
import nock from 'nock';
import { connectedComponent, reduxMockStore } from 'test/helpers';
import helpers from 'components/queries/QueryPageWrapper/helpers';
import QueryPageWrapper from 'components/queries/QueryPageWrapper';
import mocks from 'test/mocks';
const { queries: queryMocks } = mocks;
const bearerToken = 'abc123';
const storeWithoutQuery = {
entities: {
queries: {
data: {},
},
},
};
describe('QueryPageWrapper - component', () => {
beforeEach(() => {
global.localStorage.setItem('KOLIDE::auth_token', bearerToken);
});
afterEach(() => {
restoreSpies();
nock.cleanAll();
});
describe('/queries/:id', () => {
const queryID = '10';
const locationProp = { params: { id: queryID } };
it('dispatches an action to get the query when there is no query', () => {
queryMocks.load.valid(bearerToken, queryID);
const mockStore = reduxMockStore(storeWithoutQuery);
mount(connectedComponent(QueryPageWrapper, { mockStore, props: locationProp }));
const dispatchedActions = mockStore.getActions().map((action) => { return action.type; });
expect(dispatchedActions).toInclude('queries_LOAD_REQUEST');
});
it('calls the fetchQuery helper function', () => {
queryMocks.load.valid(bearerToken, queryID);
const fetchQuerySpy = spyOn(helpers, 'fetchQuery');
const mockStore = reduxMockStore(storeWithoutQuery);
mount(connectedComponent(QueryPageWrapper, { mockStore, props: locationProp }));
expect(fetchQuerySpy).toHaveBeenCalled();
restoreSpies();
});
});
});