Skip to content

Commit

Permalink
fix: timezone and timing issue in e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
ekraffmiller committed Nov 3, 2023
1 parent b6b33ed commit d2bc0f8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"i18next": "22.4.9",
"i18next-browser-languagedetector": "7.0.1",
"i18next-http-backend": "2.1.1",
"moment-timezone": "^0.5.43",
"react-bootstrap": "2.7.2",
"react-bootstrap-icons": "1.10.3",
"react-i18next": "12.1.5",
Expand Down
17 changes: 14 additions & 3 deletions tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DatasetLabelValue } from '../../../../../src/dataset/domain/models/Data
import { TestsUtils } from '../../../shared/TestsUtils'
import { DatasetHelper } from '../../../shared/datasets/DatasetHelper'
import { FileHelper } from '../../../shared/files/FileHelper'
import moment from 'moment-timezone'

type Dataset = {
datasetVersion: { metadataBlocks: { citation: { fields: { value: string }[] } } }
Expand Down Expand Up @@ -265,18 +266,28 @@ describe('Dataset', () => {
cy.findByText('Restricted with access Icon').should('not.exist')
cy.findByText('Restricted File Icon').should('exist')

cy.findByRole('button', { name: 'Access File' }).should('exist').click()
// use alias below to avoid a timing error
cy.findByRole('button', { name: 'Access File' }).as('accessButton')
cy.get('@accessButton').should('exist')
cy.get('@accessButton').click()
cy.findByText('Restricted').should('exist')
})
})

it('loads the embargoed files', () => {
// Create a moment object in UTC and set the time to 12 AM (midnight)
const utcDate = moment.utc().startOf('day')

// Add 100 years to the UTC date
utcDate.add(100, 'years')
const dateString = utcDate.format('YYYY-MM-DD')
const expectedDate = utcDate.local().format('MMM D, YYYY')
cy.wrap(
DatasetHelper.createWithFiles(FileHelper.createMany(1)).then((dataset) =>
DatasetHelper.embargoFiles(
dataset.persistentId,
[dataset.files ? dataset.files[0].id : 0],
'2100-10-20'
dateString
)
)
)
Expand All @@ -291,7 +302,7 @@ describe('Dataset', () => {
cy.findByText('Files').should('exist')

cy.findByText(/Deposited/).should('exist')
cy.findByText('Draft: will be embargoed until Oct 20, 2100').should('exist')
cy.findByText(`Draft: will be embargoed until ${expectedDate}`).should('exist')

cy.findByText('Edit Files').should('exist')

Expand Down

0 comments on commit d2bc0f8

Please sign in to comment.