Skip to content

Commit

Permalink
feat(FilesFilterIntegration): add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Sep 4, 2023
1 parent dd90602 commit ec98c1f
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 46 deletions.
108 changes: 106 additions & 2 deletions tests/e2e-integration/e2e/sections/dataset/Dataset.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('Dataset', () => {
})

it('loads the restricted files when the user is logged in as owner', () => {
cy.wrap(DatasetHelper.createWithFilesRestricted(FileHelper.createMany(1)))
cy.wrap(DatasetHelper.createWithFiles(FileHelper.createManyRestricted(1)))
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)
Expand All @@ -238,7 +238,7 @@ describe('Dataset', () => {

it('loads the restricted files when the user is not logged in as owner', () => {
cy.wrap(
DatasetHelper.createWithFilesRestricted(FileHelper.createMany(1)).then((dataset) =>
DatasetHelper.createWithFiles(FileHelper.createManyRestricted(1)).then((dataset) =>
DatasetHelper.publish(dataset.persistentId)
)
)
Expand Down Expand Up @@ -272,6 +272,8 @@ describe('Dataset', () => {
)
.its('persistentId')
.then((persistentId: string) => {
cy.wait(1500) // Wait for the files to be embargoed

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

cy.findByText('Files').should('exist')
Expand All @@ -283,5 +285,107 @@ describe('Dataset', () => {
cy.findByText('Embargoed').should('exist')
})
})

it.skip('applies filters to the Files Table in the correct order', () => {
// TODO - Integrate fileCountInfo
const files = [
FileHelper.create('csv', {
description: 'Some description',
categories: ['category'],
restrict: 'true',
tabIngest: 'false'
}),
FileHelper.create('csv', {
description: 'Some description',
restrict: 'true',
tabIngest: 'false'
}),
FileHelper.create('csv', {
description: 'Some description',
categories: ['category'],
tabIngest: 'false'
}),
FileHelper.create('txt', {
description: 'Some description',
categories: ['category'],
restrict: 'true'
}),
FileHelper.create('csv', {
description: 'Some description',
categories: ['category'],
restrict: 'true',
tabIngest: 'false'
}),
FileHelper.create('csv', {
description: 'Some description',
categories: ['category'],
restrict: 'true',
tabIngest: 'false'
})
]
cy.wrap(DatasetHelper.createWithFiles(files))
.its('persistentId')
.then((persistentId: string) => {
cy.visit(`/spa/datasets?persistentId=${persistentId}`)

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

cy.findByText('blob').should('exist')
cy.findByText('blob-1').should('exist')
cy.findByText('blob-2').should('exist')
cy.findByText('blob-3').should('exist')
cy.findByText('blob-4').should('exist')
cy.findByText('blob-5').should('exist')

cy.findByLabelText('Search').type('blob-{enter}', { force: true })

cy.findByText('blob').should('not.exist')
cy.findByText('blob-1').should('exist')
cy.findByText('blob-2').should('exist')
cy.findByText('blob-3').should('exist')
cy.findByText('blob-4').should('exist')
cy.findByText('blob-5').should('exist')

cy.findByRole('button', { name: 'Filter Tag: All' }).click({ force: true })
cy.findByText('category').should('exist').click({ force: true })

cy.findByText('blob').should('not.exist')
cy.findByText('blob-1').should('not.exist')
cy.findByText('blob-2').should('exist')
cy.findByText('blob-3').should('exist')
cy.findByText('blob-4').should('exist')
cy.findByText('blob-5').should('exist')

cy.findByRole('button', { name: 'Access: All' }).click()
cy.findByText('Restricted').should('exist').click()

cy.findByText('blob').should('not.exist')
cy.findByText('blob-1').should('not.exist')
cy.findByText('blob-2').should('not.exist')
cy.findByText('blob-3').should('exist')
cy.findByText('blob-4').should('exist')
cy.findByText('blob-5').should('exist')

cy.findByRole('button', { name: 'Filter Type: All' }).click()
cy.findByText('text/csv').should('exist').click()

cy.findByText('blob').should('not.exist')
cy.findByText('blob-1').should('not.exist')
cy.findByText('blob-2').should('not.exist')
cy.findByText('blob-3').should('not.exist')
cy.findByText('blob-4').should('exist')
cy.findByText('blob-5').should('exist')

cy.findByRole('button', { name: /Sort/ }).click()
cy.findByText('Name (Z-A)').should('exist').click()

cy.findByText('blob').should('not.exist')
cy.findByText('blob-1').should('not.exist')
cy.findByText('blob-2').should('not.exist')
cy.findByText('blob-3').should('not.exist')
cy.get('table > tbody > tr').eq(0).should('contain', 'blob-5')
cy.get('table > tbody > tr').eq(1).should('contain', 'blob-4')
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
FileSortByOption
} from '../../../../src/files/domain/models/FileCriteria'
import { DatasetHelper } from '../../shared/datasets/DatasetHelper'
import { FileHelper } from '../../shared/files/FileHelper'
import { FileData, FileHelper } from '../../shared/files/FileHelper'

chai.use(chaiAsPromised)
const expect = chai.expect
Expand Down Expand Up @@ -101,9 +101,11 @@ describe('File JSDataverse Repository', () => {

it('gets all the files by dataset persistentId with the correct size', async () => {
const expectedSize = new FileSize(25, FileSizeUnit.BYTES)
const dataset = await DatasetHelper.createWithFiles([
new Blob([new ArrayBuffer(expectedSize.value)], { type: 'text/csv' })
]).then((datasetResponse) =>
const fileData: FileData = {
file: new Blob([new ArrayBuffer(expectedSize.value)], { type: 'text/csv' }),
jsonData: JSON.stringify({ description: 'This is an example file' })
}
const dataset = await DatasetHelper.createWithFiles([fileData]).then((datasetResponse) =>
datasetRepository.getByPersistentId(datasetResponse.persistentId)
)
if (!dataset) throw new Error('Dataset not found')
Expand Down Expand Up @@ -385,7 +387,7 @@ describe('File JSDataverse Repository', () => {
})
})

it.only('gets all the files by dataset persistentId when passing searchText criteria', async () => {
it('gets all the files by dataset persistentId when passing searchText criteria', async () => {
const dataset = await DatasetHelper.createWithFiles(FileHelper.createMany(3)).then(
(datasetResponse) => datasetRepository.getByPersistentId(datasetResponse.persistentId)
)
Expand Down
42 changes: 8 additions & 34 deletions tests/e2e-integration/shared/datasets/DatasetHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import newDatasetData from '../../fixtures/dataset-finch1.json'
import { DataverseApiHelper } from '../DataverseApiHelper'
import { forEach } from 'react-bootstrap/ElementChildren'
import { FileData } from '../files/FileHelper'

export interface DatasetResponse {
persistentId: string
Expand Down Expand Up @@ -56,32 +56,12 @@ export class DatasetHelper extends DataverseApiHelper {
)
}

static async createWithFiles(
filesBinary: Blob[],
filesMetadata?: { [key: string]: string }
): Promise<DatasetResponse> {
static async createWithFiles(filesData: FileData[]): Promise<DatasetResponse> {
const datasetResponse = await this.create()
const files = await this.uploadFiles(datasetResponse.persistentId, filesBinary, filesMetadata)
const files = await this.uploadFiles(datasetResponse.persistentId, filesData)
return { ...datasetResponse, files: files }
}

static async createWithFilesRestricted(filesBinary: Blob[]): Promise<DatasetResponse> {
const datasetResponse = await this.createWithFiles(filesBinary, {
description: 'This is an example file',
restrict: 'true'
})
return datasetResponse
}

static async createWithFilesEmbargoed(filesBinary: Blob[]): Promise<DatasetResponse> {
const datasetResponse = await this.createWithFiles(filesBinary, {
description: 'This is an example file',
restrict: 'true',
embargoDate: '2021-01-01'
})
return datasetResponse
}

static async embargoFiles(
persistentId: string,
filesIds: number[],
Expand All @@ -97,31 +77,25 @@ export class DatasetHelper extends DataverseApiHelper {

private static async uploadFiles(
datasetPersistentId: string,
filesBinary: Blob[],
filesMetadata: { [key: string]: string } = { description: 'This is an example file' }
filesData: FileData[]
): Promise<DatasetFileResponse[]> {
// TODO - Instead of uploading the files one by one, upload them all at once - do this refactor when integrating the pagination
const files = []
for (const fileBinary of filesBinary) {
const file = await this.uploadFile(datasetPersistentId, fileBinary, filesMetadata)
for (const fileData of filesData) {
const file = await this.uploadFile(datasetPersistentId, fileData)
files.push(file)
}
return files
}

private static async uploadFile(
datasetPersistentId: string,
fileBinary: Blob,
filesMetadata: { [key: string]: string } = { description: 'This is an example file' }
fileData: FileData
): Promise<DatasetFileResponse> {
const data = {
file: fileBinary,
jsonData: JSON.stringify(filesMetadata)
}
const { files } = await this.request<{ files: [{ dataFile: { id: number } }] }>(
`/datasets/:persistentId/add?persistentId=${datasetPersistentId}`,
'POST',
data,
fileData,
true
)

Expand Down
47 changes: 42 additions & 5 deletions tests/e2e-integration/shared/files/FileHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,57 @@ interface FileResponse {
id: number
}

export interface FileData {
file: Blob
jsonData: string
}

interface FileMetadata {
description: string
restrict?: string
categories?: string[]
tabIngest?: string
}

export class FileHelper extends DataverseApiHelper {
static createMany(count: number, type: 'csv' | 'txt' = 'txt'): Blob[] {
static createManyRestricted(
count: number,
type: 'csv' | 'txt' = 'txt',
fileMetadata: FileMetadata = { description: 'This is an example file' }
): FileData[] {
const files = []
for (let i = 0; i < count; i++) {
files.push(this.create(type))
files.push(this.create(type, { ...fileMetadata, restrict: 'true' }))
}
return files
}

static create(type: 'csv' | 'txt' = 'txt'): Blob {
static createMany(
count: number,
type: 'csv' | 'txt' = 'txt',
fileMetadata: FileMetadata = { description: 'This is an example file' }
): FileData[] {
const files = []
for (let i = 0; i < count; i++) {
files.push(this.create(type, fileMetadata))
}
return files
}

static create(
type: 'csv' | 'txt' = 'txt',
fileMetadata: FileMetadata = { description: 'This is an example file' }
): FileData {
let fileBinary = new Blob([this.generateTxtData()], { type: 'text/plain' })

if (type === 'csv') {
return new Blob([this.generateCsvData()], { type: 'text/csv' })
fileBinary = new Blob([this.generateCsvData()], { type: 'text/csv' })
}

return {
file: fileBinary,
jsonData: JSON.stringify(fileMetadata)
}
return new Blob([this.generateTxtData()], { type: 'text/plain' })
}

static generateCsvData(): string {
Expand Down

0 comments on commit ec98c1f

Please sign in to comment.