From 73e3ad70b9bc12bf5caa20939518343435425371 Mon Sep 17 00:00:00 2001 From: juhanikat Date: Thu, 7 Aug 2025 13:31:54 +0300 Subject: [PATCH 1/2] add tests for time bound creation inside time unit view --- cypress/e2e/timeUnit.cy.js | 49 +++++++++++++++++++ .../DetailView/common/EditingForm.tsx | 4 +- .../components/TimeUnit/Tabs/TimeUnitTab.tsx | 2 + 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/timeUnit.cy.js b/cypress/e2e/timeUnit.cy.js index 7d43ac1f..ed971731 100644 --- a/cypress/e2e/timeUnit.cy.js +++ b/cypress/e2e/timeUnit.cy.js @@ -40,6 +40,55 @@ describe('Creating a time unit', () => { cy.get('[id=write-button]').should('be.disabled') }) + it('with incorrect, newly created bounds does not work', () => { + cy.visit(`/time-unit/new`) + cy.get('[id=tu_display_name-textfield]').type('Testing Time Unit Creation') + cy.get('[id=sequence-tableselection]').first().click() + cy.get('[data-cy=add-button-ALMAAsianlandmammalage]').first().click() + cy.get('[id=low_bnd-tableselection]').click() + cy.get('[data-cy=add-button-11]').first().click() + + cy.get('[data-cy=add-new-up-bound-form]').click() + cy.get('[name=b_name]').type('new upper time bound name') + cy.get('[name=b_comment]').type('test comment') + + cy.get('[name=age]').type('one') + cy.contains('Save').click() + cy.contains('Value must be a valid number') + + cy.get('[name=age]').clear() + cy.get('[name=age]').type('-2') + cy.contains('Save').click() + cy.contains('Value must be a valid number') + + cy.get('[name=age]').clear() + cy.get('[name=age]').type('0123') + cy.contains('Save').click() + cy.contains('Value must be a valid number') + + cy.get('[name=age]').clear() + cy.get('[name=age]').type('0,5') + cy.contains('Save').click() + cy.contains('Value must be a valid number') + + cy.get('[name=age]').clear() + cy.get('[name=age]').type('1') + cy.contains('Save').click() + cy.contains('Value must be a valid number').should('not.exist') + + cy.get('[id=write-button]').should('not.be.disabled') + + cy.get('[data-cy=add-new-low-bound-form]').click() + cy.get('[name=b_name]').type('new lower time bound name') + cy.get('[name=b_comment]').type('test comment') + cy.get('[name=age]').type('0.5') + cy.contains('Save').click() + + cy.contains('Upper Bound: Upper bound age has to be lower than lower bound age') + cy.contains('Lower Bound: Lower bound age has to be higher than upper bound age') + cy.get('[id=write-button]').should('be.disabled') + }) + it('with incorrect bounds does not work', () => { cy.visit(`/time-unit/new`) cy.get('[id=tu_display_name-textfield]').type('Testing Time Unit Creation') diff --git a/frontend/src/components/DetailView/common/EditingForm.tsx b/frontend/src/components/DetailView/common/EditingForm.tsx index c257e92d..c0ba3d55 100755 --- a/frontend/src/components/DetailView/common/EditingForm.tsx +++ b/frontend/src/components/DetailView/common/EditingForm.tsx @@ -13,12 +13,14 @@ If using for adding new, provide arrayFieldName. For editing existing row, use existingObject and editAction. */ export const EditingForm = ({ + dataCy, buttonText, formFields, editAction, existingObject, arrayFieldName, }: { + dataCy?: string buttonText: string formFields: EditingFormField[] arrayFieldName?: keyof ParentType @@ -48,7 +50,7 @@ export const EditingForm = ({ } return ( - + {formFields.map(field => ( { {!mode.read && ( + dataCy="add-new-up-bound-form" buttonText="Add new time bound" formFields={formFields} editAction={(newUpTimeBound: TimeBound) => { @@ -105,6 +106,7 @@ export const TimeUnitTab = () => { {!mode.read && ( + dataCy="add-new-low-bound-form" buttonText="Add new time bound" formFields={formFields} editAction={(newLowTimeBound: TimeBound) => { From 6972797ae46138a3758c7886515eb6c56a042e70 Mon Sep 17 00:00:00 2001 From: juhanikat Date: Thu, 7 Aug 2025 13:48:19 +0300 Subject: [PATCH 2/2] add same tests for editing existing time unit --- cypress/e2e/timeUnit.cy.js | 42 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/timeUnit.cy.js b/cypress/e2e/timeUnit.cy.js index ed971731..bdf17a3d 100644 --- a/cypress/e2e/timeUnit.cy.js +++ b/cypress/e2e/timeUnit.cy.js @@ -89,7 +89,7 @@ describe('Creating a time unit', () => { cy.get('[id=write-button]').should('be.disabled') }) - it('with incorrect bounds does not work', () => { + it('with incorrect, existing bounds does not work', () => { cy.visit(`/time-unit/new`) cy.get('[id=tu_display_name-textfield]').type('Testing Time Unit Creation') cy.get('[id=sequence-tableselection]').first().click() @@ -199,7 +199,45 @@ describe('Editing a time unit', () => { cy.contains('ALMAAsianlandmammalage') }) - it('with incorrect bounds does not work', () => { + it('with incorrect, newly created bounds does not work', () => { + cy.visit(`/time-unit/bahean?tab=0`) + cy.get('[id=edit-button]').click() + cy.contains('7.2') // existing upper bound age + cy.contains('11.63') // existing lower bound age + + cy.get('[data-cy=add-new-up-bound-form]').click() + cy.get('[name=b_name]').type('new upper time bound name') + cy.get('[name=b_comment]').type('test comment') + cy.get('[name=age]').type('12') + cy.contains('Save').click() + cy.contains('Upper Bound: Upper bound age has to be lower than lower bound age') + cy.contains('Lower Bound: Lower bound age has to be higher than upper bound age') + cy.get('[id=write-button]').should('be.disabled') + + cy.get('[data-cy=add-new-up-bound-form]').click() + cy.get('[name=age]').clear() + cy.get('[name=age]').type('11.02') + cy.contains('Save').click() + cy.get('[id=write-button]').should('not.be.disabled') + + cy.get('[data-cy=add-new-low-bound-form]').click() + cy.get('[name=b_name]').type('new lower time bound name') + cy.get('[name=b_comment]').type('test comment') + cy.get('[name=age]').type('0.5') + cy.contains('Save').click() + + cy.contains('Upper Bound: Upper bound age has to be lower than lower bound age') + cy.contains('Lower Bound: Lower bound age has to be higher than upper bound age') + cy.get('[id=write-button]').should('be.disabled') + + cy.get('[data-cy=add-new-low-bound-form]').click() + cy.get('[name=age]').clear() + cy.get('[name=age]').type('15.55') + cy.contains('Save').click() + cy.get('[id=write-button]').should('not.be.disabled') + }) + + it('with incorrect, existing bounds does not work', () => { cy.visit(`/time-unit/bahean?tab=0`) cy.contains('Bahean') cy.get('[id=edit-button]').click()