Skip to content

Commit

Permalink
Merge branch 'master' into 1928-fix-metadata-track-rename
Browse files Browse the repository at this point in the history
  • Loading branch information
cosa65 authored Jun 13, 2022
2 parents 09569f1 + ef10b9a commit 4a1c7a3
Show file tree
Hide file tree
Showing 66 changed files with 1,737 additions and 957 deletions.
3 changes: 1 addition & 2 deletions codecov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ coverage:
default:
target: auto
# don't allow new commits to decrease coverage
# Temporary to merge pr https://github.com/hms-dbmi-cellenics/ui/pull/723
threshold: 1%
threshold: 0%

patch: # measuring the coverage of new changes
default:
Expand Down
17 changes: 9 additions & 8 deletions src/__test__/components/ContentWrapper.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import AppRouteProvider from 'utils/AppRouteProvider';
import { makeStore } from 'redux/store';
import { getBackendStatus } from 'redux/selectors';
import { loadProjects, setActiveProject } from 'redux/actions/projects';
import { loadExperiments } from 'redux/actions/experiments';
import { updateExperimentInfo } from 'redux/actions/experimentSettings';
import generateGem2sParamsHash from 'utils/data-management/generateGem2sParamsHash';

import mockAPI, {
generateDefaultMockAPIResponses,
} from '__test__/test-utils/mockAPI';

import { experiments } from '__test__/test-utils/mockData';
import { projects } from '__test__/test-utils/mockData';

jest.mock('redux/selectors');
jest.mock('utils/socketConnection');
Expand Down Expand Up @@ -56,19 +57,18 @@ enableFetchMocks();

generateGem2sParamsHash.mockImplementation(() => 'mockParamsHash');

const experimentWithSamples = experiments.find((experiment) => experiment.samplesOrder.length > 0);

const sampleIds = experimentWithSamples.samplesOrder;

const experimentId = experimentWithSamples.id;
const projectWithSamples = projects.find((project) => project.samples.length > 0);
const experimentId = projectWithSamples.experiments[0];
const projectUuid = projectWithSamples.uuid;
const sampleIds = projectWithSamples.samples;

const experimentName = 'test experiment';
const experimentData = {
experimentId,
experimentName,
};

const mockAPIResponses = generateDefaultMockAPIResponses(experimentId);
const mockAPIResponses = generateDefaultMockAPIResponses(experimentId, projectUuid);

let store = null;

Expand Down Expand Up @@ -118,7 +118,8 @@ describe('ContentWrapper', () => {
}));

await store.dispatch(loadProjects());
await store.dispatch(setActiveProject(experimentId));
await store.dispatch(loadExperiments(projectUuid));
await store.dispatch(setActiveProject(projectUuid));
await store.dispatch(updateExperimentInfo({ experimentId, experimentName, sampleIds }));
});

