Skip to content

Commit

Permalink
add more e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyaGu committed Feb 6, 2020
1 parent a930f5e commit ade8e67
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 101 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports = {
// unecessary rerenders does not - at present - apply
'react/no-array-index-key': 0,
"jest/no-export": "off",
"jest/expect-expect": "off"
"jest/expect-expect": "off",
"jest/valid-expect-in-promise": "off"
},
overrides: [{
env: {browser: true},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ describe('End-to-end - delete record', () => {

cy.get('[data-button-type="delete"]').click();

cy.window()
.its('confirm')
.should('called', 1);
cy.window()
.its('confirm.args.0')
.should('deep.eq', [deleteConfirmText]);
cy.window().then(win => {
cy.wrap(win)
.its('confirm')
.should('called', 1);
cy.wrap(win)
.its('confirm.args.0')
.should('deep.eq', [deleteConfirmText]);
});
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);
});
Expand Down
179 changes: 151 additions & 28 deletions packages/tc-ui/src/pages/edit/__tests__/e2e-edit-record.cyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ const {
code,
anotherDocument,
someString,
anotherString,
someEnum,
someDate,
someDatetime,
} = require('../../../test-helpers/mainTypeData.json');
const {
populateMinimumViableFields,
Expand Down Expand Up @@ -77,32 +80,89 @@ describe('End-to-end - edit record', () => {
.should('have.attr', 'href', `/ChildType/${code}-second-child`);
});

it('can edit other non minimum viable fields of a record', () => {
it('can edit document type fields', () => {
cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);

visitEditPage();
cy.get('textarea[name=anotherDocument]').type(anotherDocument);
save();

cy.url().should('contain', `/MainType/${code}`);
cy.get('#anotherDocument').should('have.text', anotherDocument);

visitEditPage();
cy.get('textarea[name=anotherDocument]').type(` ${anotherString}`);
save();

cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);
cy.get('#anotherDocument').should(
'have.text',
`${anotherDocument} ${anotherString}`,
);
});

it('can edit boolean type fields', () => {
cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);

visitEditPage();
cy.get('[type="radio"]')
.first()
.check({ force: true });
cy.get('select[name=someEnum]').select(someEnum);
cy.get('#checkbox-someMultipleChoice-First').check({ force: true });
cy.get('#checkbox-someMultipleChoice-Third').check({ force: true });
save();
cy.url().should('contain', `/MainType/${code}`);
cy.get('#someBoolean').should('have.text', 'Yes');

visitEditPage();
cy.get('[type="radio"]')
.eq(1)
.check({ force: true });
save();

cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);
cy.get('#children>li')
.eq(0)
.should('have.text', `${code}-first-child`)
.find('a')
.should('have.attr', 'href', `/ChildType/${code}-first-child`);
cy.get('#anotherDocument').should('have.text', anotherDocument);
cy.get('#someBoolean').should('have.text', 'Yes');
cy.get('#someBoolean').should('have.text', 'No');
});

it('can edit enum type fields', () => {
cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);

visitEditPage();
cy.get('select[name=someEnum]').select(someEnum);
save();

cy.url().should('contain', `/MainType/${code}`);
cy.get('#someEnum').should('have.text', someEnum);

visitEditPage();
cy.get('select[name=someEnum]').select(`Third`);
save();

cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);
cy.get('#someEnum').should('have.text', 'Third');
});

it('can edit multiple choice type fields', () => {
cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);

visitEditPage();
cy.get('#checkbox-someMultipleChoice-First').check({ force: true });
cy.get('#checkbox-someMultipleChoice-Third').check({ force: true });
save();

cy.url().should('contain', `/MainType/${code}`);
cy.get('#someMultipleChoice span:first-child').should(
'have.text',
'First',
Expand All @@ -116,30 +176,13 @@ describe('End-to-end - edit record', () => {
.should('have.length', 2);

visitEditPage();

cy.get('textarea[name=anotherDocument]').type(` - updated`);
cy.get('[type="radio"]')
.eq(1)
.check({ force: true });
cy.get('select[name=someEnum]').select(`Third`);
cy.get('#checkbox-someMultipleChoice-Third').uncheck({ force: true });
cy.get('#checkbox-someMultipleChoice-Second').check({ force: true });
save();

cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);
cy.get('#children>li')
.eq(0)
.should('have.text', `${code}-first-child`)
.find('a')
.should('have.attr', 'href', `/ChildType/${code}-first-child`);
cy.get('#anotherDocument').should(
'have.text',
`${anotherDocument} - updated`,
);
cy.get('#someBoolean').should('have.text', 'No');
cy.get('#someEnum').should('have.text', 'Third');
cy.get('#someMultipleChoice span:first-child').should(
'have.text',
'First',
Expand All @@ -152,4 +195,84 @@ describe('End-to-end - edit record', () => {
.children()
.should('have.length', 2);
});

it('can edit date type fields', () => {
cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);

visitEditPage();
cy.get('input[name=someDate]')
.click()
.then(input => {
input[0].dispatchEvent(new Event('input', { bubbles: true }));
input.val(someDate);
})
.click();
save();

cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);
cy.get('#someDate').should('have.text', '15 January 2020');

visitEditPage();

cy.get('input[name=someDate]')
.click()
.then(input => {
input[0].dispatchEvent(new Event('input', { bubbles: true }));
input.val('2022-09-12');
})
.click();
save();

cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);
cy.get('#someDate').should('have.text', '12 September 2022');
});

it('can edit date-time type fields', () => {
cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);

visitEditPage();
cy.get('input[name=someDatetime]')
.click()
.then(input => {
input[0].dispatchEvent(new Event('input', { bubbles: true }));
input.val(someDatetime);
})
.click();
save();

cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);
cy.get('#someDatetime').should(
'have.text',
'15 January 2020, 1:00:00 PM',
);

visitEditPage();

cy.get('input[name=someDatetime]')
.click()
.then(input => {
input[0].dispatchEvent(new Event('input', { bubbles: true }));
input.val('2022-11-12T19:00');
})
.click();
save();

cy.url().should('contain', `/MainType/${code}`);
cy.get('#code').should('have.text', code);
cy.get('#someString').should('have.text', someString);
cy.get('#someDatetime').should(
'have.text',
'12 November 2022, 7:00:00 PM',
);
});
});
Loading

0 comments on commit ade8e67

Please sign in to comment.