Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BIOMAGE-1903] add two checkboxes for compliance #772

Merged
merged 40 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
051354f
TMP - Mock get auth info so it fetches the info from the fake userPoo…
cosa65 Jul 12, 2022
bb11357
Add basic layout
cosa65 Jul 12, 2022
78f0eda
Add functionality for PrivacyPolicyIntercept and connect it to cognito
cosa65 Jul 12, 2022
0a828f2
Some style updates to PrivacyPolicyIntercept
cosa65 Jul 13, 2022
74d3d5e
Minor fixes
cosa65 Jul 13, 2022
7693e91
Center vertically modal
cosa65 Jul 13, 2022
3060a0f
Add logout button
cosa65 Jul 13, 2022
48fbe73
Fix alignment of checkbox on updates
cosa65 Jul 13, 2022
b00800f
Add check on user attributes to decide whether to load data or not an…
cosa65 Jul 13, 2022
934a5ff
Use user from selector in UserButton
cosa65 Jul 13, 2022
e1894cc
Merge branch 'master' into 1903-add-two-checkboxes-for-compliance
cosa65 Jul 13, 2022
a0f2f84
Some cleanup
cosa65 Jul 14, 2022
eb00fa5
Remove console log
cosa65 Jul 14, 2022
eafe075
Fix contente wrappe tests
cosa65 Jul 14, 2022
e030491
Fix SamplesTable tests
cosa65 Jul 14, 2022
cd745de
Fix index of data-management
cosa65 Jul 14, 2022
11c4a6f
Update snapshots
cosa65 Jul 14, 2022
ebdd045
Merge branch 'master' into 1903-add-two-checkboxes-for-compliance
ivababukova Jul 14, 2022
de60c27
Fix profile test
cosa65 Jul 14, 2022
d0dadc6
Fix userButton tests
cosa65 Jul 14, 2022
c4b5f9a
Update snapshots
cosa65 Jul 14, 2022
09fc0e8
Fix based on comment
cosa65 Jul 15, 2022
cd5356e
Disable closing modal by clicking outside
cosa65 Jul 15, 2022
b6b8d97
Merge branch 'master' into 1903-add-two-checkboxes-for-compliance
cosa65 Jul 15, 2022
ef10bb5
Add 424 erros message
cosa65 Jul 15, 2022
d61c644
Add domainName loading from ssr
cosa65 Jul 15, 2022
5cdffd3
Make it include biomage staging
cosa65 Jul 15, 2022
6eedf1c
Minor refactoring
cosa65 Jul 15, 2022
7d15ea1
Fix _error.test.jsx
cosa65 Jul 15, 2022
9ae59ce
Fix
cosa65 Jul 15, 2022
f62cc54
Small fixes
cosa65 Jul 15, 2022
fc7b9d0
Remove unused import
cosa65 Jul 15, 2022
da9f7f9
Update text
cosa65 Jul 15, 2022
6b20c08
Fix networkResources hydration
cosa65 Jul 15, 2022
7cab480
Update snapshots
cosa65 Jul 15, 2022
483b740
Add privacyPolicyIsNotAccepted tsts
cosa65 Jul 18, 2022
3b257e3
Some minor refctoring and add tests fro ssrGetDeploymentINfo
cosa65 Jul 18, 2022
293abfd
Rever tmp changes, point back to real user pool
cosa65 Jul 18, 2022
47b2d2e
Update privacy policy
cosa65 Jul 19, 2022
6c5b8bc
Fix experiment switch carryover of user
cosa65 Jul 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/__test__/components/ContentWrapper.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ jest.mock('next/router', () => ({
}));

jest.mock('@aws-amplify/auth', () => ({
currentAuthenticatedUser: jest.fn().mockImplementation(async () => true),
currentAuthenticatedUser: jest.fn().mockImplementation(async () => ({
attributes: {
'custom:agreed_terms': 'true',
},
})),
federatedSignIn: jest.fn(),
}));

Expand Down Expand Up @@ -124,7 +128,6 @@ describe('ContentWrapper', () => {
await store.dispatch(updateExperimentInfo({ experimentId, experimentName, sampleIds }));
});

