Skip to content

Commit

Permalink
test: change the testcases to match new changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengShi-1 committed Nov 2, 2024
1 parent fc49589 commit adfe478
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ export function FileDate({ date }: { date: FileDateModel }) {
return (
<div>
<span>
<time>
{t(`table.date.${date.type}`)}
{DateHelper.toDisplayFormat(date.date)}
</time>
{t(`table.date.${date.type}`)} <time>{DateHelper.toDisplayFormat(date.date)}</time>
</span>
</div>
)
Expand Down
6 changes: 2 additions & 4 deletions src/sections/file/file-embargo/FileEmbargoDate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@ interface FileEmbargoDateProps {
export function FileEmbargoDate({
embargo,
datasetPublishingStatus,
format = 'short'
format = 'YYYY-MM-DD'
}: FileEmbargoDateProps) {
const { t } = useTranslation('files')

if (!embargo) {
return <></>
}

// TODO: use time tag with dateTime attr https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time

return (
<div>
<span>
{t(embargoTypeOfDate(embargo.isActive, datasetPublishingStatus))}{' '}
<time>
<time data-testid="embargo-date">
{format === 'YYYY-MM-DD'
? DateHelper.toISO8601Format(embargo.dateAvailable)
: DateHelper.toDisplayFormat(embargo.dateAvailable)}
Expand Down
23 changes: 10 additions & 13 deletions tests/component/sections/file/file-embargo/FileEmbargoDate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ describe('FileEmbargoDate', () => {
day: 'numeric'
}
)
cy.findByText(`Embargoed until ` + dateString).should('exist')
cy.findByText(`Embargoed until`).should('exist')
cy.get('time').should('have.text', dateString)
})

it('renders the until embargo date when embargo is not active and the file is not released', () => {
Expand All @@ -33,7 +34,8 @@ describe('FileEmbargoDate', () => {
day: 'numeric'
}
)
cy.findByText(`Was embargoed until ` + dateString).should('exist')
cy.findByText(`Was embargoed until`).should('exist')
cy.get('time').should('have.text', dateString)
})

it('renders the draft until embargo date when embargo is active and the file is not released', () => {
Expand All @@ -50,15 +52,15 @@ describe('FileEmbargoDate', () => {
day: 'numeric'
}
)
cy.findByText(`Draft: will be embargoed until ` + dateString).should('exist')
cy.findByText(`Draft: will be embargoed until`).should('exist')
cy.get('time').should('have.text', dateString)
})

it('renders an empty fragment when embargo is undefined', () => {
const embargo = undefined
const status = DatasetPublishingStatus.RELEASED

cy.customMount(<FileEmbargoDate embargo={embargo} datasetPublishingStatus={status} />)

cy.findByText(/Draft: will be embargoed until/).should('not.exist')
cy.findByText(/Embargoed until/).should('not.exist')
cy.findByText(/Was embargoed until/).should('not.exist')
Expand All @@ -68,17 +70,12 @@ describe('FileEmbargoDate', () => {
const embargoDate = new Date('2123-09-18')
const embargo = FileEmbargoMother.create({ dateAvailable: embargoDate })
const status = DatasetPublishingStatus.RELEASED

cy.customMount(
<FileEmbargoDate embargo={embargo} datasetPublishingStatus={status} format="YYYY-MM-DD" />
)
const dateString = embargoDate.toLocaleDateString(
Intl.DateTimeFormat().resolvedOptions().locale,
{
year: 'numeric',
month: '2-digit',
day: '2-digit'
}
)
cy.findByText(`Embargoed until ` + dateString).should('exist')
const dateString = embargoDate.toISOString().split('T')[0]
cy.findByText(`Embargoed until`).should('exist')
cy.get('time').should('have.text', dateString)
})
})
28 changes: 16 additions & 12 deletions tests/component/sections/file/file-metadata/FileMetadata.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe('FileMetadata', () => {
)

cy.findByText('Deposit Date').should('exist')
cy.findByText(DateHelper.toDisplayFormatYYYYMMDD(file.metadata.depositDate)).should('exist')
cy.findByText(DateHelper.toISO8601Format(file.metadata.depositDate)).should('exist')
})

it('renders the file Metadata Release Date', () => {
Expand All @@ -231,9 +231,11 @@ describe('FileMetadata', () => {
)

cy.findByText('Metadata Release Date').should('exist')
cy.findAllByText(
DateHelper.toDisplayFormatYYYYMMDD(metadataWithPublicationDate.publicationDate)
).should('exist')
if (metadataWithPublicationDate.publicationDate) {
cy.findAllByText(
DateHelper.toISO8601Format(metadataWithPublicationDate.publicationDate)
).should('exist')
}
})

it('does not render the file Metadata Release Date if the publication date does not exist', () => {
Expand Down Expand Up @@ -262,9 +264,11 @@ describe('FileMetadata', () => {
)

cy.findByText('Publication Date').should('exist')
cy.findAllByText(
DateHelper.toDisplayFormatYYYYMMDD(metadataWithPublicationDate.publicationDate)
).should('exist')
if (metadataWithPublicationDate.publicationDate) {
cy.findAllByText(
DateHelper.toISO8601Format(metadataWithPublicationDate.publicationDate)
).should('exist')
}
})

it('renders the file Publication Date with embargo', () => {
Expand All @@ -280,11 +284,11 @@ describe('FileMetadata', () => {
)

cy.findByText('Publication Date').should('exist')
cy.findByText(
`Embargoed until ${DateHelper.toDisplayFormatYYYYMMDD(
metadataWithPublicationDateEmbargoed.embargo?.dateAvailable
)}`
).should('exist')
if (metadataWithPublicationDateEmbargoed.publicationDate) {
cy.findAllByText(
DateHelper.toISO8601Format(metadataWithPublicationDateEmbargoed.publicationDate)
).should('exist')
}
})

it('does not render the file Publication Date if the publication date and embargo do not exist', () => {
Expand Down
66 changes: 24 additions & 42 deletions tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,57 +478,39 @@ describe('Dataset', () => {
})

it('loads the embargoed files', () => {
cy.window().then((win) => {
// Get the browser's locale from the window object
const browserLocale = win.navigator.language

// 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')

// Use the browser's locale to format the date using Intl.DateTimeFormat
const options: Intl.DateTimeFormatOptions = {
year: 'numeric',
month: 'short',
day: 'numeric'
}
const expectedDate = new Intl.DateTimeFormat(browserLocale, options).format(
utcDate.toDate()
)
const utcDate = moment.utc().startOf('day').add(100, 'years')
const expectedDate = utcDate.toISOString().split('T')[0]

cy.wrap(
DatasetHelper.createWithFiles(FileHelper.createMany(1)).then((dataset) =>
DatasetHelper.embargoFiles(
dataset.persistentId,
[dataset.files ? dataset.files[0].id : 0],
dateString
)
cy.wrap(
DatasetHelper.createWithFiles(FileHelper.createMany(1)).then((dataset) =>
DatasetHelper.embargoFiles(
dataset.persistentId,
[dataset.files ? dataset.files[0].id : 0],
expectedDate
)
)
.its('persistentId')
.then((persistentId: string) => {
cy.wait(1500) // Wait for the files to be embargoed
)
.its('persistentId')
.then((persistentId: string) => {
cy.wait(1500) // Wait for the files to be embargoed

cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)
cy.visit(`/spa/datasets?persistentId=${persistentId}&version=${DRAFT_PARAM}`)

cy.wait(1500) // Wait for the files to be loaded
cy.wait(1500) // Wait for the files to be loaded

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

cy.findByText(/Deposited/).should('exist')
cy.findByText(`Draft: will be embargoed until ${expectedDate}`).should('exist')
cy.findByText(/Deposited/).should('exist')
cy.findByText(`Draft: will be embargoed until`).should('exist')
cy.findByTestId('embargo-date').should('have.text', expectedDate)

cy.get('#edit-files-menu').should('exist')
cy.get('#edit-files-menu').should('exist')

cy.findByRole('button', { name: 'Access File' }).as('accessButton')
cy.get('@accessButton').should('exist')
cy.get('@accessButton').click()
cy.findByText('Embargoed').should('exist')
})
})
cy.findByRole('button', { name: 'Access File' }).as('accessButton')
cy.get('@accessButton').should('exist')
cy.get('@accessButton').click()
cy.findByText('Embargoed').should('exist')
})
})

it('applies filters to the Files Table in the correct order', () => {
Expand Down

0 comments on commit adfe478

Please sign in to comment.