Skip to content

Commit

Permalink
fix document uploading missing required validation and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tsubik committed Nov 3, 2023
1 parent 13e2657 commit b5f5752
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/ui/country-doc-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class DocModal extends React.Component {
name: 'file',
label: intl.formatMessage({ id: 'file' }),
required: !url,
default: { name: url }
default: !url ? null : { name: url }
}}
>
{File}
Expand Down
2 changes: 1 addition & 1 deletion components/ui/doc-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class DocModal extends React.Component {
name: 'file',
label: intl.formatMessage({ id: 'file' }),
required: !url,
default: { name: url }
default: !url ? null : { name: url }
}}
>
{File}
Expand Down
36 changes: 35 additions & 1 deletion e2e/cypress/e2e/operator.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('User', function () {
.should('contains.text', '50% Provided (valid)')
})

it('can delete existing document', function () {
it('can delete existing document and reupload it', function () {
cy.docExpandCategory('Legal registration');

cy.intercept('http://localhost:3000/operator-document-histories?*').as('documentsReload');
Expand All @@ -98,6 +98,27 @@ describe('User', function () {
.parents('.c-doc-by-category')
.find('.doc-by-category-chart')
.should('contains.text', '75% Provided (valid)')

cy.docGetProducerDocCard("Certificat d'agrément forestier")
.siblings('.c-doc-card-upload')
.contains('button', 'Add file')
.click();

// testing validation
cy.get('button').contains('Submit').click();
cy.get('.c-file ~ .error').should('have.text', 'The field is required');
cy.get('.rrt-text').should('have.text', 'Fill all the required fields');

cy.get('input[type=file]').attachFile('test_document.docx');

// cy.intercept('http://localhost:3000/operator-document-histories?*').as('documentsReload');
cy.get('button').contains('Submit').click();
cy.wait('@documentsReload');
cy.wait(1000);

cy.docGetProducerDocCard("Certificat d'agrément forestier")
.find('.doc-card-status')
.should('contains.text', 'Pending approval');
})

it('can mark document as non applicable', function () {
Expand All @@ -108,6 +129,11 @@ describe('User', function () {
.contains('button', 'Non applicable')
.click();

// testing validation
cy.get('button').contains('Submit').click();
cy.get('textarea[name=reason] ~ .error').should('have.text', 'The field is required');
cy.get('.rrt-text').should('have.text', 'Fill all the required fields');

cy.get('#input-startDate').type('2022-03-30');
cy.get('#input-expireDate').type('2030-03-30');
cy.get('#input-reason').clear().type('Reason why this document is non applicable');
Expand All @@ -134,6 +160,14 @@ describe('User', function () {
.click();

cy.contains('Add a document for the annex of Compte-rendu du conseil de concertation');

// testing validation
cy.get('button').contains('Submit').click();
cy.get('input[name=name] ~ .error').should('have.text', 'The field is required');
cy.get('input[name=startDate] ~ .error').should('have.text', 'The field is required');
cy.get('.c-file ~ .error').should('have.text', 'The field is required');
cy.get('.rrt-text').should('have.text', 'Fill all the required fields');

cy.get('#input-name').type('Here is the name of annex');
cy.get('#input-startDate').type('2022-03-30');
cy.get('#input-expireDate').type('2030-03-30');
Expand Down

0 comments on commit b5f5752

Please sign in to comment.