Skip to content

Commit

Permalink
#285: Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aswallace committed Dec 8, 2022
1 parent ccf56c6 commit bf3f860
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 0 deletions.
91 changes: 91 additions & 0 deletions app/tests/unit/components/explorer/DatasetDetailView.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import createWrapper from '../../../jest/script/wrapper'
import { enableAutoDestroy } from '@vue/test-utils'
import Dataset from '@/pages/explorer/curate/edit/Dataset.vue'

const apollo = {
getFilesets: {
filesets: [
{
filesetName: 'L325_S1_Test_2015',
files: [
{
id: 'test_file1.xlsx',
filename: 'test_file1.xlsx',
contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
},
{
id: 'test_file2.csv',
filename: 'test_file2.csv',
contentType: 'text/csv'
}
]
},
{
filesetName: 'L325_S2_Test_2015',
files: [
{
id: 'test_file1.xlsx',
filename: 'test_file1.xlsx',
contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
},
{
id: 'test_file2.csv',
filename: 'test_file2.csv',
contentType: 'text/csv'
}
]
}
],
totalItems: 2,
pageSize: 20,
pageNumber: 1,
totalPages: 1,
hasPreviousPage: false,
hasNextPage: false
},
verifyUser: {
isAuth: true
}
}

describe('Dataset.vue', () => {
const defaultProps = {
id: '123456789'
}

let wrapper
beforeEach(async () => {
wrapper = await createWrapper(Dataset, {
props: defaultProps,
mocks: {
$apollo: {
loading: false
}
}
}, true)
await wrapper.setData({ getFilesets: apollo.getFilesets, verifyUser: apollo.verifyUser })
})

enableAutoDestroy(afterEach)

it('displays the current dataset ID', () => {
expect.assertions(1)
expect(wrapper.text()).toContain(defaultProps.id)
})

it('renders labeled cards for all of the filesets', () => {
expect.assertions(3)
const filesetCards = wrapper.findAll('.md-card')
expect(filesetCards.length).toBe(2)
expect(filesetCards.at(0).text()).toContain(apollo.getFilesets.filesets[0].filesetName)
expect(filesetCards.at(1).text()).toContain(apollo.getFilesets.filesets[1].filesetName)
})

it('displays labeled icons for files in fileset', () => {
expect.assertions(2)
const filesetCard = wrapper.findAll('.md-card').at(0)
const fileIcons = filesetCard.findAll('.md-icon')
expect(fileIcons.length).toBe(2)
expect(filesetCard.text()).toContain('test_file1.xlsx')
})
})
105 changes: 105 additions & 0 deletions app/tests/unit/components/explorer/UserDatasets.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import createWrapper from '../../../jest/script/wrapper'
import { enableAutoDestroy } from '@vue/test-utils'
import UserDatasets from '@/pages/explorer/curate/edit/UserDatasets.vue'

const apollo = {
getUserDataset: {
totalItems: 2,
pageSize: 10,
pageNumber: 1,
totalPages: 1,
hasNextPage: false,
hasPreviousPage: false,
datasets: [
{
datasetGroupId: '5e96fa91c9db0157d0737e39',
status: 'APPROVED',
title: null,
filesetInfo: [
{
filesetName: 'L325_S1_Test_2015',
files: [
{
id: 'test_file1.png',
filename: 'test_file1.png',
contentType: 'image/png'
},
{
id: 'test_file2.csv',
filename: 'test_file2.csv',
contentType: 'text/csv'
}
]
},
{
filesetName: 'L325_S2_Test_2015',
files: [
{
id: 'test_file1.png',
filename: 'test_file1.png',
contentType: 'image/png'
}
]
}
]
},
{
datasetGroupId: '5e96fae7c9db0157d0737e3a',
title: null,
filesetInfo: [{
filesetName: 'L325_S3_Test_2015',
files: [
{
id: '5b59f276e74a1d4cdbaed0a7',
filename: '1.png',
contentType: 'image/png'
}
]
}]
}
]
},
verifyUser: {
isAuth: true,
user: {
username: 'Test User'
}
}
}

describe('UserDatasets.vue', () => {
let wrapper
beforeEach(async () => {
wrapper = await createWrapper(UserDatasets, {
mocks: {
$apollo: {
loading: false
}
}
}, true)
await wrapper.setData({ getUserDataset: apollo.getUserDataset, verifyUser: apollo.verifyUser })
})

enableAutoDestroy(afterEach)

it('displays the name of current user', () => {
expect.assertions(1)
expect(wrapper.text()).toContain('Test User')
})

it('renders labeled cards for all of the datasets', () => {
expect.assertions(3)
const filesetCards = wrapper.findAll('.md-card')
expect(filesetCards.length).toBe(2)
expect(filesetCards.at(0).text()).toContain(apollo.getUserDataset.datasets[0].datasetGroupId)
expect(filesetCards.at(1).text()).toContain(apollo.getUserDataset.datasets[1].datasetGroupId)
})

it('displays labeled icons for filesets in a dataset', () => {
expect.assertions(2)
const datasetCard = wrapper.findAll('.md-card').at(0)
const datasetIcons = datasetCard.find('.md-card-content').findAll('.md-icon')
expect(datasetIcons.length).toBe(2)
expect(datasetCard.text()).toContain('L325_S')
})
})

0 comments on commit bf3f860

Please sign in to comment.