Expand Down
2 changes: 1 addition & 1 deletion src/__test__/components/PlotContainer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let store = null;
fetchMock.mockIf(/.*/, (req) => {
const path = req.url;
// Saving config, return 200
if (path.match(`/v2/experiments/${experimentId}/plots/${plotUuid}`)) {
if (path.match(`/v1/experiments/${experimentId}/plots-tables/${plotUuid}`)) {
return Promise.resolve({ body: JSON.stringify('Plot saved') });
}
return Promise.resolve({ status: 404, body: JSON.stringify('Plot config not found') });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const createMockStore = configureMockStore([thunk]);

const mockOnCompute = jest.fn();
const experimentId = fake.EXPERIMENT_ID;

const defaultProps = {
experimentId,
onCompute: mockOnCompute,
Expand Down
18 changes: 8 additions & 10 deletions src/__test__/components/data-management/ProjectMenu.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import createTestComponentFactory from '__test__/test-utils/testComponentFactory
import mockAPI, { generateDefaultMockAPIResponses } from '__test__/test-utils/mockAPI';

import { loadProjects, setActiveProject } from 'redux/actions/projects';
import { experiments } from '__test__/test-utils/mockData';
import { projects } from '__test__/test-utils/mockData';
import ProjectMenu from 'components/data-management/ProjectMenu';

const mockNavigateTo = jest.fn();
Expand All @@ -37,20 +37,18 @@ jest.mock('utils/AppRouteProvider', () => ({
})),
}));

const experimentWithSamples = experiments.find((experiment) => experiment.samplesOrder.length > 0);
const experimentWithoutSamples = experiments.find(
(experiment) => experiment.samplesOrder.length === 0,
);
const projectWithSamples = projects.find((project) => project.samples.length > 0);
const projectWithoutSamples = projects.find((project) => project.samples.length === 0);

const experimentWithSamplesId = experimentWithSamples.id;
const experimentWithoutSamplesId = experimentWithoutSamples.id;
const experimentWithSamplesId = projectWithSamples.experiments[0];
const projectWithSamplesId = projectWithSamples.uuid;

const defaultAPIResponse = generateDefaultMockAPIResponses(
experimentWithSamplesId,
projectWithSamplesId,
);

const responses = _.merge(defaultAPIResponse, {
[`/v2/access/${fake.EXPERIMENT_ID}-1`]: () => (
[`/v1/access/${fake.EXPERIMENT_ID}-1`]: () => (
Promise.resolve(
new Response(JSON.stringify(
[{
Expand Down Expand Up @@ -82,7 +80,7 @@ describe('ProjectMenu', () => {
storeState = makeStore();

await storeState.dispatch(loadProjects());
await storeState.dispatch(setActiveProject(experimentWithoutSamplesId));
await storeState.dispatch(setActiveProject(projectWithoutSamples.uuid));
});

it('Renders correctly when there is a project', async () => {
Expand Down
49 changes: 29 additions & 20 deletions src/__test__/components/data-management/SamplesTable.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import userEvent from '@testing-library/user-event';
import { act } from 'react-dom/test-utils';
import '@testing-library/jest-dom';
import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';
import reactSortableHoc from 'react-sortable-hoc';

import Storage from '@aws-amplify/storage';

import _ from 'lodash';
import { Provider } from 'react-redux';

import mockAPI, { generateDefaultMockAPIResponses, statusResponse } from '__test__/test-utils/mockAPI';
import { experiments, samples } from '__test__/test-utils/mockData';
import { projects, samples } from '__test__/test-utils/mockData';

import SamplesTable from 'components/data-management/SamplesTable';
import { makeStore } from 'redux/store';
Expand All @@ -22,10 +21,14 @@ import createTestComponentFactory from '__test__/test-utils/testComponentFactory

import { loadProjects, setActiveProject } from 'redux/actions/projects';
import downloadFromUrl from 'utils/data-management/downloadFromUrl';

import loadEnvironment from 'redux/actions/networkResources/loadEnvironment';
import { loadExperiments } from 'redux/actions/experiments';

import reactSortableHoc from 'react-sortable-hoc';

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

jest.mock('config');

jest.mock('@aws-amplify/auth', () => ({
Expand Down Expand Up @@ -73,23 +76,24 @@ const renderSamplesTable = async (store) => {

enableFetchMocks();

const experimentWithSamples = experiments.find((experiment) => experiment.samplesOrder.length > 0);
const experimentWithoutSamples = experiments.find(
(experiment) => experiment.samplesOrder.length === 0,
);
const firstProjectWithSamples = projects.find((p) => p.samples.length > 0);
const projectIdWithSamples = firstProjectWithSamples.uuid;
const experimentIdWithSamples = firstProjectWithSamples.experiments[0];

const experimentWithSamplesId = experimentWithSamples.id;
const experimentWithoutSamplesId = experimentWithoutSamples.id;
const firstProjectWithoutSamples = projects.find((p) => p.samples.length === 0);
const projectIdWithoutSamples = firstProjectWithoutSamples.uuid;
const experimentIdWithoutSamples = firstProjectWithoutSamples.experiments[0];

// Mocking samples update / delete routes
const customResponses = {
[`experiments/${experimentWithSamplesId}/samples/${experimentWithSamples.samplesOrder[0]}`]: () => statusResponse(200, 'OK'),
[`experiments/${experimentWithSamplesId}/samples/position`]: () => statusResponse(200, 'OK'),
[`/projects/${projectIdWithSamples}`]: () => statusResponse(200, JSON.stringify('OK')),
[`/projects/${projectIdWithSamples}/${experimentIdWithSamples}/samples`]: () => statusResponse(200, 'OK'),
[`/v2/experiments/${projectIdWithSamples}/samples/position`]: () => statusResponse(200, 'OK'),
};

const mockAPIResponse = _.merge(
generateDefaultMockAPIResponses(experimentWithSamplesId),
generateDefaultMockAPIResponses(experimentWithoutSamplesId),
generateDefaultMockAPIResponses(experimentIdWithSamples, projectIdWithSamples),
generateDefaultMockAPIResponses(experimentIdWithoutSamples, projectIdWithoutSamples),
customResponses,
);

Expand All @@ -100,24 +104,27 @@ describe('Samples table', () => {
fetchMock.mockClear();
fetchMock.mockIf(/.*/, mockAPI(mockAPIResponse));

config.currentApiVersion = api.V1;

storeState = makeStore();

await storeState.dispatch(loadProjects());

// Loading experiment is usually called in Data Management, so we have to load them manually
await storeState.dispatch(loadExperiments(experimentWithSamplesId));
await storeState.dispatch(loadExperiments(experimentWithoutSamplesId));
await storeState.dispatch(loadExperiments(projectIdWithSamples));
await storeState.dispatch(loadExperiments(projectIdWithoutSamples));

// Defaults to project with samples
await storeState.dispatch(setActiveProject(experimentWithSamplesId));
await storeState.dispatch(setActiveProject(projectIdWithSamples));

await storeState.dispatch(loadEnvironment('test'));
});

it('Shows option to download datasets if there are no samples', async () => {
await renderSamplesTable(storeState);

// Load project without samples
storeState.dispatch(setActiveProject(experimentWithoutSamplesId));
storeState.dispatch(setActiveProject(projectIdWithoutSamples));

expect(screen.getByText(/Start uploading your samples by clicking on Add samples./i)).toBeInTheDocument();
expect(screen.getByText(/Don't have data\? Get started using one of our example datasets:/i)).toBeInTheDocument();
Expand Down Expand Up @@ -151,7 +158,7 @@ describe('Samples table', () => {
await renderSamplesTable(storeState);

// Load project without samples
storeState.dispatch(setActiveProject(experimentWithoutSamplesId));
storeState.dispatch(setActiveProject(projectIdWithoutSamples));

// This prompt to upload samples is still visible
expect(screen.getByText(/Start uploading your samples by clicking on Add samples./i)).toBeInTheDocument();
Expand All @@ -172,7 +179,7 @@ describe('Samples table', () => {
await renderSamplesTable(storeState);

// Load project without samples
storeState.dispatch(setActiveProject(experimentWithoutSamplesId));
storeState.dispatch(setActiveProject(projectIdWithoutSamples));

const linksContainer = screen.getByText(expectedSampleNames[0]).closest('ul');
const links = Array.from(linksContainer.children).map((el) => el.textContent);
Expand Down Expand Up @@ -275,6 +282,8 @@ describe('Samples table', () => {
});

it('Reorder samples send correct request in api v2', async () => {
config.currentApiVersion = api.V2;

let onSortEndProp;
reactSortableHoc.sortableContainer.mockImplementationOnce(() => (...params) => {
onSortEndProp = params[0].onSortEnd;
Expand All @@ -288,7 +297,7 @@ describe('Samples table', () => {
});

expect(fetchMock).toHaveBeenCalledWith(
`http://localhost:3000/v2/experiments/${experimentWithSamplesId}/samples/position`,
`http://localhost:3000/v2/experiments/${projectIdWithSamples}/samples/position`,
{
method: 'PUT',
headers: expect.anything(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`Share expeirment modal Inviting users works 1`] = `
Array [
"http://localhost:3000/v2/access/testae48e318dab9a1bd0bexperiment",
"http://localhost:3000/v1/access/testae48e318dab9a1bd0bexperiment",
Object {
"body": "{\\"projectUuid\\":\\"test24b6-8600-test-mock-63822d2fmock\\",\\"role\\":\\"explorer\\",\\"userEmail\\":\\"asd@asd.com\\"}",
"headers": Object {
Expand Down
2 changes: 1 addition & 1 deletion src/__test__/components/plots/DotPlot.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const experimentId = fake.EXPERIMENT_ID;
const plotUuid = 'dotPlotMain';

const customAPIResponses = {
[`/plots/${plotUuid}`]: () => statusResponse(404, 'Not found'),
[`/plots-tables/${plotUuid}`]: () => statusResponse(404, 'Not found'),
};

const mockAPIResponses = _.merge(
Expand Down
Loading

0 comments on commit 4a1c7a3

Please sign in to comment.