From 35a7148ee0b9ae801b07b92ce1c7ae404ec504e5 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Thu, 26 Oct 2023 16:21:28 -0400 Subject: [PATCH 01/12] fix: try extending timeout for containers --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d962cc4f4..3f7ee55a0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,7 +49,7 @@ jobs: run: ./run-env.sh "$E2E_DATAVERSE_IMAGE_TAG" - name: Wait for containers to be ready - run: timeout 360s sh -c 'while ! docker logs dev_dataverse_bootstrap 2>&1 | grep -q "your instance has been configured"; do sleep 2; done' + run: timeout 720s sh -c 'while ! docker logs dev_dataverse_bootstrap 2>&1 | grep -q "your instance has been configured"; do sleep 2; done' - name: Run e2e tests run: npm run test:e2e From fe1c284c1cb4c91d95430881e307c209f3550813 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 27 Oct 2023 14:22:57 -0400 Subject: [PATCH 02/12] add step to test.yml worfklow to display logs --- .github/workflows/test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3f7ee55a0..bfca4915b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,7 +49,11 @@ jobs: run: ./run-env.sh "$E2E_DATAVERSE_IMAGE_TAG" - name: Wait for containers to be ready - run: timeout 720s sh -c 'while ! docker logs dev_dataverse_bootstrap 2>&1 | grep -q "your instance has been configured"; do sleep 2; done' + run: timeout 360s sh -c 'while ! docker logs dev_dataverse_bootstrap 2>&1 | grep -q "your instance has been configured"; do sleep 2; done' + + - name: Display Docker logs + run: | + docker logs dev_dataverse_bootstrap - name: Run e2e tests run: npm run test:e2e From a5abd9ea376031150e6ff69453775578db35a62e Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 27 Oct 2023 14:47:35 -0400 Subject: [PATCH 03/12] show tail of log while wait for containers to be ready --- .github/workflows/test.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bfca4915b..e8d06489f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,8 +48,14 @@ jobs: working-directory: dev-env run: ./run-env.sh "$E2E_DATAVERSE_IMAGE_TAG" - - name: Wait for containers to be ready - run: timeout 360s sh -c 'while ! docker logs dev_dataverse_bootstrap 2>&1 | grep -q "your instance has been configured"; do sleep 2; done' + - - name: Wait for containers to be ready + run: | + timeout 360s sh -c 'while ! docker logs dev_dataverse_bootstrap 2>&1 | grep -q "your instance has been configured"; do + echo "Checking logs..." + docker logs dev_dataverse_bootstrap | tail -n 10 + echo "Text not found, waiting for 2 seconds..." + sleep 2 + done' - name: Display Docker logs run: | From 4a5caba17dcba357ce4fe2e427464f4799070ae4 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 27 Oct 2023 14:49:57 -0400 Subject: [PATCH 04/12] fix: syntax error in test.yml --- .github/workflows/test.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e8d06489f..a9d7fefb7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,14 +48,14 @@ jobs: working-directory: dev-env run: ./run-env.sh "$E2E_DATAVERSE_IMAGE_TAG" - - - name: Wait for containers to be ready - run: | - timeout 360s sh -c 'while ! docker logs dev_dataverse_bootstrap 2>&1 | grep -q "your instance has been configured"; do - echo "Checking logs..." - docker logs dev_dataverse_bootstrap | tail -n 10 - echo "Text not found, waiting for 2 seconds..." - sleep 2 - done' + - name: Wait for containers to be ready + run: | + timeout 360s sh -c 'while ! docker logs dev_dataverse_bootstrap 2>&1 | grep -q "your instance has been configured"; do + echo "Checking logs..." + docker logs dev_dataverse_bootstrap | tail -n 10 + echo "Text not found, waiting for 2 seconds..." + sleep 2 + done' - name: Display Docker logs run: | From b462fe5dfdb789e3e8fca1134706f57df50c0336 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 27 Oct 2023 15:51:38 -0400 Subject: [PATCH 05/12] use develop dataverse image --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a9d7fefb7..208bfee01 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: test on: push env: - E2E_DATAVERSE_IMAGE_TAG: unstable + E2E_DATAVERSE_IMAGE_TAG: develop jobs: e2e: @@ -52,7 +52,7 @@ jobs: run: | timeout 360s sh -c 'while ! docker logs dev_dataverse_bootstrap 2>&1 | grep -q "your instance has been configured"; do echo "Checking logs..." - docker logs dev_dataverse_bootstrap | tail -n 10 + docker logs dev_dataverse_bootstrap | tail -n 5 echo "Text not found, waiting for 2 seconds..." sleep 2 done' From 7d2bce2aaa6a9c0cb6bfeabf03ca2227aba65373 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 27 Oct 2023 16:27:58 -0400 Subject: [PATCH 06/12] revert dataverse image to unstable --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 208bfee01..6b31f8e88 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: test on: push env: - E2E_DATAVERSE_IMAGE_TAG: develop + E2E_DATAVERSE_IMAGE_TAG: unstable jobs: e2e: From 8681f80ba92178aef99bda1ddcb2be6b71dc8e48 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Wed, 1 Nov 2023 15:45:00 -0400 Subject: [PATCH 07/12] feat: add TestUtils.waitForNoLocks() --- .../DatasetJSDataverseRepository.spec.ts | 4 +- tests/e2e-integration/shared/TestsUtils.ts | 30 ++++++++++ .../shared/datasets/DatasetHelper.ts | 60 ++++++++++++++----- 3 files changed, 76 insertions(+), 18 deletions(-) diff --git a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts index 65f01dbfc..dda9f60c6 100644 --- a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts @@ -113,9 +113,7 @@ describe('Dataset JSDataverse Repository', () => { it('gets the dataset by persistentId and version number', async () => { const datasetResponse = await DatasetHelper.create() await DatasetHelper.publish(datasetResponse.persistentId) - - await TestsUtils.wait(1500) - + await TestsUtils.waitForNoLocks(datasetResponse.persistentId) await datasetRepository .getByPersistentId(datasetResponse.persistentId, '1.0') .then((dataset) => { diff --git a/tests/e2e-integration/shared/TestsUtils.ts b/tests/e2e-integration/shared/TestsUtils.ts index 1ad0c0bdb..fd8f364ee 100644 --- a/tests/e2e-integration/shared/TestsUtils.ts +++ b/tests/e2e-integration/shared/TestsUtils.ts @@ -2,6 +2,7 @@ import { ApiConfig } from '@iqss/dataverse-client-javascript/dist/core' import { DataverseApiHelper } from './DataverseApiHelper' import { DataverseApiAuthMechanism } from '@iqss/dataverse-client-javascript/dist/core/infra/repositories/ApiConfig' import { UserJSDataverseRepository } from '../../../src/users/infrastructure/repositories/UserJSDataverseRepository' +import { DatasetHelper } from './datasets/DatasetHelper' export class TestsUtils { static readonly DATAVERSE_BACKEND_URL = @@ -25,4 +26,33 @@ export class TestsUtils { static logout() { return new UserJSDataverseRepository().removeAuthenticated() } + + static async waitForNoLocks(persistentId: string, maxRetries = 20, delay = 1000): Promise { + await this.checkForLocks(persistentId, maxRetries, delay) + } + + private static async checkForLocks( + persistentId: string, + maxRetries: number, + delay: number + ): Promise { + let retry = 0 + + while (retry < maxRetries) { + const response = await DatasetHelper.getLocks(persistentId) + console.log('Checking locks: ' + JSON.stringify(response)) + + // Check if response has a property "0" + if (Object.keys(response).length === 1) { + console.log('No locks found.') + return + } + + retry++ + await this.wait(delay) + } + + console.log('Max retries reached.') + throw new Error('Max retries reached.') + } } diff --git a/tests/e2e-integration/shared/datasets/DatasetHelper.ts b/tests/e2e-integration/shared/datasets/DatasetHelper.ts index 32143ec12..45b9eb03b 100644 --- a/tests/e2e-integration/shared/datasets/DatasetHelper.ts +++ b/tests/e2e-integration/shared/datasets/DatasetHelper.ts @@ -17,11 +17,24 @@ export class DatasetHelper extends DataverseApiHelper { return this.request(`/dataverses/root/datasets`, 'POST', newDatasetData) } - static async publish(persistentId: string): Promise<{ status: string; persistentId: string }> { - const response = await this.request<{ status: string }>( - `/datasets/:persistentId/actions/:publish?persistentId=${persistentId}&type=major`, - 'POST' - ) + static async publish(persistentId: string): Promise<{ + status: string + persistentId: string + }> { + const response = await this.request<{ + status: string + }>(`/datasets/:persistentId/actions/:publish?persistentId=${persistentId}&type=major`, 'POST') + + return { ...response, persistentId } + } + + static async getLocks(persistentId: string): Promise<{ + status: string + persistentId: string + }> { + const response = await this.request<{ + status: string + }>(`/datasets/:persistentId/locks?persistentId=${persistentId}`, 'GET') return { ...response, persistentId } } @@ -45,15 +58,20 @@ export class DatasetHelper extends DataverseApiHelper { .click() } - static async createPrivateUrl(id: string): Promise<{ token: string }> { - return this.request<{ token: string }>(`/datasets/${id}/privateUrl`, 'POST') + static async createPrivateUrl(id: string): Promise<{ + token: string + }> { + return this.request<{ + token: string + }>(`/datasets/${id}/privateUrl`, 'POST') } - static async createPrivateUrlAnonymized(id: string): Promise<{ token: string }> { - return this.request<{ token: string }>( - `/datasets/${id}/privateUrl?anonymizedAccess=true`, - 'POST' - ) + static async createPrivateUrlAnonymized(id: string): Promise<{ + token: string + }> { + return this.request<{ + token: string + }>(`/datasets/${id}/privateUrl?anonymizedAccess=true`, 'POST') } static async createWithFiles(filesData: FileData[]): Promise { @@ -92,7 +110,15 @@ export class DatasetHelper extends DataverseApiHelper { datasetPersistentId: string, fileData: FileData ): Promise { - const { files } = await this.request<{ files: [{ dataFile: { id: number } }] }>( + const { files } = await this.request<{ + files: [ + { + dataFile: { + id: number + } + } + ] + }>( `/datasets/:persistentId/add?persistentId=${datasetPersistentId}`, 'POST', fileData, @@ -108,8 +134,12 @@ export class DatasetHelper extends DataverseApiHelper { static async setCitationDateFieldType( persistentId: string, fieldType: string - ): Promise<{ status: string }> { - return this.request<{ status: string }>( + ): Promise<{ + status: string + }> { + return this.request<{ + status: string + }>( `/datasets/:persistentId/citationdate?persistentId=${persistentId}`, 'PUT', fieldType, From f32407413ad89e50b937680f90df54007ad988ff Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Wed, 1 Nov 2023 17:02:23 -0400 Subject: [PATCH 08/12] add more calls to waitForLocks() --- .../DatasetJSDataverseRepository.spec.ts | 2 +- .../files/FileJSDataverseRepository.spec.ts | 22 +++++++++---------- tests/e2e-integration/shared/TestsUtils.ts | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts index dda9f60c6..796d88044 100644 --- a/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/datasets/DatasetJSDataverseRepository.spec.ts @@ -175,7 +175,7 @@ describe('Dataset JSDataverse Repository', () => { const datasetResponse = await DatasetHelper.create() await DatasetHelper.publish(datasetResponse.persistentId) - await TestsUtils.wait(1500) + await TestsUtils.waitForNoLocks(datasetResponse.persistentId) await DatasetHelper.setCitationDateFieldType(datasetResponse.persistentId, 'dateOfDeposit') diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index 1dd07b335..8e5938028 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -129,7 +129,7 @@ describe('File JSDataverse Repository', () => { if (!dataset) throw new Error('Dataset not found') await DatasetHelper.publish(dataset.persistentId) - await TestsUtils.wait(1500) // Wait for the dataset to be published + await TestsUtils.waitForNoLocks(dataset.persistentId) // Wait for the dataset to be published await fileRepository .getAllByDatasetPersistentId( @@ -163,7 +163,7 @@ describe('File JSDataverse Repository', () => { if (!dataset) throw new Error('Dataset not found') await DatasetHelper.publish(dataset.persistentId) - await TestsUtils.wait(1500) // Wait for the dataset to be published + await TestsUtils.waitForNoLocks(dataset.persistentId) // Wait for the dataset to be published DatasetHelper.deaccession(dataset.persistentId) await TestsUtils.wait(1500) // Wait for the dataset to be deaccessioned @@ -199,7 +199,7 @@ describe('File JSDataverse Repository', () => { if (!datasetResponse.files) throw new Error('Files not found') await DatasetHelper.publish(datasetResponse.persistentId) - await TestsUtils.wait(1500) // Wait for the dataset to be published + await TestsUtils.waitForNoLocks(datasetResponse.persistentId) // Wait for the dataset to be published const dataset = await datasetRepository.getByPersistentId(datasetResponse.persistentId) if (!dataset) throw new Error('Dataset not found') @@ -238,8 +238,7 @@ describe('File JSDataverse Repository', () => { it('gets all the files by dataset persistentId after adding tag labels to the files', async () => { const datasetResponse = await DatasetHelper.createWithFiles(FileHelper.createMany(1, 'csv')) if (!datasetResponse.files) throw new Error('Files not found') - await TestsUtils.wait(1500) // Wait for the tabular data to be ingested - + await TestsUtils.waitForNoLocks(datasetResponse.persistentId) // Wait for the tabular data to be ingested const dataset = await datasetRepository.getByPersistentId(datasetResponse.persistentId) if (!dataset) throw new Error('Dataset not found') @@ -270,7 +269,7 @@ describe('File JSDataverse Repository', () => { [datasetResponse.files[0].id, datasetResponse.files[1].id, datasetResponse.files[2].id], embargoDate ) - await TestsUtils.wait(1500) // Wait for the files to be embargoed + await TestsUtils.waitForNoLocks(datasetResponse.persistentId) // Wait for the files to be embargoed await fileRepository .getAllByDatasetPersistentId(dataset.persistentId, dataset.version) @@ -490,11 +489,11 @@ describe('File JSDataverse Repository', () => { total: 6, perAccess: [ { - access: FileAccessOption.RESTRICTED, + access: FileAccessOption.PUBLIC, count: 3 }, { - access: FileAccessOption.PUBLIC, + access: FileAccessOption.RESTRICTED, count: 3 } ], @@ -519,12 +518,13 @@ describe('File JSDataverse Repository', () => { } ] } - + let filesCountInfo: FilesCountInfo | undefined = undefined await fileRepository .getFilesCountInfoByDatasetPersistentId(dataset.persistentId, dataset.version) - .then((filesCountInfo) => { - expect(filesCountInfo).to.deep.equal(expectedFilesCountInfo) + .then((filesCountInfoResp) => { + filesCountInfo = filesCountInfoResp }) + expect(filesCountInfo).to.deep.equal(expectedFilesCountInfo) }) }) }) diff --git a/tests/e2e-integration/shared/TestsUtils.ts b/tests/e2e-integration/shared/TestsUtils.ts index fd8f364ee..f6508dcfd 100644 --- a/tests/e2e-integration/shared/TestsUtils.ts +++ b/tests/e2e-integration/shared/TestsUtils.ts @@ -42,7 +42,7 @@ export class TestsUtils { const response = await DatasetHelper.getLocks(persistentId) console.log('Checking locks: ' + JSON.stringify(response)) - // Check if response has a property "0" + // The response will have a single key if there are no locks if (Object.keys(response).length === 1) { console.log('No locks found.') return From 4bf1c82830be60942ef23c4cf03226ad4244f8e4 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Thu, 2 Nov 2023 21:40:44 -0400 Subject: [PATCH 09/12] fix: merge commit --- src/files/infrastructure/mappers/DomainFileMapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/files/infrastructure/mappers/DomainFileMapper.ts b/src/files/infrastructure/mappers/DomainFileMapper.ts index ae0a673e6..71082838d 100644 --- a/src/files/infrastructure/mappers/DomainFileMapper.ts +++ b/src/files/infrastructure/mappers/DomainFileMapper.ts @@ -7,7 +7,7 @@ import { } from '../../domain/models/FileCriteria' import { FileAccessStatus as JSFileAccessStatus, - FileCriteria as JSFileSearchCriteria, + FileSearchCriteria as JSFileSearchCriteria, FileOrderCriteria as JSFileOrderCriteria } from '@iqss/dataverse-client-javascript' import { FileType } from '../../domain/models/File' From d2bc0f8e823067118a4011bfcf67285fe61e4e6e Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Fri, 3 Nov 2023 13:47:38 -0400 Subject: [PATCH 10/12] fix: timezone and timing issue in e2e test --- package-lock.json | 20 +++++++++++++++++++ package.json | 1 + .../e2e/sections/dataset/Dataset.spec.tsx | 17 +++++++++++++--- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9cab908e7..ae9b44949 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,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", @@ -31965,6 +31966,25 @@ "integrity": "sha512-23g5BFj4zdQL/b6tor7Ji+QY4pEfNH784BMslY9Qb0UnJWRAt+lQGLYmRaM0KDBwIG23ffEBELhZDP2rhi9f/Q==", "dev": true }, + "node_modules/moment": { + "version": "2.29.4", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", + "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", + "engines": { + "node": "*" + } + }, + "node_modules/moment-timezone": { + "version": "0.5.43", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.43.tgz", + "integrity": "sha512-72j3aNyuIsDxdF1i7CEgV2FfxM1r6aaqJyLB2vwb33mXYyoyLly+F1zbWqhA3/bVIoJ4szlUoMbUnVdid32NUQ==", + "dependencies": { + "moment": "^2.29.4" + }, + "engines": { + "node": "*" + } + }, "node_modules/mri": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", diff --git a/package.json b/package.json index 0c61160a5..6c826d6b0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx index ef743d439..a0ec9c0f0 100644 --- a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx +++ b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx @@ -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 }[] } } } @@ -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 ) ) ) @@ -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') From 2ade85125a7a9c32949c4edfaa1dbe9bb9605511 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Mon, 6 Nov 2023 16:41:45 -0500 Subject: [PATCH 11/12] fix: use browser locale for expected date --- .../e2e/sections/dataset/Dataset.spec.tsx | 65 ++++++++++++------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx index a0ec9c0f0..4d963130f 100644 --- a/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx +++ b/tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx @@ -275,40 +275,55 @@ describe('Dataset', () => { }) 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') + 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() + ) - // 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], - dateString + cy.wrap( + DatasetHelper.createWithFiles(FileHelper.createMany(1)).then((dataset) => + DatasetHelper.embargoFiles( + dataset.persistentId, + [dataset.files ? dataset.files[0].id : 0], + dateString + ) ) ) - ) - .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}`) + cy.visit(`/spa/datasets?persistentId=${persistentId}`) - 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 ${expectedDate}`).should('exist') - cy.findByText('Edit Files').should('exist') + cy.findByText('Edit Files').should('exist') - cy.findByRole('button', { name: 'Access File' }).should('exist').click() - cy.findByText('Embargoed').should('exist') - }) + cy.findByRole('button', { name: 'Access File' }).should('exist').click() + cy.findByText('Embargoed').should('exist') + }) + }) }) it('applies filters to the Files Table in the correct order', () => { From 65a883ee025f8c1901f6e91c7070039b48abc997 Mon Sep 17 00:00:00 2001 From: Ellen Kraffmiller Date: Mon, 6 Nov 2023 16:54:23 -0500 Subject: [PATCH 12/12] fix: add waitForNoLocks() for file ingest --- .../integration/files/FileJSDataverseRepository.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts index a305136d2..09c7de97c 100644 --- a/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts +++ b/tests/e2e-integration/integration/files/FileJSDataverseRepository.spec.ts @@ -672,7 +672,7 @@ describe('File JSDataverse Repository', () => { ) if (!dataset) throw new Error('Dataset not found') - await TestsUtils.wait(2500) // wait for the files to be ingested + await TestsUtils.waitForNoLocks(dataset.persistentId) // wait for the files to be ingested const expectedTotalDownloadSize = await fileRepository .getAllByDatasetPersistentId(dataset.persistentId, dataset.version) @@ -710,7 +710,7 @@ describe('File JSDataverse Repository', () => { ) if (!dataset) throw new Error('Dataset not found') - await TestsUtils.wait(2500) // wait for the files to be ingested + await TestsUtils.waitForNoLocks(dataset.persistentId) // wait for the files to be ingested const expectedTotalDownloadSize = await fileRepository .getAllByDatasetPersistentId(