// PROBLEMATIC
it('renders correctly', async () => {
getBackendStatus.mockImplementation(() => () => ({
loading: false,
Expand Down
14 changes: 11 additions & 3 deletions src/__test__/components/data-management/SamplesTable.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ import thunk from 'redux-thunk';
import createTestComponentFactory from '__test__/test-utils/testComponentFactory';

import { loadExperiments, setActiveExperiment } from 'redux/actions/experiments';
import loadEnvironment from 'redux/actions/networkResources/loadEnvironment';
import loadDeploymentInfo from 'redux/actions/networkResources/loadDeploymentInfo';
import { loadSamples } from 'redux/actions/samples';

import mockDemoExperiments from '__test__/test-utils/mockData/mockDemoExperiments.json';
import { loadUser } from 'redux/actions/user';

jest.mock('@aws-amplify/auth', () => ({
currentAuthenticatedUser: jest.fn(() => Promise.resolve({ attributes: { name: 'mockUserName' } })),
currentAuthenticatedUser: jest.fn(() => Promise.resolve({
attributes: {
name: 'mockUserName',
'custom:agreed_terms': 'true',
},
})),
federatedSignIn: jest.fn(),
}));

Expand Down Expand Up @@ -103,7 +109,9 @@ describe('Samples table', () => {

// Defaults to project with samples
await storeState.dispatch(setActiveExperiment(experimentWithSamplesId));
await storeState.dispatch(loadEnvironment('test'));
await storeState.dispatch(loadDeploymentInfo({ environment: 'test' }));

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

it('Does not show prompt to upload datasets if samples are available', async () => {
Expand Down
28 changes: 22 additions & 6 deletions src/__test__/components/header/UserButton.test.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

import { screen, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { act } from 'react-dom/test-utils';
Expand All @@ -6,12 +8,19 @@ import Auth from '@aws-amplify/auth';

import UserButton from 'components/header/UserButton';
import createTestComponentFactory from '__test__/test-utils/testComponentFactory';
import { Provider } from 'react-redux';
import { makeStore } from 'redux/store';
import { loadUser } from 'redux/actions/user';

const UserButtonFactory = createTestComponentFactory(UserButton);

const renderUserButton = async () => {
const renderUserButton = async (store) => {
await act(async () => {
render(UserButtonFactory({}));
render(
<Provider store={store}>
{UserButtonFactory(store)}
</Provider>,
);
});
};

Expand All @@ -26,32 +35,39 @@ const getLoginButton = () => {
};

describe('UserButton', () => {
let store;

beforeEach(async () => {
jest.clearAllMocks();

Auth.currentAuthenticatedUser = jest.fn(() => Promise.resolve({ attributes: { name: userName } }));
store = makeStore();

Auth.currentAuthenticatedUser = jest.fn(() => Promise.resolve({ attributes: { name: userName, 'custom:agreed_terms': 'true' } }));
Auth.signOut = jest.fn(() => { });
Auth.federatedSignIn = jest.fn(() => { });

store.dispatch(loadUser());
});

it('Shows sign in by default', async () => {
Auth.currentAuthenticatedUser = jest.fn(() => Promise.resolve(null));
store.dispatch(loadUser());

await renderUserButton();
await renderUserButton(store);

expect(screen.getByText(/Sign in/i)).toBeInTheDocument();
});

it('Shows the user initial for the ', async () => {
const userInitial = getUserInitial();

await renderUserButton();
await renderUserButton(store);

expect(screen.getByText(userInitial)).toBeInTheDocument();
});

it('Clicking on menu opens up the menu bar', async () => {
await renderUserButton();
await renderUserButton(store);

const button = getLoginButton();

Expand Down
8 changes: 8 additions & 0 deletions src/__test__/pages/__snapshots__/_error.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Array [
},
},
"networkResources": Object {
"domainName": "scp.biomage.net",
"environment": "production",
},
"samples": Object {
Expand All @@ -143,6 +144,9 @@ Array [
"saving": false,
},
},
"user": Object {
"current": null,
},
},
]
`;
Expand Down Expand Up @@ -281,6 +285,7 @@ Array [
},
},
"networkResources": Object {
"domainName": "scp.biomage.net",
"environment": "staging",
},
"samples": Object {
Expand All @@ -290,6 +295,9 @@ Array [
"saving": false,
},
},
"user": Object {
"current": null,
},
},
]
`;
11 changes: 6 additions & 5 deletions src/__test__/pages/_error.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Provider } from 'react-redux';
import { makeStore } from 'redux/store';

import postErrorToSlack from 'utils/postErrorToSlack';
import loadEnvironment from 'redux/actions/networkResources/loadEnvironment';
import loadDeploymentInfo from 'redux/actions/networkResources/loadDeploymentInfo';
import { DomainName } from 'utils/deploymentInfo';

import createTestComponentFactory from '__test__/test-utils/testComponentFactory';

Expand Down Expand Up @@ -36,7 +37,7 @@ describe('ErrorPage', () => {
beforeEach(() => {
jest.clearAllMocks();
storeState = makeStore();
storeState.dispatch(loadEnvironment('production'));
storeState.dispatch(loadDeploymentInfo({ environment: 'production', domainName: DomainName.BIOMAGE }));
});

it('Renders properly without props', () => {
Expand Down Expand Up @@ -70,7 +71,7 @@ describe('ErrorPage', () => {
});

it('Should post error to Slack if environment is production', () => {
storeState.dispatch(loadEnvironment('production'));
storeState.dispatch(loadDeploymentInfo({ environment: 'production', domainName: DomainName.BIOMAGE }));

renderErrorPage(mockErrorProp, storeState);

Expand All @@ -79,7 +80,7 @@ describe('ErrorPage', () => {
});

it('Should post error to Slack if environment is staging', () => {
storeState.dispatch(loadEnvironment('staging'));
storeState.dispatch(loadDeploymentInfo({ environment: 'staging', domainName: DomainName.BIOMAGE }));

renderErrorPage(mockErrorProp, storeState);

Expand All @@ -88,7 +89,7 @@ describe('ErrorPage', () => {
});

it('Should not post error to Slack if environment is not production', () => {
storeState.dispatch(loadEnvironment('development'));
storeState.dispatch(loadDeploymentInfo({ environment: 'development', domainName: DomainName.BIOMAGE }));

renderErrorPage(mockErrorProp, storeState);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import _ from 'lodash';

import { render, screen, waitFor } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import fetchMock, { enableFetchMocks } from 'jest-fetch-mock';
import { Provider } from 'react-redux';
Expand All @@ -20,7 +20,8 @@ import DataManagementPage from 'pages/data-management';
import userEvent from '@testing-library/user-event';

import { setActiveExperiment } from 'redux/actions/experiments';
import loadEnvironment from 'redux/actions/networkResources/loadEnvironment';
import loadDeploymentInfo from 'redux/actions/networkResources/loadDeploymentInfo';
import { loadUser } from 'redux/actions/user';

jest.mock('utils/data-management/downloadFromUrl');
jest.mock('react-resize-detector', () => (props) => props.children({ width: 100, height: 100 }));
Expand All @@ -34,7 +35,12 @@ jest.mock('utils/AppRouteProvider', () => ({
}));

jest.mock('@aws-amplify/auth', () => ({
currentAuthenticatedUser: jest.fn(() => Promise.resolve({ attributes: { name: 'mockUserName' } })),
currentAuthenticatedUser: jest.fn(() => Promise.resolve({
attributes: {
name: 'mockUserName',
'custom:agreed_terms': 'true',
},
})),
federatedSignIn: jest.fn(),
}));

Expand All @@ -53,11 +59,6 @@ const experimentWithoutSamples = experiments.find(
(experiment) => experiment.samplesOrder.length === 0,
);

const expectedSampleNames = [
'Example 1',
'Another-Example no.2',
];

const experimentWithSamplesId = experimentWithSamples.id;
const experimentWithoutSamplesId = experimentWithoutSamples.id;

Expand All @@ -79,7 +80,8 @@ describe('Data Management page', () => {
fetchMock.mockIf(/.*/, mockAPI(mockAPIResponse));

storeState = makeStore();
storeState.dispatch(loadEnvironment('test'));
storeState.dispatch(loadDeploymentInfo({ environment: 'test' }));
storeState.dispatch(loadUser());
});

it('Shows an empty project list if there are no projects', async () => {
Expand Down
47 changes: 36 additions & 11 deletions src/__test__/pages/settings/profile/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import { render, screen } from '@testing-library/react';
import { act } from 'react-dom/test-utils';
import userEvent from '@testing-library/user-event';
import { useRouter } from 'next/router';
import { makeStore } from 'redux/store';
import createTestComponentFactory from '__test__/test-utils/testComponentFactory';
import Auth from '@aws-amplify/auth';
import ProfileSettings from 'pages/settings/profile';
import pushNotificationMessage from 'utils/pushNotificationMessage';
import { Provider } from 'react-redux';

import { loadUser } from 'redux/actions/user';
import loadDeploymentInfo from 'redux/actions/networkResources/loadDeploymentInfo';

jest.mock('next/router', () => ({
useRouter: jest.fn(),
Expand All @@ -16,19 +21,43 @@ jest.mock('next/router', () => ({
jest.mock('@aws-amplify/auth', () => jest.fn());
jest.mock('utils/pushNotificationMessage');

const profileSettingsPageFactory = createTestComponentFactory(ProfileSettings);
const updateMock = jest.fn(() => Promise.resolve(true));

const profileSettingsPageFactory = createTestComponentFactory(ProfileSettings);

const renderProfileSettingsPage = (store, newState = {}) => {
render(
<Provider store={store}>
{profileSettingsPageFactory(newState)}
</Provider>,
);
};

const setUpAuthMocks = () => {
Auth.currentAuthenticatedUser = jest.fn(() => Promise.resolve({
attributes: {
name: userName,
'custom:agreed_terms': 'true',
},
}));
Auth.signOut = jest.fn(() => { });
Auth.federatedSignIn = jest.fn(() => { });
Auth.updateUserAttributes = updateMock;
};

const userName = 'Arthur Dent';
jest.mock('components/Header', () => () => <></>);

describe('Profile page', () => {
const store = makeStore();

beforeEach(async () => {
jest.clearAllMocks();
Auth.currentAuthenticatedUser = jest.fn(() => Promise.resolve({ attributes: { name: userName } }));
Auth.signOut = jest.fn(() => { });
Auth.federatedSignIn = jest.fn(() => { });
Auth.updateUserAttributes = updateMock;

setUpAuthMocks();

store.dispatch(loadDeploymentInfo({ environment: 'test' }));
store.dispatch(loadUser());
});

it('check that the back button is called on cancel', async () => {
Expand All @@ -38,9 +67,7 @@ describe('Profile page', () => {
}));

await act(async () => {
render(
profileSettingsPageFactory(),
);
renderProfileSettingsPage(store);
});

await act(async () => {
Expand All @@ -52,9 +79,7 @@ describe('Profile page', () => {

it('check update is called on Save changes', async () => {
await act(async () => {
render(
profileSettingsPageFactory(),
);
renderProfileSettingsPage(store);
});

const nameInput = screen.getByPlaceholderText(userName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ Object {
},
},
"networkResources": Object {
"domainName": undefined,
"environment": undefined,
},
"samples": Object {
Expand Down Expand Up @@ -321,6 +322,9 @@ Object {
"uuid": "test9188-d682-test-mock-cb6d644cmock-2",
},
},
"user": Object {
"current": null,
},
}
`;

Expand Down Expand Up @@ -507,6 +511,7 @@ Object {
},
},
"networkResources": Object {
"domainName": undefined,
"environment": undefined,
},
"samples": Object {
Expand Down Expand Up @@ -645,5 +650,8 @@ Object {
"uuid": "test9188-d682-test-mock-cb6d644cmock-2",
},
},
"user": Object {
"current": null,
},
}
`;
Loading