Skip to content

Commit

Permalink
Merge pull request #776 from hms-dbmi-cellenics/hotfix-rename-metadat…
Browse files Browse the repository at this point in the history
…a-tracks

[HOTFIX] Rename metadata tracks
  • Loading branch information
cosa65 authored Jul 20, 2022
2 parents f62b605 + 1a387c4 commit dcfcb2c
Show file tree
Hide file tree
Showing 20 changed files with 157 additions and 205 deletions.
17 changes: 7 additions & 10 deletions src/__test__/components/data-management/SamplesTable.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('Samples table', () => {

storeState = makeStore();

await storeState.dispatch(loadUser());
await storeState.dispatch(loadExperiments());

// Loading experiment is usually called in Data Management, so we have to load them manually
Expand All @@ -110,8 +111,6 @@ describe('Samples table', () => {
// Defaults to project with samples
await storeState.dispatch(setActiveExperiment(experimentWithSamplesId));
await storeState.dispatch(loadDeploymentInfo({ environment: 'test' }));

await storeState.dispatch(loadUser());
});

it('Does not show prompt to upload datasets if samples are available', async () => {
Expand All @@ -129,24 +128,22 @@ describe('Samples table', () => {
});
});

it('Should show an error if a sample fails to upload', async () => {
it('Should not show the samples until they are loaded', async () => {
const missingSampleState = _.cloneDeep(storeState.getState());

const createMockStore = configureMockStore([thunk]);

// Delete one of the samples
// Remove one of the samples of the experiment
const deletedSampleUuid = Object.keys(missingSampleState.samples).find((key) => key !== 'meta');
const deletedSampleObject = missingSampleState.samples[deletedSampleUuid];
delete missingSampleState.samples[deletedSampleUuid];

const missingSampleStore = createMockStore(missingSampleState);

await renderSamplesTable(missingSampleStore);

// The sample name should not be in the document
expect(screen.queryByText(deletedSampleObject.name)).toBeNull();

// There should be an error entry for the missing sample
expect(screen.getByText(/UPLOAD ERROR: Please reupload sample/i)).toBeInTheDocument();
Object.values(samples).forEach((sample) => {
expect(screen.queryByText(sample.name)).not.toBeInTheDocument();
});
});

it('Renaming the sample renames the sample', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renameMetadataTrack action Works correctly 1`] = `
Array [
Object {
"experimentId": "experiment-1234",
"newKey": "New_track",
"oldKey": "Old_track",
},
]
`;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ import thunk from 'redux-thunk';
import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';

import { metadataNameToKey } from 'utils/data-management/metadataUtils';
import updateMetadataTrack from 'redux/actions/experiments/updateMetadataTrack';
import renameMetadataTrack from 'redux/actions/experiments/renameMetadataTrack';
import initialExperimentState from 'redux/reducers/experiments';
import initialSampleState from 'redux/reducers/samples';

import {
EXPERIMENTS_METADATA_UPDATE,
} from 'redux/actionTypes/experiments';
import { EXPERIMENTS_METADATA_RENAME } from 'redux/actionTypes/experiments';
import '__test__/test-utils/setupTests';

import { SAMPLES_METADATA_DELETE, SAMPLES_UPDATE } from 'redux/actionTypes/samples';

const mockStore = configureStore([thunk]);

const mockExperimentId = 'experiment-1234';
Expand Down Expand Up @@ -58,7 +54,7 @@ const initialState = {
},
};

describe('updateMetadataTrack action', () => {
describe('renameMetadataTrack action', () => {
beforeEach(() => {
enableFetchMocks();
fetchMock.resetMocks();
Expand All @@ -71,11 +67,11 @@ describe('updateMetadataTrack action', () => {
fetchMock.mockResolvedValue(new Response(JSON.stringify({})));

await store.dispatch(
updateMetadataTrack(oldMetadataTrack, newMetadataTrack, mockExperiment.id),
renameMetadataTrack(oldMetadataTrack, newMetadataTrack, mockExperiment.id),
);

const actions = store.getActions();
expect(_.map(actions, 'type')).toEqual([EXPERIMENTS_METADATA_UPDATE, SAMPLES_UPDATE, SAMPLES_METADATA_DELETE]);
expect(_.map(actions, 'type')).toEqual([EXPERIMENTS_METADATA_RENAME]);
expect(_.map(actions, 'payload')).toMatchSnapshot();

expect(fetchMock).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,8 @@ Object {
}
`;

exports[`experimentsReducer Correctly creates project metadata 1`] = `
exports[`experimentsReducer Correctly creates experiment metadata 1`] = `
Object {
"[object Object]": Object {
"createdAt": "2021-01-01",
"description": "this is a test description",
"id": "experiment-1",
"metadataKeys": Array [],
"name": "experiment 1",
"notifyByEmail": true,
"sampleIds": Array [
"testSampleId",
],
"updatedAt": "2022-01-17",
},
"experiment-1": Object {
"createdAt": "2021-01-01",
"description": "this is a test description",
Expand All @@ -90,22 +78,8 @@ Object {
}
`;

exports[`experimentsReducer Correctly deletes project metadata 1`] = `
exports[`experimentsReducer Correctly deletes experiment metadata 1`] = `
Object {
"[object Object]": Object {
"createdAt": "2021-01-01",
"description": "this is a test description",
"id": "experiment-1",
"metadataKeys": Array [
"metadata-old",
],
"name": "experiment 1",
"notifyByEmail": true,
"sampleIds": Array [
"testSampleId",
],
"updatedAt": "2022-01-17",
},
"experiment-1": Object {
"createdAt": "2021-01-01",
"description": "this is a test description",
Expand All @@ -129,22 +103,8 @@ Object {
}
`;

exports[`experimentsReducer Correctly updates project metadata 1`] = `
exports[`experimentsReducer Correctly renames experiment metadata 1`] = `
Object {
"[object Object]": Object {
"createdAt": "2021-01-01",
"description": "this is a test description",
"id": "experiment-1",
"metadataKeys": Array [
"metadata-old",
],
"name": "experiment 1",
"notifyByEmail": true,
"sampleIds": Array [
"testSampleId",
],
"updatedAt": "2022-01-17",
},
"experiment-1": Object {
"createdAt": "2021-01-01",
"description": "this is a test description",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ Object {
}
`;

exports[`samplesReducer Handles experimentMetadataRename correctly 1`] = `
Object {
"asd123": Object {
"experimentId": "mockExpId",
"metadata": Object {
"metadata-new": "value",
},
},
"meta": Object {
"error": false,
"loading": false,
"saving": false,
},
}
`;

exports[`samplesReducer Handles samplesValueInMetadataTrackUpdated correctly 1`] = `
Object {
"asd123": Object {
Expand Down Expand Up @@ -324,33 +340,3 @@ Object {
},
}
`;

exports[`samplesReducer Updates sample metadata correctly 1`] = `
Object {
"[object Object]": Object {
"metadata": Object {
"metadata-test": "old-value",
},
},
"asd123": Object {
"complete": false,
"createdDate": "2021-01-01T14:48:00.000Z",
"error": false,
"experimentId": null,
"fileNames": Array [],
"files": Object {},
"lastModified": "2021-01-01T14:48:00.000Z",
"metadata": Object {
"metadata-test": "new-value",
},
"name": "test sample",
"type": null,
"uuid": "asd123",
},
"meta": Object {
"error": false,
"loading": false,
"saving": false,
},
}
`;
16 changes: 8 additions & 8 deletions src/__test__/redux/reducers/experimentsReducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
EXPERIMENTS_DELETED,
EXPERIMENTS_SAVING,
EXPERIMENTS_METADATA_CREATE,
EXPERIMENTS_METADATA_UPDATE,
EXPERIMENTS_METADATA_RENAME,
EXPERIMENTS_METADATA_DELETE,
} from 'redux/actionTypes/experiments';

Expand Down Expand Up @@ -294,12 +294,12 @@ describe('experimentsReducer', () => {
expect(newState).toMatchSnapshot();
});

it('Correctly creates project metadata', () => {
it('Correctly creates experiment metadata', () => {
const newMetadataKey = 'metadata-test';

const stateWithMetadata = {
...oneExperimentWithSampleState,
[oneExperimentWithSampleState[experiment1.id]]: {
[experiment1.id]: {
...oneExperimentWithSampleState[experiment1.id],
metadataKeys: [],
},
Expand All @@ -317,19 +317,19 @@ describe('experimentsReducer', () => {
expect(newState).toMatchSnapshot();
});

it('Correctly updates project metadata', () => {
it('Correctly renames experiment metadata', () => {
const oldMetadataKey = 'metadata-old';
const newMetadataKey = 'metadata-new';
const stateWithMetadata = {
...oneExperimentWithSampleState,
[oneExperimentWithSampleState[experiment1.id]]: {
[experiment1.id]: {
...oneExperimentWithSampleState[experiment1.id],
metadataKeys: [oldMetadataKey],
},
};

const newState = experimentsReducer(stateWithMetadata, {
type: EXPERIMENTS_METADATA_UPDATE,
type: EXPERIMENTS_METADATA_RENAME,
payload: {
oldKey: oldMetadataKey,
newKey: newMetadataKey,
Expand All @@ -341,11 +341,11 @@ describe('experimentsReducer', () => {
expect(newState).toMatchSnapshot();
});

it('Correctly deletes project metadata', () => {
it('Correctly deletes experiment metadata', () => {
const metadataKey = 'metadata-old';
const stateWithMetadata = {
...oneExperimentWithSampleState,
[oneExperimentWithSampleState[experiment1.id]]: {
[experiment1.id]: {
...oneExperimentWithSampleState[experiment1.id],
metadataKeys: [metadataKey],
},
Expand Down
Loading

0 comments on commit dcfcb2c

Please sign in to comment.