Skip to content

Commit

Permalink
feat: extract common json, split edit and manage edit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rushtong committed Nov 1, 2024
1 parent 68049b5 commit 5256704
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 136 deletions.
15 changes: 15 additions & 0 deletions cypress/component/DAC/admin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"userId": 2,
"displayName": "Admin",
"institution": {
"id": 150,
"name": "The Broad Institute of MIT and Harvard"
},
"roles": [
{
"userId": 2,
"roleId": 4,
"name": "Admin"
}
]
}
16 changes: 16 additions & 0 deletions cypress/component/DAC/chair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"userId": 1,
"displayName": "Chairperson",
"institution": {
"id": 150,
"name": "The Broad Institute of MIT and Harvard"
},
"roles": [
{
"userId": 1,
"roleId": 2,
"name": "Chairperson",
"dacId": 1
}
]
}
67 changes: 67 additions & 0 deletions cypress/component/DAC/dac.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"dacId": 1,
"name": "Test DAC",
"description": "Test DAC",
"createDate": "Oct 6, 2020",
"updateDate": "Jun 27, 2024",
"chairpersons": [
{
"userId": 1,
"email": "[email protected]",
"displayName": "Chairperson",
"createDate": 1704827256598,
"roles": [
{
"userId": 1,
"roleId": 2,
"name": "Chairperson",
"dacId": 1
}
],
"emailPreference": true,
"institutionId": 150,
"eraCommonsId": "test"
}
],
"members": [
{
"userId": 2,
"email": "[email protected]",
"displayName": "Member",
"createDate": 1704827256598,
"roles": [
{
"userId": 2,
"roleId": 1,
"name": "Member",
"dacId": 1
}
],
"emailPreference": true,
"institutionId": 150,
"eraCommonsId": "test"
}
],
"electionIds": [],
"datasetIds": [],
"email": "[email protected]",
"associatedDaa": {
"daaId": 1,
"createUserId": 5146,
"createDate": 1713386755554,
"updateUserId": 5146,
"updateDate": 1713386755554,
"initialDacId": 8,
"file": {
"fileStorageObjectId": 216,
"entityId": 1,
"fileName": "test_daa.txt",
"category": "dataAccessAgreement",
"mediaType": "application/octet-stream",
"createUserId": 5146,
"createDate": 1713386755554,
"deleted": false
},
"broadDaa": true
}
}
36 changes: 36 additions & 0 deletions cypress/component/DAC/editDac.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable no-undef */

import React from 'react';
import {mount} from 'cypress/react';
import {DAC} from '../../../src/libs/ajax/DAC';
import {Storage} from '../../../src/libs/storage';
import EditDac from '../../../src/pages/manage_dac/EditDac';
import {BrowserRouter} from 'react-router-dom';
import admin from './admin.json';
import chair from './chair.json';
import dac from './dac.json';

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

describe('EditDAC Tests', () => {

Cypress._.each([admin, chair], (user) => {
it('Should Load for ' + user.displayName, () => {
cy.viewport(600, 600);
cy.stub(Storage, 'getCurrentUser').returns(user);
cy.stub(DAC, 'get').returns(dac);
const props = {match: {params: {dacId: 1}}};
mount(WrappedEditDac(props));
cy.contains(dac.name).should('exist');
cy.get('[data-cy="dac_name"]').should('not.be.disabled');
cy.get('[data-cy="dac_description"]').should('not.be.disabled');
cy.get('[data-cy="dac_email"]').should('not.be.disabled');
cy.get('[data-cy="btn_save"]').should('not.be.disabled');
cy.get('[data-cy="btn_cancel"]').should('not.be.disabled');
});
});

});
135 changes: 0 additions & 135 deletions cypress/component/DAC/manageDac.spec.js

This file was deleted.

36 changes: 36 additions & 0 deletions cypress/component/DAC/manageEditDac.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable no-undef */

import React from 'react';
import {mount} from 'cypress/react';
import {DAC} from '../../../src/libs/ajax/DAC';
import {Storage} from '../../../src/libs/storage';
import ManageEditDac from '../../../src/pages/manage_dac/ManageEditDac';
import {BrowserRouter} from 'react-router-dom';
import admin from './admin.json';
import chair from './chair.json';
import dac from './dac.json';

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

describe('ManageEditDAC Tests', () => {

Cypress._.each([admin, chair], (user) => {
it('Should Load for ' + user.displayName, () => {
cy.viewport(600, 600);
cy.stub(Storage, 'getCurrentUser').returns(user);
cy.stub(DAC, 'get').returns(dac);
const props = {match: {params: {dacId: 1}}};
mount(WrappedManageEditDac(props));
cy.contains(dac.name).should('exist');
cy.get('[data-cy="dac_name"]').should('not.be.disabled');
cy.get('[data-cy="dac_description"]').should('not.be.disabled');
cy.get('[data-cy="dac_email"]').should('not.be.disabled');
cy.get('[data-cy="btn_save"]').should('not.be.disabled');
cy.get('[data-cy="btn_cancel"]').should('not.be.disabled');
});
});

});
5 changes: 5 additions & 0 deletions src/pages/manage_dac/EditDac.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ export default function EditDac(props) {
name='name'
className='form-control vote-input'
required={true}
data-cy='dac_name'
/>
</div>
</div>
Expand All @@ -385,6 +386,7 @@ export default function EditDac(props) {
name='description'
className='form-control vote-input'
required={true}
data-cy='dac_description'
/>
</div>
</div>
Expand All @@ -400,6 +402,7 @@ export default function EditDac(props) {
name='email'
className='form-control vote-input'
required={true}
data-cy='dac_email'
/>
</div>
</div>
Expand Down Expand Up @@ -459,6 +462,7 @@ export default function EditDac(props) {
id='btn_save'
onClick={okHandler}
className='f-left btn-primary common-background'
data-cy='btn_save'
>
Save
</button>
Expand All @@ -467,6 +471,7 @@ export default function EditDac(props) {
id='btn_cancel'
onClick={closeHandler}
className='f-left btn-secondary'
data-cy='btn_cancel'
>
Cancel
</button>
Expand Down
1 change: 0 additions & 1 deletion src/pages/manage_dac/ManageEditDac.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ export default function ManageEditDac(props) {
classNamePrefix='select'
placeholder='Select a DUOS User...'
className='select-autocomplete'
data-cy='sel_dacMember'
/>
</div>
</div>
Expand Down

0 comments on commit 5256704

Please sign in to comment.