Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop' into gr-DT-979-appcues
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/components/SignInButton.tsx
  • Loading branch information
rushtong committed Nov 15, 2024
2 parents 5552e3d + 79aac19 commit 5ee185f
Show file tree
Hide file tree
Showing 16 changed files with 361 additions and 84 deletions.
65 changes: 65 additions & 0 deletions cypress/component/DataSearch/dataset_search_footer.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* eslint-disable no-undef */
import {mount} from 'cypress/react';
import {React} from 'react';
import {DatasetSearchFooter} from '../../../src/components/data_search/DatasetSearchFooter';

const datasets = [
{
datasetId: 123456,
study: {
studyId: 1,
}
},
{
datasetId: 234567,
study: {
studyId: 1,
}
},
{
datasetId: 345678,
study: {
studyId: 2,
}
},
];

const oneDatasetProps = {
selectedDatasets: [123456],
datasets: datasets,
onClick: () => {},
};

const oneStudyProps = {
selectedDatasets: [123456, 234567],
datasets: datasets,
onClick: () => {},
};

const twoStudiesProps = {
selectedDatasets: [123456, 234567, 345678],
datasets: datasets,
onClick: () => {},
};

describe('Dataset Search Footer renders correct text and button', () => {

it('Shows button and single dataset and study text', () => {
mount(<DatasetSearchFooter {...oneDatasetProps} />);
cy.contains('1 dataset selected from 1 study');
cy.contains('Apply for Access');
});


it('Shows button and two datasets from one study text', () => {
mount(<DatasetSearchFooter {...oneStudyProps} />);
cy.contains('2 datasets selected from 1 study');
cy.contains('Apply for Access');
});

it('Shows button and three datasets from two studies text', () => {
mount(<DatasetSearchFooter {...twoStudiesProps} />);
cy.contains('3 datasets selected from 2 studies');
cy.contains('Apply for Access');
});
});
43 changes: 43 additions & 0 deletions cypress/component/DataSearch/dataset_search_table.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-disable no-undef */
import {React} from 'react';
import {mount} from 'cypress/react';
import DatasetSearchTable from '../../../src/components/data_search/DatasetSearchTable';
import {TerraDataRepo} from '../../../src/libs/ajax/TerraDataRepo';

const datasets = [
{
datasetId: 123456,
datasetIdentifier: `DUOS-123456`,
datasetName: 'Some Dataset 1',
study: {
studyId: 1,
dataCustodianEmail: ['Some Data Custodian Email 1'],
}
}
];

const props = {
datasets: datasets,
history: {}
};

describe('Dataset Search Table tests', () => {

describe('Data library with three datasets', () => {
beforeEach(() => {
cy.stub(TerraDataRepo, 'listSnapshotsByDatasetIds').returns({});
mount(<DatasetSearchTable {...props} />);
});

it('When no datasets are selected the footer does not appear', () => {
cy.contains('1 dataset selected from 1 study').should('not.exist');
});


it('When a dataset is selected the footer appears', () => {
cy.get('#header-checkbox').click();
cy.contains('1 dataset selected from 1 study');
});

});
});
34 changes: 24 additions & 10 deletions cypress/component/SignIn/sign_in_button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ import {Metrics} from '../../../src/libs/ajax/Metrics';
import {StackdriverReporter} from '../../../src/libs/stackdriverReporter';
import {ToS} from '../../../src/libs/ajax/ToS';
import {mockOidcUser} from '../Auth/mockOidcUser';

const signInText = 'Sign In';

