Skip to content

Commit

Permalink
Merge pull request #751 from hms-dbmi-cellenics/1902-clean-up-v1-expe…
Browse files Browse the repository at this point in the history
…riments-redux

1902 clean up v1 redux
  • Loading branch information
cosa65 authored Jun 28, 2022
2 parents 2ebf8c9 + 787a685 commit 496c58f
Show file tree
Hide file tree
Showing 86 changed files with 271 additions and 957 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ import { setCellSetHiddenStatus } from 'redux/actions/cellSets';
import { isSubset } from 'utils/arrayUtils';
import { updatePlotConfig } from 'redux/actions/componentConfig';

import config from 'config';
import { api } from 'utils/constants';

jest.mock('config');

const experimentId = fake.EXPERIMENT_ID;

// Mock hash so we can control the ETag that is produced by hash.MD5 when fetching work requests
Expand Down Expand Up @@ -146,8 +141,6 @@ describe('HeatmapPlot', () => {
});

it('Shows loader message if cellSets are loading in v2', async () => {
config.currentApiVersion = 'v2';

const mockLoadingAPIResponses = {
...mockWorkerResponses,
[`experiments/${experimentId}/cellSets`]: () => delayedResponse({ body: 'Not found', status: 404 }, 4000),
Expand Down Expand Up @@ -262,7 +255,8 @@ describe('HeatmapPlot', () => {
// Renders correctly
expect(screen.getByText(/Sup Im a heatmap/i)).toBeInTheDocument();

// Cell ids stored in expression matrix is string, whereas cell ids stored in the store are number
// Cell ids stored in expression matrix is string,
// whereas cell ids stored in the store are number
// So we need to convert them to string to be able to compare the values
const cellsInLouvain3 = cellSetsData
.cellSets.find(({ key }) => key === 'louvain')
Expand Down
9 changes: 1 addition & 8 deletions src/__test__/components/data-management/ProjectCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ import thunk from 'redux-thunk';
import initialState, { projectTemplate } from 'redux/reducers/projects/initialState';
import ProjectCard from 'components/data-management/ProjectCard';

import config from 'config';
import { api } from 'utils/constants';

jest.mock('config');

const projectUuid = '12345';
const projectName = 'Test Project';
const experimentId = 'experimentId1';
Expand Down Expand Up @@ -89,9 +84,7 @@ describe('ProjectCard', () => {
expect(modal).toBeInTheDocument();
});

it('Updates project name in api v2 when clicked', async () => {
config.currentApiVersion = api.V2;

it('Updates project name when clicked', async () => {
render(
<Provider store={mockStore(projectState)}>
<ProjectCard projectUuid={projectUuid} />
Expand Down
2 changes: 0 additions & 2 deletions src/__test__/components/data-management/SamplesTable.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import { loadSamples } from 'redux/actions/samples';

import mockDemoExperiments from '__test__/test-utils/mockData/mockDemoExperiments.json';

jest.mock('config');

jest.mock('@aws-amplify/auth', () => ({
currentAuthenticatedUser: jest.fn(() => Promise.resolve({ attributes: { name: 'mockUserName' } })),
federatedSignIn: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';
import mockAPI, {
} from '__test__/test-utils/mockAPI';

import config from 'config';
import { api } from 'utils/constants';

import ShareExperimentModal from 'components/data-management/ShareExperimentModal';

jest.mock('@aws-amplify/auth', () => ({
Expand Down Expand Up @@ -96,28 +93,4 @@ describe('Share expeirment modal', () => {
await act(() => userEvent.click(revokeButton[0]));
await waitFor(() => expect(onCancel).toHaveBeenCalled());
});

it('Inviting users works for v2', async () => {
config.currentApiVersion = api.V2;

await renderShareExperimentModal();
const input = screen.getAllByRole('combobox');
userEvent.type(input[0], '[email protected]{enter}');

await waitFor(() => expect(screen.getByText('Add')).toBeInTheDocument());
const inviteButton = screen.getByText('Add');
await act(() => fireEvent.click(inviteButton));
expect(fetchMock.mock.calls.length).toEqual(2);
expect(fetchMock.mock.calls[1]).toMatchSnapshot();
});

it('Revoke access works for v2', async () => {
config.currentApiVersion = api.V2;

await renderShareExperimentModal();
const revokeButton = screen.getAllByText('Revoke');
expect(screen.getByText('[email protected]')).toBeInTheDocument();
await act(() => userEvent.click(revokeButton[0]));
await waitFor(() => expect(onCancel).toHaveBeenCalled());
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,3 @@ Array [
},
]
`;

exports[`Share expeirment modal Inviting users works for v2 1`] = `
Array [
"http://localhost:3000/v2/access/testae48e318dab9a1bd0bexperiment",
Object {
"body": "{\\"projectUuid\\":\\"test24b6-8600-test-mock-63822d2fmock\\",\\"role\\":\\"explorer\\",\\"userEmail\\":\\"asd@asd.com\\"}",
"headers": Object {
"Content-Type": "application/json",
},
"method": "PUT",
},
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ describe('ChangesNotAppliedModal', () => {
});

it('Fires the correct action for Run button', () => {
const mockRunPipeline = jest.fn();
const mockRunQC = jest.fn();

render(
<Provider store={mockStore(withChangesState)}>
<ChangesNotAppliedModal onRunPipeline={() => mockRunPipeline()} />
<ChangesNotAppliedModal onRunQC={() => mockRunQC()} />
</Provider>,
);

userEvent.click(screen.getByText('Run'));
expect(mockRunPipeline).toHaveBeenCalled();
expect(mockRunQC).toHaveBeenCalled();
});

it('Fires the correct action for Discard button', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import initialSamplesState, { sampleTemplate } from 'redux/reducers/samples/init
import { getBackendStatus } from 'redux/selectors';
import '__test__/test-utils/setupTests';

import { runPipeline } from 'redux/actions/pipeline';
import { runQC } from 'redux/actions/pipeline';
import generateExperimentSettingsMock from '__test__/test-utils/experimentSettings.mock';
import { modules } from 'utils/constants';
import { act } from 'react-dom/test-utils';
Expand Down Expand Up @@ -46,7 +46,7 @@ jest.mock('utils/AppRouteProvider', () => ({
jest.mock('redux/selectors');

jest.mock('redux/actions/pipeline', () => ({
runPipeline: jest.fn(() => ({ type: 'RUN_PIPELINE' })),
runQC: jest.fn(() => ({ type: 'RUN_PIPELINE' })),
}));

const mockStore = configureMockStore([thunk]);
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('DataProcessingPage', () => {

userEvent.click(screen.getByText('Start'));

expect(runPipeline).toHaveBeenCalled();
expect(runQC).toHaveBeenCalled();
});

it('Classifier filter (1st filter) should show custom disabled message if sample is prefiltered ', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ Array [
]
`;

exports[`loadBackendStatus Dispatches error if fetch fails for api v2 1`] = `
Array [
Object {
"experimentId": "1234",
},
Object {
"error": "We couldn't get the status of the experiment's data processing.",
"experimentId": "1234",
},
]
`;

exports[`loadBackendStatus Works well if fetch works 1`] = `
Array [
Object {
Expand Down Expand Up @@ -56,36 +44,3 @@ Array [
},
]
`;

exports[`loadBackendStatus Works well if fetch works for api v2 1`] = `
Array [
Object {
"experimentId": "1234",
},
Object {
"experimentId": "1234",
"status": Object {
"gem2s": Object {
"completedSteps": Array [],
"error": false,
"startDate": null,
"status": "NOT_CREATED",
"stopDate": null,
},
"pipeline": Object {
"completedSteps": Array [],
"error": false,
"startDate": null,
"status": "NOT_CREATED",
"stopDate": null,
},
"worker": Object {
"ready": true,
"restartCount": 0,
"started": true,
"status": "Running",
},
},
},
]
`;
38 changes: 0 additions & 38 deletions src/__test__/redux/actions/backendStatus/loadBackendStatus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import initialState from 'redux/reducers/backendStatus/initialState';
import loadBackendStatus from 'redux/actions/backendStatus/loadBackendStatus';
import { BACKEND_STATUS_LOADING, BACKEND_STATUS_LOADED, BACKEND_STATUS_ERROR } from 'redux/actionTypes/backendStatus';

import config from 'config';
import { api } from 'utils/constants';

jest.mock('config');

const mockStore = configureStore([thunk]);

const backendStatusResponse = {
Expand Down Expand Up @@ -81,37 +76,4 @@ describe('loadBackendStatus', () => {
{ headers: {} },
);
});

it('Works well if fetch works for api v2', async () => {
config.currentApiVersion = api.V2;
fetchMock.mockResponseOnce(() => Promise.resolve(JSON.stringify(backendStatusResponse)));
const store = mockStore({ backendStatus: initialState });

await store.dispatch(loadBackendStatus(experimentId));

const actions = store.getActions();
expect(_.map(actions, 'type')).toEqual([BACKEND_STATUS_LOADING, BACKEND_STATUS_LOADED]);
expect(_.map(actions, 'payload')).toMatchSnapshot();

expect(fetchMock).toHaveBeenCalledWith(
'http://localhost:3000/v2/experiments/1234/backendStatus',
{ headers: {} },
);
});

it('Dispatches error if fetch fails for api v2', async () => {
fetchMock.mockRejectOnce(() => new Error('An api error'));
const store = mockStore({ backendStatus: initialState });

await store.dispatch(loadBackendStatus(experimentId));

const actions = store.getActions();
expect(_.map(actions, 'type')).toEqual([BACKEND_STATUS_LOADING, BACKEND_STATUS_ERROR]);
expect(_.map(actions, 'payload')).toMatchSnapshot();

expect(fetchMock).toHaveBeenCalledWith(
'http://localhost:3000/v2/experiments/1234/backendStatus',
{ headers: {} },
);
});
});
2 changes: 0 additions & 2 deletions src/__test__/redux/actions/cellSets/reorderCellSet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import initialState from 'redux/reducers/cellSets/initialState';

enableFetchMocks();

jest.mock('config');

const mockStore = configureStore([thunk]);

describe('reorderCellSet action', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import '__test__/test-utils/setupTests';

enableFetchMocks();

jest.mock('config');

const mockStore = configureStore([thunk]);

describe('updateCellSetProperty action', () => {
Expand Down
20 changes: 4 additions & 16 deletions src/__test__/redux/actions/componentConfig/loadPlotConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import endUserMessages from 'utils/endUserMessages';
import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';
import fake from '__test__/test-utils/constants';

import config from 'config';
import { api } from 'utils/constants';

jest.mock('utils/pushNotificationMessage');

let testStore = null;
Expand Down Expand Up @@ -47,6 +44,10 @@ describe('loadPlotConfig', () => {
await testStore.dispatch(loadPlotConfig(experimentId, plotUuid, plotType));
});

// Hits the correct url
const fetchUrl = fetchMock.mock.calls[0][0];
expect(fetchUrl).toEqual(`http://localhost:3000/v2/experiments/${experimentId}/plots/${plotUuid}`);

// Expect componentConfig to contain key for plotUuid
expect(testStore.getState().componentConfig[plotUuid]).toBeDefined();

Expand Down Expand Up @@ -92,17 +93,4 @@ describe('loadPlotConfig', () => {
expect(pushNotificationMessage).toHaveBeenCalledTimes(1);
expect(pushNotificationMessage).toHaveBeenCalledWith('error', expect.anything());
});

it('Uses V2 URL when using API version V2', async () => {
fetchMock.mockResponse(() => Promise.resolve(new Response(JSON.stringify(mockConfigData))));
config.currentApiVersion = api.V2;

await act(async () => {
await testStore.dispatch(loadPlotConfig(experimentId, plotUuid, plotType));
});

const fetchUrl = fetchMock.mock.calls[0][0];

expect(fetchUrl).toEqual(`http://localhost:3000/v2/experiments/${experimentId}/plots/${plotUuid}`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import endUserMessages from 'utils/endUserMessages';
import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';
import fake from '__test__/test-utils/constants';

import config from 'config';
import { api } from 'utils/constants';

jest.mock('utils/pushNotificationMessage');

const mockStore = configureMockStore([thunk]);
Expand All @@ -37,7 +34,7 @@ const state = {

const store = mockStore(state);

describe('loadPlotConfig', () => {
describe('savePlotConfig', () => {
beforeEach(async () => {
jest.clearAllMocks();
fetchMock.resetMocks();
Expand All @@ -63,15 +60,4 @@ describe('loadPlotConfig', () => {
expect(pushNotificationMessage).toHaveBeenCalledTimes(1);
expect(pushNotificationMessage).toHaveBeenCalledWith('error', endUserMessages.ERROR_SAVING_PLOT_CONFIG);
});

it('Uses V2 URL when using API version V2', async () => {
config.currentApiVersion = api.V2;

await act(async () => {
await store.dispatch(savePlotConfig(experimentId, plotUuid));
});

const url = fetchMock.mock.calls[0][0];
expect(url).toEqual(`http://localhost:3000/v2/experiments/${experimentId}/plots/${plotUuid}`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import {
EXPERIMENT_SETTINGS_PROCESSING_ERROR,
} from 'redux/actionTypes/experimentSettings';
import loadProcessingSettings from 'redux/actions/experimentSettings/processingConfig/loadProcessingSettings';
import config from 'config';
import { api } from 'utils/constants';
import generateExperimentSettingsMock from '../../../test-utils/experimentSettings.mock';

import generateExperimentSettingsMock from '__test__/test-utils/experimentSettings.mock';

import '__test__/test-utils/setupTests';

Expand Down Expand Up @@ -59,6 +58,8 @@ describe('loadProcessingSettings action', () => {

expect(actions.length).toEqual(1);
expect(actions[0].type).toEqual(EXPERIMENT_SETTINGS_PROCESSING_CONFIG_LOADED);

expect(fetchMock).toHaveBeenCalledWith(`http://localhost:3000/v2/experiments/${experimentId}/processingConfig`, { headers: {} });
});

it('Correctly sets error if returned an error', async () => {
Expand Down Expand Up @@ -100,11 +101,4 @@ describe('loadProcessingSettings action', () => {
expect(actions.length).toEqual(1);
expect(actions[0].type).toEqual(EXPERIMENT_SETTINGS_PROCESSING_CONFIG_LOADED);
});

it('Works with apiv2', async () => {
config.currentApiVersion = api.V2;
const store = mockStore(mockState);
await store.dispatch(loadProcessingSettings(experimentId));
expect(fetchMock).toHaveBeenCalledWith(`http://localhost:3000/v2/experiments/${experimentId}/processingConfig`, { headers: {} });
});
});
Loading

0 comments on commit 496c58f

Please sign in to comment.