Skip to content

Commit

Permalink
fix: unit tests mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Dec 11, 2023
1 parent 2758d01 commit 6610d27
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const NonTabularFiles: Story = {
}

export const TabularFiles: Story = {
render: () => <AccessFileMenu file={FileMother.createWithTabularData()} />
render: () => <AccessFileMenu file={FileMother.createTabular()} />
}

export const Restricted: Story = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const WithEmbargo: Story = {
}

export const WithTabularData: Story = {
render: () => <FileInfoCell file={FileMother.createWithTabularData()} />
render: () => <FileInfoCell file={FileMother.createTabular()} />
}

export const WithDescription: Story = {
Expand Down
10 changes: 9 additions & 1 deletion tests/component/files/domain/models/FileMother.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class FileMother {
})
}

static createWithTabularData(props?: Partial<File>): File {
static createTabular(props?: Partial<File>): File {
return this.createDefault({
type: new FileType('text/tab-separated-values', 'Comma Separated Values'),
tabularData: {
Expand All @@ -237,6 +237,14 @@ export class FileMother {
})
}

static createNonTabular(props?: Partial<File>): File {
return this.createDefault({
type: new FileType('text/plain'),
tabularData: undefined,
...props
})
}

static createWithDescription(): File {
return this.createDefault({
description: faker.lorem.paragraph()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ describe('AccessFileMenu', () => {
})

it('renders the download options header', () => {
const filePublic = FileMother.createWithPublicAccess()
cy.customMount(
<Suspense fallback="loading">
<FilePermissionsProvider repository={fileRepository}>
<AccessFileMenu file={file} />
</FilePermissionsProvider>
</Suspense>
<FilePermissionsProvider repository={fileRepository}>
<AccessFileMenu file={filePublic} />
</FilePermissionsProvider>
)

cy.findByRole('button', { name: 'Access File' }).click()
Expand Down
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(<FileNonTabularDownloadOptions file={fileTabular} />)

cy.findByRole('link', { name: 'Original File Format' }).should('not.exist')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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(<FileTabularDownloadOptions file={fileTabularRData} />)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down

0 comments on commit 6610d27

Please sign in to comment.