Files
nowdatabase/cypress/e2e/locality.cy.js
T
2024-11-15 17:42:28 +02:00

197 lines
8.5 KiB
JavaScript

describe('Creating a new locality', () => {
beforeEach('Login as admin', () => {
cy.login('testSu')
})
it('with valid data works', () => {
cy.visit('/locality/new/')
cy.contains('Creating new locality')
cy.get('[name=dating-method]').should('have.value', 'time_unit')
cy.get('[name=dating-method][value=absolute]').click()
cy.get('[id="Min Basis for age (absolute)-multiselect"]').click()
cy.get('[data-value=other_absolute]').click()
cy.contains('other_absolute')
// test clearing of age fields
cy.get('[name=dating-method][value=time_unit]').click()
cy.contains('other_absolute').should('not.exist')
cy.get('[name=dating-method][value=absolute]').click()
cy.get('[id="Min Basis for age (absolute)-multiselect"]').click()
cy.get('[data-value=other_absolute]').click()
cy.get('[id="Max Basis for age (absolute)-multiselect"]').click()
cy.get('[data-value=other_absolute]').click()
cy.get('[id=min_age-textfield]').type('10.23')
cy.get('[id=max_age-textfield]').type('24.01')
cy.get('[role=tablist]').contains('Locality').click()
cy.get('[id=loc_name-textfield]').type('Bugat')
cy.get('[id=country-textfield]').type('Mongolia')
cy.get('[id=dec_lat-textfield]').type('49.07')
cy.get('[id=dec_long-textfield]').type('103.67')
cy.get('[id=dms_lat-textfield]').should('have.value', '49 4 12 N')
cy.get('[id=dms_long-textfield]').should('have.value', '103 40 12 E')
cy.get('[id=write-button]').click()
cy.get('[id=write-button]').click()
cy.contains('Edited item successfully.')
cy.contains('Bugat')
cy.get('[id=delete-button]').should('exist')
cy.visit('/locality/')
cy.contains('Bugat')
})
it("with missing country, min basis for age and longitude doesn't work", () => {
cy.visit('/locality/new/')
cy.contains('Creating new locality')
cy.get('[id=write-button]').should('be.disabled')
cy.get('[name=dating-method][value=absolute]').click()
cy.get('[id="Max Basis for age (absolute)-multiselect"]').click()
cy.get('[data-value=other_absolute]').click()
cy.get('[id=min_age-textfield]').type('11.61')
cy.get('[id=max_age-textfield]').type('35.22')
cy.contains('This field is required')
cy.get('[role=tablist]').contains('Locality').click()
cy.get('[id=loc_name-textfield]').type('Eg')
cy.get('[id=dec_lat-textfield]').type('48.68')
cy.get('[id=dms_lat-textfield]').should('have.value', '48 40 48 N')
cy.contains('This field is required')
cy.get('[id=write-button]').should('be.disabled')
})
it("and filling, then erasing needed data doesn't work", () => {
cy.visit('/locality/new/')
cy.contains('Creating new locality')
cy.get('[name=dating-method][value=absolute]').click()
cy.get('[id="Min Basis for age (absolute)-multiselect"]').click()
cy.get('[data-value=other_absolute]').click()
cy.get('[id="Max Basis for age (absolute)-multiselect"]').click()
cy.get('[data-value=other_absolute]').click()
cy.get('[id=min_age-textfield]').type('11.61')
cy.get('[id=max_age-textfield]').type('35.22')
cy.get('[role=tablist]').contains('Locality').click()
cy.get('[id=loc_name-textfield]').type('Bugat')
cy.get('[id=country-textfield]').type('Mongolia')
cy.get('[id=dec_lat-textfield]').type('49.07')
cy.get('[id=dec_long-textfield]').type('103.67')
cy.get('[id=dms_lat-textfield]').should('have.value', '49 4 12 N')
cy.get('[id=dms_long-textfield]').should('have.value', '103 40 12 E')
// all required data is provided so the write button is enabled
cy.get('[id=write-button]').should('not.be.disabled')
cy.get('[id=dec_lat-textfield]').type('{backspace}{backspace}{backspace}{backspace}{backspace}')
cy.contains('This field is required')
cy.get('[id=write-button]').should('be.disabled')
cy.get('[id=dec_lat-textfield]').type('49.07')
cy.get('[id=write-button]').should('not.be.disabled')
cy.get('[role=tablist]').contains('Age').click()
cy.get('[id=min_age-textfield]').type('{backspace}{backspace}{backspace}{backspace}{backspace}')
cy.contains('This field is required')
cy.get('[id=write-button]').should('be.disabled')
// make sure errors in other tabs disable the write button
cy.get('[role=tablist]').contains('Locality').click()
cy.get('[id=write-button]').should('be.disabled')
})
it('write button is disabled if unvisited tab has validation errors', () => {
cy.visit('/locality/new/')
cy.contains('Creating new locality')
cy.get('[name=dating-method][value=absolute]').click()
cy.get('[id="Min Basis for age (absolute)-multiselect"]').click()
cy.get('[data-value=other_absolute]').click()
cy.get('[id="Max Basis for age (absolute)-multiselect"]').click()
cy.get('[data-value=other_absolute]').click()
cy.get('[id=min_age-textfield]').type('11.61')
cy.get('[id=max_age-textfield]').type('35.22')
// Age tab has no errors, but Locality tab has unfilled mandatory fields
cy.get('[id=write-button]').should('be.disabled')
cy.get('[id=min_age-textfield-helper-text]').should('not.exist')
cy.get('[id=max_age-textfield-helper-text]').should('not.exist')
cy.contains('This field is required').should('not.exist')
cy.get('[role=tablist]').contains('Locality').click()
cy.contains('This field is required')
cy.get('[id=write-button]').should('be.disabled')
})
it('composite dating method works', () => {
cy.visit('/locality/new')
cy.get('[name=dating-method][value=composite]').click()
cy.get('[id=bfa_min-tableselection-helper-text]').contains(
'One age row must follow the rules for Absolute, the other for Time Unit'
)
cy.get('[id="Max Basis for age (absolute)-multiselect"]').click()
cy.get('[data-value=chemical]').click()
cy.get('[id=max_age-textfield]').type('12.3')
cy.get('[id=bfa_min-tableselection-helper-text]').contains('This field is required')
cy.get('[id="Min Basis for age (absolute)-multiselect"]').should('have.attr', 'aria-disabled', 'true')
cy.get('[id=bfa_max-tableselection]').should('be.disabled')
cy.get('[id="Maximum fraction-multiselect"]').should('have.attr', 'aria-disabled', 'true')
cy.get('[id="Minimum fraction-multiselect"]').click()
cy.get('[data-value="2:3"]').click()
cy.get('[id=bfa_min-tableselection]').click()
cy.get('[data-cy=detailview-button-bahean]').click()
cy.get('[id=min_age-textfield]').should('have.value', '8.676666666666668')
cy.get('[role=tablist]').contains('Locality').click()
cy.get('[id=loc_name-textfield]').type('Bugat')
cy.get('[id=country-textfield]').type('Mongolia')
cy.get('[id=dec_lat-textfield]').type('49.07')
cy.get('[id=dec_long-textfield]').type('103.67')
cy.get('[id=write-button]').should('not.be.disabled')
cy.get('[id=write-button]').click()
cy.get('[id=write-button]').click()
cy.contains('Edited item successfully.')
cy.contains('Bugat')
cy.contains('8.676')
cy.get('[id=delete-button]').should('exist')
cy.visit('/locality/')
cy.contains('Bugat')
})
})
describe('Editing a locality', () => {
beforeEach('Login as admin', () => {
cy.login('testSu')
})
it('with contradictory min and max ages does not work', () => {
cy.visit(`/locality/20920?tab=0`)
cy.contains('Lantian-Shuijiazui')
cy.get('[id=edit-button]').click()
cy.get('[name=dating-method][value=absolute]').click()
cy.get('[id=min_age-textfield]').first().type('{backspace}{backspace}{backspace}10')
cy.get('[id=max_age-textfield]').type('{backspace}{backspace}{backspace}{backspace}{backspace}9')
cy.contains('Min value cannot be higher than max')
cy.get('[id=write-button]').should('be.disabled')
})
})
describe("Locality's Map works", () => {
beforeEach('Login as admin', () => {
cy.login('testSu')
})
// note that this changes only dec coordinates, dms is still the old one
it('Opening map view in edit works', () => {
cy.visit(`/locality/20920?tab=1`)
cy.contains('Coordinates')
cy.get('[id=edit-button]').click()
cy.contains('Latitude')
cy.contains('Get Coordinates').click()
cy.contains('OpenStreetMap')
cy.contains('Leaflet')
cy.contains('Save').click()
cy.contains('OpenStreetMap').should('not.exist')
cy.contains('Longitude')
cy.contains('Finalize entry').click()
cy.contains('Complete and save').click()
cy.visit(`/locality/20920?tab=1`)
cy.contains('60.202665856')
cy.contains('24.957662836')
cy.contains('60 12 9 N')
cy.contains('24 57 27 E')
})
})