Skip to content

Commit

Permalink
disable clasifier filter (#189)
Browse files Browse the repository at this point in the history
* disable clasifier filter if sample has preFiltered flag
* add actions to load sample
  • Loading branch information
Anugerah Erlaut authored Apr 1, 2021
1 parent f6f2522 commit 98687de
Show file tree
Hide file tree
Showing 16 changed files with 317 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import waitForActions from 'redux-mock-store-await-actions';
import Adapter from 'enzyme-adapter-react-16';
import { act } from 'react-dom/test-utils';
import thunk from 'redux-thunk';
import _ from 'lodash';

import DataProcessingPage from '../../../../../pages/experiments/[experimentId]/data-processing/index';

Expand All @@ -21,8 +22,8 @@ jest.mock('localforage');

const mockStore = configureMockStore([thunk]);

const getStore = () => {
const store = mockStore({
const getStore = (settings = {}) => {
const initialState = {
notifications: {},
experimentSettings: {
...initialExperimentSettingsState,
Expand Down Expand Up @@ -102,7 +103,22 @@ const getStore = () => {
componentConfig: {
...initialPlotConfigStates,
},
});
samples: {
ids: ['sample-1', 'sample-2'],
meta: {
loading: false,
error: false,
},
'sample-1': {
name: 'sample-1',
},
'sample-2': {
name: 'sample-2',
},
},
};

const store = mockStore(_.merge(initialState, settings));

return store;
};
Expand Down Expand Up @@ -186,4 +202,25 @@ describe('DataProcessingPage', () => {
// Run filter is disabled after triggering the pipeline
expect(page.find('#runFilterButton').filter('Button').at(0).props().disabled).toEqual(true);
});

it('preFiltered on a sample disables filter', async () => {
const store = getStore({
samples: {
'sample-1': {
preFiltered: true,
},
},
});

const page = mount(
<Provider store={store}>
<DataProcessingPage experimentId='experimentId' experimentData={experimentData} route='route'>
<></>
</DataProcessingPage>
</Provider>,
);

// Run filter button is disabled on the first
expect(page.find('#runFilterButton').filter('Button').at(0).props().disabled).toEqual(true);
});
});
2 changes: 0 additions & 2 deletions src/__test__/redux/actions/projects/deleteProject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ describe('deleteProject action', () => {
const store = mockStore(initialStateMultipleProjects);
await store.dispatch(deleteProject(mockProjectUuid1));

console.log(store.getActions());

// Delete sample
const action1 = store.getActions()[0];
expect(action1.type).toEqual(SAMPLES_DELETE);
Expand Down
57 changes: 57 additions & 0 deletions src/__test__/redux/actions/samples/loadSamples.test..js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';

import initialSampleState from '../../../../redux/reducers/samples/initialState';
import { SAMPLES_ERROR, SAMPLES_LOADED } from '../../../../redux/actionTypes/samples';
import { loadSamples } from '../../../../redux/actions/samples';

enableFetchMocks();

const mockStore = configureStore([thunk]);

describe('loadSample action', () => {
const experimentId = '1234';

const initialState = {
samples: {
...initialSampleState,
},
};

const response = new Response(
JSON.stringify(
{
samples: {
ids: ['sample-1', 'sample-2'],
'sample-1': { name: 'sample-1' },
'sample-2': { name: 'sample-2' },
},
},
),
);

fetchMock.resetMocks();
fetchMock.doMock();
fetchMock.mockResolvedValue(response);

it('Dispatches event correctly', async () => {
const store = mockStore(initialState);
await store.dispatch(loadSamples(experimentId));

// LOAD SAMPLE
const action1 = store.getActions()[0];
expect(action1.type).toEqual(SAMPLES_LOADED);
});

it('Dispatches error correctly', async () => {
fetchMock.mockReject(new Error('Failed fetching samples'));

const store = mockStore(initialState);
await store.dispatch(loadSamples(experimentId));

// LOAD SAMPLE
const action1 = store.getActions()[0];
expect(action1.type).toEqual(SAMPLES_ERROR);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Object {
"asd123",
"qwe234",
],
"meta": Object {
"error": false,
"loading": true,
},
"qwe234": Object {
"complete": false,
"createdDate": "2021-01-02T14:48:00.000Z",
Expand Down Expand Up @@ -53,6 +57,10 @@ Object {
"ids": Array [
"asd123",
],
"meta": Object {
"error": false,
"loading": true,
},
}
`;

Expand All @@ -74,6 +82,10 @@ Object {
"ids": Array [
"asd123",
],
"meta": Object {
"error": false,
"loading": true,
},
}
`;

Expand All @@ -95,6 +107,10 @@ Object {
"ids": Array [
"asd123",
],
"meta": Object {
"error": false,
"loading": true,
},
}
`;

Expand Down Expand Up @@ -128,5 +144,9 @@ Object {
"ids": Array [
"asd123",
],
"meta": Object {
"error": false,
"loading": true,
},
}
`;
38 changes: 37 additions & 1 deletion src/__test__/redux/reducers/samplesReducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import samplesReducer from '../../../redux/reducers/samples';
import initialState, { sampleTemplate, sampleFileTemplate } from '../../../redux/reducers/samples/initialState';

import {
SAMPLES_CREATE, SAMPLES_UPDATE, SAMPLES_FILE_UPDATE, SAMPLES_DELETE,
SAMPLES_CREATE,
SAMPLES_UPDATE,
SAMPLES_FILE_UPDATE,
SAMPLES_LOADED,
SAMPLES_ERROR,
SAMPLES_DELETE,
} from '../../../redux/actionTypes/samples';

describe('samplesReducer', () => {
Expand Down Expand Up @@ -135,4 +140,35 @@ describe('samplesReducer', () => {
expect(newState[sample1.uuid].fileNames).toEqual([fileName]);
expect(newState[sample1.uuid].files[fileName]).toEqual(mockFile);
});

it('Loads samples correctly', () => {
const newState = samplesReducer(oneSampleState, {
type: SAMPLES_LOADED,
payload: {
samples: {
ids: [sample1.uuid, sample2.uuid],
[sample1.uuid]: sample1,
[sample2.uuid]: sample2,
},
},
});

expect(newState.ids).toEqual([mockUuid1, mockUuid2]);
expect(newState.meta.loading).toEqual(false);
expect(newState.meta.error).toEqual(false);
});

it('Handles errors correctly', () => {
const error = 'Failed uploading samples';

const newState = samplesReducer(oneSampleState, {
type: SAMPLES_ERROR,
payload: {
error,
},
});

expect(newState.meta.loading).toEqual(false);
expect(newState.meta.error).toEqual(error);
});
});
Loading

0 comments on commit 98687de

Please sign in to comment.