Skip to content

Commit

Permalink
component integration tests for <WatchStatus/>
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Jun 24, 2019
1 parent d9219ac commit 9507ade
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
);
};

const setLoadWatchHistoryItemResponse = (response: HttpResponse = {}) => {
const defaultResponse = { watchHistoryItem: {} };
server.respondWith('GET', `${API_ROOT}/history/:id`, mockResponse(defaultResponse, response));
};

const setDeleteWatchResponse = (response?: HttpResponse, error?: any) => {
const status = error ? error.status || 400 : 200;
const body = error ? JSON.stringify(error.body) : JSON.stringify(response);
Expand Down Expand Up @@ -90,17 +95,48 @@ const registerHttpRequestMockHelpers = (server: SinonFakeServer) => {
);
};

const setDeactivateWatchResponse = (response: HttpResponse = {}) => {
const defaultResponse = { watchStatus: {} };
server.respondWith(
'PUT',
`${API_ROOT}/watch/:id/deactivate`,
mockResponse(defaultResponse, response)
);
};

const setActivateWatchResponse = (response: HttpResponse = {}) => {
const defaultResponse = { watchStatus: {} };
server.respondWith(
'PUT',
`${API_ROOT}/watch/:id/activate`,
mockResponse(defaultResponse, response)
);
};

const setAcknowledgeWatchResponse = (response: HttpResponse = {}) => {
const defaultResponse = { watchStatus: {} };
server.respondWith(
'PUT',
`${API_ROOT}/watch/:id/action/:actionId/acknowledge`,
mockResponse(defaultResponse, response)
);
};

return {
setLoadWatchesResponse,
setLoadWatchResponse,
setLoadWatchHistoryResponse,
setLoadWatchHistoryItemResponse,
setDeleteWatchResponse,
setSaveWatchResponse,
setLoadExecutionResultResponse,
setLoadMatchingIndicesResponse,
setLoadEsFieldsResponse,
setLoadSettingsResponse,
setLoadWatchVisualizeResponse,
setDeactivateWatchResponse,
setActivateWatchResponse,
setAcknowledgeWatchResponse,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
findTestSubject,
TestBed,
TestBedConfig,
nextTick,
} from '../../../../../../test_utils';
import { WatchStatus } from '../../../public/sections/watch_status/components/watch_status';
import { ROUTES } from '../../../common/constants';
Expand All @@ -28,8 +29,9 @@ const initTestBed = registerTestBed(WatchStatus, testBedConfig);

export interface WatchStatusTestBed extends TestBed<WatchStatusTestSubjects> {
actions: {
selectTab: (tab: 'execution history' | 'action statuses') => void;
clickToggleActivationButton: () => void;
clickAcknowledgeButton: () => void;
clickAcknowledgeButton: (index: number) => void;
clickDeleteWatchButton: () => void;
clickWatchExecutionAt: (index: number, tableCellText: string) => void;
};
Expand All @@ -42,6 +44,15 @@ export const setup = async (): Promise<WatchStatusTestBed> => {
* User Actions
*/

const selectTab = (tab: 'execution history' | 'action statuses') => {
const tabs = ['execution history', 'action statuses'];

testBed
.find('tab')
.at(tabs.indexOf(tab))
.simulate('click');
};

const clickToggleActivationButton = async () => {
const { component } = testBed;
const button = testBed.find('toggleWatchActivationButton');
Expand All @@ -53,9 +64,12 @@ export const setup = async (): Promise<WatchStatusTestBed> => {
});
};

const clickAcknowledgeButton = async () => {
const { component } = testBed;
const button = testBed.find('acknowledgeWatchButton');
const clickAcknowledgeButton = async (index: number) => {
const { component, table } = testBed;
const { rows } = table.getMetaData('watchActionStatusTable');
const currentRow = rows[index];
const lastColumn = currentRow.columns[currentRow.columns.length - 1].reactWrapper;
const button = findTestSubject(lastColumn, 'acknowledgeWatchButton');

// @ts-ignore (remove when react 16.9.0 is released)
await act(async () => {
Expand All @@ -79,19 +93,22 @@ export const setup = async (): Promise<WatchStatusTestBed> => {
const { component, table } = testBed;
const { rows } = table.getMetaData('watchHistoryTable');
const currentRow = rows[index];
const firstColumn = currentRow.columns[currentRow.columns.length - 1].reactWrapper;
const button = findTestSubject(firstColumn, `watchIdColumn-${tableCellText}`);
const firstColumn = currentRow.columns[0].reactWrapper;

const button = findTestSubject(firstColumn, `watchStartTimeColumn-${tableCellText}`);

// @ts-ignore (remove when react 16.9.0 is released)
await act(async () => {
button.simulate('click');
await nextTick(100);
component.update();
});
};

return {
...testBed,
actions: {
selectTab,
clickToggleActivationButton,
clickAcknowledgeButton,
clickDeleteWatchButton,
Expand All @@ -110,9 +127,14 @@ export type TestSubjects =
| 'actionErrorsFlyout.title'
| 'deleteWatchButton'
| 'pageTitle'
| 'tab'
| 'toggleWatchActivationButton'
| 'watchActionStatusTable'
| 'watchActionsTable'
| 'watchDetailSection'
| 'watchHistoryDetailFlyout'
| 'watchHistoryDetailFlyout.title'
| 'watchHistorySection'
| 'watchHistoryErrorDetailFlyout'
| 'watchHistoryErrorDetailFlyout.errorMessage'
| 'watchHistoryErrorDetailFlyout.title'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe.skip('<WatchList />', () => {
).toContain('Delete watch');
});

test('should send the correct HTTP request to delete repository', async () => {
test('should send the correct HTTP request to delete watch', async () => {
const { component, actions, table } = testBed;
const { rows } = table.getMetaData('watchesTable');

Expand Down
Loading

0 comments on commit 9507ade

Please sign in to comment.