From 7e3acab22b962bddebc7766c3143ffcc595838de Mon Sep 17 00:00:00 2001 From: MellyGray Date: Mon, 11 Dec 2023 12:43:50 +0100 Subject: [PATCH] fix: unit tests mocks --- .../access-file-menu/AccessFileMenu.stories.tsx | 2 +- .../file-info/file-info-cell/FileInfoCell.stories.tsx | 2 +- tests/component/files/domain/models/FileMother.ts | 10 +++++++++- .../access-file-menu/AccessFileMenu.spec.tsx | 9 ++++----- .../access-file-menu/FileDownloadOptions.spec.tsx | 8 ++------ .../FileNonTabularDownloadOptions.spec.tsx | 2 +- .../FileTabularDownloadOptions.spec.tsx | 8 ++++---- .../file-info-cell/file-info-data/FileType.spec.tsx | 2 +- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/access-file-menu/AccessFileMenu.stories.tsx b/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/access-file-menu/AccessFileMenu.stories.tsx index a3a80a32d..b016c7722 100644 --- a/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/access-file-menu/AccessFileMenu.stories.tsx +++ b/src/stories/dataset/dataset-files/files-table/file-actions/file-action-buttons/access-file-menu/AccessFileMenu.stories.tsx @@ -25,7 +25,7 @@ export const NonTabularFiles: Story = { } export const TabularFiles: Story = { - render: () => + render: () => } export const Restricted: Story = { diff --git a/src/stories/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.stories.tsx b/src/stories/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.stories.tsx index 6f4d8c401..7cd2f550d 100644 --- a/src/stories/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.stories.tsx +++ b/src/stories/dataset/dataset-files/files-table/file-info/file-info-cell/FileInfoCell.stories.tsx @@ -29,7 +29,7 @@ export const WithEmbargo: Story = { } export const WithTabularData: Story = { - render: () => + render: () => } export const WithDescription: Story = { diff --git a/tests/component/files/domain/models/FileMother.ts b/tests/component/files/domain/models/FileMother.ts index c06948a17..880cbb459 100644 --- a/tests/component/files/domain/models/FileMother.ts +++ b/tests/component/files/domain/models/FileMother.ts @@ -225,7 +225,7 @@ export class FileMother { }) } - static createWithTabularData(props?: Partial): File { + static createTabular(props?: Partial): File { return this.createDefault({ type: new FileType('text/tab-separated-values', 'Comma Separated Values'), tabularData: { @@ -237,6 +237,14 @@ export class FileMother { }) } + static createNonTabular(props?: Partial): File { + return this.createDefault({ + type: new FileType('text/plain'), + tabularData: undefined, + ...props + }) + } + static createWithDescription(): File { return this.createDefault({ description: faker.lorem.paragraph() diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu.spec.tsx index 39887fd78..460cfab8d 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/AccessFileMenu.spec.tsx @@ -65,12 +65,11 @@ describe('AccessFileMenu', () => { }) it('renders the download options header', () => { + const filePublic = FileMother.createWithPublicAccess() cy.customMount( - - - - - + + + ) cy.findByRole('button', { name: 'Access File' }).click() diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions.spec.tsx index f4c6c9b44..912c63a18 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions.spec.tsx @@ -1,15 +1,11 @@ import { FileDownloadOptions } from '../../../../../../../../../../src/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileDownloadOptions' import { FileMother } from '../../../../../../../../files/domain/models/FileMother' -import { FileType } from '../../../../../../../../../../src/files/domain/models/File' import { FileUserPermissionsMother } from '../../../../../../../../files/domain/models/FileUserPermissionsMother' import { FilePermissionsProvider } from '../../../../../../../../../../src/sections/file/file-permissions/FilePermissionsProvider' import { FileRepository } from '../../../../../../../../../../src/files/domain/repositories/FileRepository' -const fileNonTabular = FileMother.create({ - tabularData: undefined, - type: new FileType('text/plain') -}) -const fileTabular = FileMother.createWithTabularData() +const fileNonTabular = FileMother.createNonTabular() +const fileTabular = FileMother.createTabular() const fileRepository = {} as FileRepository describe('FileDownloadOptions', () => { beforeEach(() => { diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileNonTabularDownloadOptions.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileNonTabularDownloadOptions.spec.tsx index d2207f468..2d9cf8c17 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileNonTabularDownloadOptions.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileNonTabularDownloadOptions.spec.tsx @@ -39,7 +39,7 @@ describe('FileNonTabularDownloadOptions', () => { }) it('does not render the download options for a tabular file', () => { - const fileTabular = FileMother.createWithTabularData() + const fileTabular = FileMother.createTabular() cy.customMount() cy.findByRole('link', { name: 'Original File Format' }).should('not.exist') diff --git a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileTabularDownloadOptions.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileTabularDownloadOptions.spec.tsx index e89603eca..8dad61fb6 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileTabularDownloadOptions.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/file-actions/file-actions-cell/file-action-buttons/access-file-menu/FileTabularDownloadOptions.spec.tsx @@ -15,8 +15,8 @@ const fileNonTabular = FileMother.create({ tabularData: undefined, type: new FileType('text/plain') }) -const fileTabular = FileMother.createWithTabularData() -const fileTabularUnknown = FileMother.createWithTabularData({ +const fileTabular = FileMother.createTabular() +const fileTabularUnknown = FileMother.createTabular({ type: new FileType('text/tab-separated-values', 'Unknown') }) describe('FileTabularDownloadOptions', () => { @@ -55,7 +55,7 @@ describe('FileTabularDownloadOptions', () => { }) it('renders the options as disabled when the file ingest is in progress', () => { - const fileTabularInProgress = FileMother.createWithTabularData({ + const fileTabularInProgress = FileMother.createTabular({ ingest: { status: FileIngestStatus.IN_PROGRESS } @@ -96,7 +96,7 @@ describe('FileTabularDownloadOptions', () => { }) it('does not render the RData option if the file type is already R Data', () => { - const fileTabularRData = FileMother.createWithTabularData({ + const fileTabularRData = FileMother.createTabular({ type: new FileType('text/tab-separated-values', 'R Data') }) cy.customMount() diff --git a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileType.spec.tsx b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileType.spec.tsx index db176f339..e68ae02c7 100644 --- a/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileType.spec.tsx +++ b/tests/component/sections/dataset/dataset-files/files-table/files-info/file-info-cell/file-info-data/FileType.spec.tsx @@ -28,7 +28,7 @@ describe('FileType', () => { }) it('renders the type correctly when is a tabular file', () => { - const file = FileMother.createWithTabularData({ + const file = FileMother.createTabular({ size: new FileSize(123.03932894722, FileSizeUnit.BYTES) })