const duosUser = {
displayName: 'display name',
email: '[email protected]',
isAdmin: true,
isAlumni: false,
isChairPerson: false,
isDataSubmitter: false,
isMember: false,
isResearcher: false,
isSigningOfficial: false,
roles: [{
name: 'Admin'
}]
Expand All @@ -33,6 +39,11 @@ const notAcceptedUserStatus = Object.assign({}, userStatus, {'tosAccepted': fals

describe('Sign In: Component Loads', function () {

// Intercept configuration calls
beforeEach(() => {
cy.initApplicationConfig();
});

it('Sign In Button Loads', function () {
cy.viewport(600, 300);
mount(<SignInButton history={undefined}/>);
Expand All @@ -42,14 +53,15 @@ describe('Sign In: Component Loads', function () {
it('Sign In: On Success', function () {
cy.viewport(600, 300);
cy.stub(Auth, 'signIn').returns(Promise.resolve(mockOidcUser));
cy.stub(User, 'getMe').returns(duosUser);
cy.intercept({method: 'GET', url: '**/api/user/me'}, {statusCode: 200, body: duosUser}).as('getMe');
cy.stub(StackdriverReporter, 'report');
cy.stub(Metrics, 'identify');
cy.stub(Metrics, 'syncProfile');
cy.stub(Metrics, 'captureEvent');
cy.stub(ToS, 'getStatus').returns(userStatus);
mount(<SignInButton history={[]}/>);
cy.get('button').click().then(() => {
cy.get('button').click();
cy.wait('@getMe').then(() => {
expect(Storage.getCurrentUser()).to.deep.equal(duosUser);
expect(Storage.getAnonymousId()).to.not.be.null;
expect(StackdriverReporter.report).to.not.be.called;
Expand All @@ -63,29 +75,31 @@ describe('Sign In: Component Loads', function () {
const bareUser = {email: '[email protected]'};
cy.viewport(600, 300);
cy.stub(Auth, 'signIn').returns(Promise.resolve(mockOidcUser));
cy.stub(User, 'getMe').returns(bareUser);
cy.intercept({method: 'GET', url: '**/api/user/me'}, {statusCode: 200, body: bareUser}).as('getMe');
cy.stub(StackdriverReporter, 'report');
cy.stub(Metrics, 'identify');
cy.stub(Metrics, 'syncProfile');
cy.stub(Metrics, 'captureEvent');
cy.stub(ToS, 'getStatus').returns(userStatus);
mount(<SignInButton history={[]}/>);
cy.get('button').click().then(() => {
cy.get('button').click();
cy.wait('@getMe').then(() => {
expect(StackdriverReporter.report).to.be.called;
});
});

it('Sign In: Redirects to ToS if not accepted', function () {
cy.viewport(600, 300);
cy.stub(Auth, 'signIn').returns(Promise.resolve(mockOidcUser));
cy.stub(User, 'getMe').returns(duosUser);
cy.intercept({method: 'GET', url: '**/api/user/me'}, {statusCode: 200, body: duosUser}).as('getMe');
cy.stub(ToS, 'getStatus').returns(notAcceptedUserStatus);
cy.stub(Metrics, 'identify');
cy.stub(Metrics, 'syncProfile');
cy.stub(Metrics, 'captureEvent');
let history = [];
mount(<SignInButton history={history}/>);
cy.get('button').click().then(() => {
cy.get('button').click();
cy.wait('@getMe').then(() => {
expect(history).to.not.be.empty;
expect(history[0].includes('tos_acceptance')).to.be.true;
});
Expand All @@ -96,15 +110,15 @@ describe('Sign In: Component Loads', function () {
cy.stub(Auth, 'signIn').returns(Promise.resolve(mockOidcUser));
// Simulate user not found
cy.stub(User, 'getMe').throws();
cy.stub(User, 'registerUser').returns(duosUser);
cy.intercept({method: 'POST', url: '**/api/user'}, {statusCode: 200, body: duosUser}).as('registerUser');
cy.stub(ToS, 'getStatus').returns(notAcceptedUserStatus);
cy.stub(Metrics, 'identify');
cy.stub(Metrics, 'syncProfile');
cy.stub(Metrics, 'captureEvent');
let history = [];
mount(<SignInButton history={history}/>);
cy.get('button').click().then(() => {
expect(User.registerUser).to.be.called;
cy.get('button').click();
cy.wait('@registerUser').then(() => {
expect(history).to.not.be.empty;
expect(history[0].includes('tos_acceptance')).to.be.true;
});
Expand Down
50 changes: 50 additions & 0 deletions cypress/component/UserProfile/user_profile.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-disable no-undef */

import {mount} from 'cypress/react';
import React from 'react';
import {Storage} from '../../../src/libs/storage';
import {User} from '../../../src/libs/ajax/User';
import {Institution} from '../../../src/libs/ajax/Institution';
import UserProfile from '../../../src/pages/user_profile/UserProfile';

const duosUser = {
isSigningOfficial: false,
};

describe('User Profile', () => {
// Intercept configuration calls
beforeEach(() => {
cy.intercept({
method: 'GET',
url: '/config.json',
hostname: 'localhost',
}, {'env': 'ci'});
});

it('Renders the user profile page', () => {
cy.stub(Storage, 'getCurrentUser').returns(duosUser);
cy.stub(Institution, 'list').returns([]);
cy.stub(User, 'getMe').returns(duosUser);
cy.stub(User, 'getApprovedDatasets').returns([]);
cy.stub(User, 'getAcknowledgements').returns({});
mount(<UserProfile/>);
cy.get('h2').should('contain', 'Your Profile');
});

it('Updates the user email preferences', () => {
cy.stub(Storage, 'getCurrentUser').returns(duosUser);
cy.stub(Institution, 'list').returns([]);
cy.stub(User, 'getMe').returns(duosUser);
cy.stub(User, 'getApprovedDatasets').returns([]);
cy.stub(User, 'getAcknowledgements').returns({});
cy.intercept(
{method: 'PUT', url: '**/user'},
{statusCode: 200, body: duosUser}
).as('updateSelf');
mount(<UserProfile/>);
cy.get('input[id="profileEmailEnabled_yes"]').check();
cy.wait('@updateSelf').then(() => {
cy.get('div').contains('Email preference updated successfully!');
});
});
});
24 changes: 23 additions & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,26 @@ Cypress.Commands.add('auth', async (roleName) => {
const url = Cypress.env('baseUrl');
await client.request({ url });
return client.credentials;
});
});

Cypress.Commands.add('initApplicationConfig', () => {
cy.intercept({
method: 'GET',
url: '/config.json',
hostname: 'localhost',
}, {
'env': 'ci',
'hash': '',
'tag': '',
'bardApiUrl': '',
'apiUrl': '',
'ontologyApiUrl': '',
'terraUrl': '',
'tdrApiUrl': '',
'errorApiKey': '',
'profileUrl': '',
'nihUrl': '',
'gaId': '',
'features': {}
});
});
9 changes: 6 additions & 3 deletions src/components/SignInButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ export const SignInButton = (props: SignInButtonProps) => {

const syncSignInOrRegistrationEvent = async (event: MetricsEventName) => {
Storage.setAnonymousId();
await Metrics.identify(`${Storage.getAnonymousId()}`);
await Metrics.syncProfile();
await Metrics.captureEvent(event);
// noinspection ES6MissingAwait
Metrics.identify(`${Storage.getAnonymousId()}`);
// noinspection ES6MissingAwait
Metrics.syncProfile();
// noinspection ES6MissingAwait
Metrics.captureEvent(event);
};

const errorStreamToString = async (error: HttpError) => {
Expand Down
51 changes: 51 additions & 0 deletions src/components/dac_dataset_table/DACDatasetConstants.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {Styles} from '../../libs/theme';

export const styles = {
baseStyle: {
fontFamily: 'Montserrat',
fontSize: '1.6rem',
fontWeight: 400,
display: 'flex',
padding: '1rem 2%',
justifyContent: 'space-between',
alignItems: 'center',
whiteSpace: 'pre-wrap',
backgroundColor: 'white',
border: '1px solid #DEDEDE',
borderRadius: '4px',
margin: '0.5% 0'
},
columnStyle: Object.assign({}, Styles.TABLE.HEADER_ROW, {
justifyContent: 'space-between',
color: '#7B7B7B',
fontFamily: 'Montserrat',
fontSize: '1.2rem',
fontWeight: 'bold',
letterSpacing: '0.2px',
textTransform: 'uppercase',
backgroundColor: 'B8CDD3',
border: 'none'
}),
cellWidths: {
duosId: '10%',
phsId: '10%',
datasetName: '15%',
studyName: '15%',
dataSubmitter: '15%',
dataCustodian: '15%',
dataUse: '10%',
status: '10%'
},
color: {
dataUseGroup: '#000000',
votes: '#000000',
numberOfDatasets: '#000000',
datasets: '#000000',
},
fontSize: {
dataUseGroup: '1.4rem',
votes: '1.4rem',
numberOfDatasets: '1.4rem',
datasets: '1.4rem',
},
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import style from '../../pages/DACDatasets.module.css';
import {styles} from './DACDatasetsTable';
import {styles} from './DACDatasetConstants';
import DACDatasetApprovalStatus from './DACDatasetApprovalStatus';
import ReactTooltip from 'react-tooltip';

Expand Down
Loading

0 comments on commit 5ee185f

Please sign in to comment.