fleet/frontend/components/queries/QueryPageWrapper/QueryPageWrapper.tests.jsx
Mike Stone 01e7ac2b6c Create query (#382)
* API call to create queries

* Add queries to redux

* create query when query form is submitted

* Redirect to ShowQueryPage after creating query

* Removes theme dropdown and NewQuery component header

* Extract NewQueryPage component state to redux state

* Pass logic down to NewQuery component as props

* Changes NewQuery component name to QueryComposer

* Render NewQueryPage for /queries/:id route

* Update ReduxConfig for loading a single resource

* QueryPage tests

* Get query when the query page loads

* catch errors when query is invalid

* Renames UpdateQueryForm to QueryForm to re-usability

* Changes InputField to a controlled component

* Always render the Query Form on Query Pages
2016-11-07 11:42:39 -05:00

57 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 { validGetQueryRequest } from 'test/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', () => {
validGetQueryRequest(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', () => {
validGetQueryRequest(bearerToken, queryID);
const fetchQuerySpy = spyOn(helpers, 'fetchQuery');
const mockStore = reduxMockStore(storeWithoutQuery);
mount(connectedComponent(QueryPageWrapper, { mockStore, props: locationProp }));
expect(fetchQuerySpy).toHaveBeenCalled();
restoreSpies();
});
});
});