Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
s-rubenstein committed Dec 5, 2024
1 parent 7cb22c9 commit 5cf5328
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
6 changes: 6 additions & 0 deletions DEVNOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,10 @@ To run cypress component tests in a browser:
```shell
npm run cypress:open:component
```

To run a single test suite:

```shell
npm run cypress:open:component --spec "**/data_access_governance.spec.js"
```

82 changes: 82 additions & 0 deletions cypress/component/StudyDetails/StudyDetails.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* eslint-disable no-undef */

import React from 'react';
import {mount} from 'cypress/react';
import { StudyDetails } from '../../../src/components/study_details/StudyDetails';
import {TerraDataRepo} from '../../../src/libs/ajax/TerraDataRepo';
import {DataSet} from '../../../src/libs/ajax/DataSet';
import {BrowserRouter} from 'react-router-dom';

const datasets = [
{
datasetId: 123456,
datasetIdentifier: `DUOS-123456`,
datasetName: 'Some Dataset 1',
participantCount: 1,
study: {
studyId: 1,
studyName: 'study name',
description: 'study description',
phenotype: 'phenotype',
species: 'species',
piName: 'piName',
dataCustodianEmail: ['[email protected]', '[email protected]'],
}
},
{
datasetId: 123457,
datasetIdentifier: `DUOS-123457`,
datasetName: 'Some Dataset 2',
participantCount: 2,
study: {
studyId: 1,
studyName: 'study name',
description: 'study description',
phenotype: 'phenotype',
species: 'species',
piName: 'piName',
dataCustodianEmail: ['[email protected]', '[email protected]'],
}
}
];

// It's necessary to wrap components that contain `Link` components
const WrappedStudyDetailsComponent = (props) => {
return <BrowserRouter>
<StudyDetails {...props}/>
</BrowserRouter>;
};


describe('Study details test', () => {
beforeEach(() => {
cy.stub(TerraDataRepo, 'listSnapshotsByDatasetIds').returns({});
cy.stub(DataSet, 'searchDatasetIndex').returns(Promise.resolve(datasets));
const props = {
history: {},
match: { params: { studyId: 1 } }
};
// @ts-ignore
mount(<WrappedStudyDetailsComponent {...props} />);
});

it('shows the appropriate data for fields', () => {
cy.contains(datasets[0].study.studyName).should('exist');
cy.contains(datasets[0].study.description).should('exist');
cy.contains((datasets[0].participantCount + datasets[1].participantCount).toString()).should('exist');
cy.contains(datasets[0].study.phenotype).should('exist');
cy.contains(datasets[0].study.species).should('exist');
cy.contains(datasets[0].study.piName).should('exist');
cy.contains(datasets[0].study.dataCustodianEmail.join(', ')).should('exist');
cy.get('[role=row]').should('have.length', datasets.length + 1);
});

it('displays DatasetSearchFooter when dataset is selected', () => {
cy.get('.row-data-0').find('input').click();
cy.contains('1 dataset selected from 1 study').should('exist');
});

it('allows navigation back to datalibrary', () => {
cy.get('#link_datalibrary').should('have.attr', 'href', '/datalibrary');
});
});

0 comments on commit 5cf5328

Please sign in to comment.