Skip to content

Commit

Permalink
Merge pull request #1947 from jplag/report-viewer/pinia-testing
Browse files Browse the repository at this point in the history
Switch tests to correct pinia framework
  • Loading branch information
tsaglam authored Aug 29, 2024
2 parents 92837df + ea59119 commit 74e483d
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 95 deletions.
42 changes: 42 additions & 0 deletions report-viewer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions report-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"vue-virtual-scroller": "^2.0.0-beta.8"
},
"devDependencies": {
"@pinia/testing": "^0.1.5",
"@playwright/test": "^1.46.0",
"@rushstack/eslint-patch": "^1.10.4",
"@types/jsdom": "^21.1.7",
Expand Down
86 changes: 45 additions & 41 deletions report-viewer/tests/unit/model/factories/ComparisonFactory.test.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,59 @@
import { vi, it, beforeAll, describe, expect } from 'vitest'
import { it, beforeEach, describe, expect } from 'vitest'
import validNew from './ValidComparison.json'
import { ComparisonFactory } from '@/model/factories/ComparisonFactory'
import { store } from '@/stores/store'
import { MetricType } from '@/model/MetricType'

const store = {
state: {
localModeUsed: false,
zipModeUsed: true,
singleModeUsed: false,
files: {}
},
getComparisonFileName: (id1: string, id2: string) => {
return `${id1}-${id2}.json`
},
filesOfSubmission: (name: string) => {
return [
{
fileName: `${name}/Structure.java`,
value: ''
},
{
fileName: `${name}/Submission.java`,
value: ''
}
]
},
getSubmissionFile: (id: string, name: string) => {
return {
fileName: name,
submissionId: id,
matchedTokenCount: 0,
displayName: name
}
}
}
import { setActivePinia, createPinia } from 'pinia'

describe('Test JSON to Comparison', () => {
beforeAll(() => {
vi.mock('@/stores/store', () => ({
store: vi.fn(() => {
return store
})
}))
beforeEach(() => {
setActivePinia(createPinia())
store().setLoadingType('zip')
})

it('Post 5.0', async () => {
store.state.files['root1-root2.json'] = JSON.stringify(validNew)
store().state.files['root1-root2.json'] = JSON.stringify(validNew)
store().state.submissionIdsToComparisonFileName.set(
'root1',
new Map([['root2', 'root1-root2.json']])
)
store().state.submissionIdsToComparisonFileName.set(
'root2',
new Map([['root1', 'root1-root2.json']])
)
store().state.submissions['root1'] = new Map()
store().state.submissions['root1'].set('root1/Structure.java', {
fileName: 'root1/Structure.java',
value: '',
submissionId: 'root1',
matchedTokenCount: 0,
displayName: 'Structure.java'
})
store().state.submissions['root1'].set('root1/Submission.java', {
fileName: 'root1/Submission.java',
value: '',
submissionId: 'root1',
matchedTokenCount: 0,
displayName: 'Submission.java'
})
store().state.submissions['root2'] = new Map()
store().state.submissions['root2'].set('root2/Structure.java', {
fileName: 'root2/Structure.java',
value: '',
submissionId: 'root2',
matchedTokenCount: 0,
displayName: 'Structure.java'
})
store().state.submissions['root2'].set('root2/Submission.java', {
fileName: 'root2/Submission.java',
value: '',
submissionId: 'root2',
matchedTokenCount: 0,
displayName: 'Submission.java'
})

const result = await ComparisonFactory.getComparison(
store.getComparisonFileName('root1', 'root2')
store().getComparisonFileName('root1', 'root2')
)

expect(result).toBeDefined()
Expand Down
25 changes: 7 additions & 18 deletions report-viewer/tests/unit/model/factories/OptionsFactory.test.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
import { beforeAll, describe, it, vi, expect } from 'vitest'
import { beforeEach, describe, it, expect } from 'vitest'
import { OptionsFactory } from '@/model/factories/OptionsFactory'
import { ParserLanguage } from '@/model/Language'
import { MetricType } from '@/model/MetricType'
import validOptions from './ValidOptions.json'

const store = {
state: {
localModeUsed: false,
zipModeUsed: true,
singleModeUsed: false,
files: {
'options.json': JSON.stringify(validOptions)
}
}
}
import { setActivePinia, createPinia } from 'pinia'
import { store } from '@/stores/store'

describe('Test JSON to Options', async () => {
beforeAll(() => {
vi.mock('@/stores/store', () => ({
store: vi.fn(() => {
return store
})
}))
beforeEach(() => {
setActivePinia(createPinia())
store().setLoadingType('zip')
})

it('Test Valid JSON', async () => {
store().state.files['options.json'] = JSON.stringify(validOptions)
const result = await OptionsFactory.getCliOptions()

expect(result).toEqual({
Expand Down
38 changes: 10 additions & 28 deletions report-viewer/tests/unit/model/factories/OverviewFactory.test.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,25 @@
import { beforeAll, describe, expect, it, vi } from 'vitest'
import { beforeAll, describe, expect, it, vi, beforeEach } from 'vitest'
import { OverviewFactory } from '@/model/factories/OverviewFactory'
import { MetricType } from '@/model/MetricType'
import { Distribution } from '@/model/Distribution'
import { ParserLanguage } from '@/model/Language'
import validNew from './ValidOverview.json'
import outdated from './OutdatedOverview.json'

const store = {
state: {
localModeUsed: false,
zipModeUsed: true,
singleModeUsed: false,
files: {}
},
saveSubmissionNames: (map) => {
expect(map.has('A')).toBeTruthy()
expect(map.has('B')).toBeTruthy()
expect(map.has('C')).toBeTruthy()
expect(map.has('D')).toBeTruthy()
},
saveComparisonFileLookup: (map) => {
expect(map.has('A')).toBeTruthy()
expect(map.has('B')).toBeTruthy()
}
}
import { setActivePinia, createPinia } from 'pinia'
import { store } from '@/stores/store'

describe('Test JSON to Overview', () => {
beforeAll(() => {
vi.mock('@/stores/store', () => ({
store: vi.fn(() => {
return store
})
}))

vi.spyOn(global.window, 'alert').mockImplementation(() => {})
})

beforeEach(() => {
setActivePinia(createPinia())
store().setLoadingType('zip')
})

it('Post 5.0', async () => {
store.state.files['overview.json'] = JSON.stringify(validNew)
store().state.files['overview.json'] = JSON.stringify(validNew)

expect(await OverviewFactory.getOverview()).toEqual({
_submissionFolderPath: ['files'],
Expand Down Expand Up @@ -143,7 +125,7 @@ describe('Test JSON to Overview', () => {

describe('Outdated JSON to Overview', () => {
it('Outdated version', async () => {
store.state.files['overview.json'] = JSON.stringify(outdated)
store().state.files['overview.json'] = JSON.stringify(outdated)
expect(() => OverviewFactory.getOverview()).rejects.toThrowError()
})
})
16 changes: 8 additions & 8 deletions report-viewer/tests/unit/model/factories/ValidComparison.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
},
"matches": [
{
"firstFile": "root2\\Structure.java",
"secondFile": "root1\\Structure.java",
"firstFile": "root1\\Structure.java",
"secondFile": "root2\\Structure.java",
"startInFirst": {
"line": 1,
"column": 1,
Expand All @@ -32,8 +32,8 @@
"tokens": 139
},
{
"firstFile": "root2\\Submission.java",
"secondFile": "root1\\Submission.java",
"firstFile": "root1\\Submission.java",
"secondFile": "root2\\Submission.java",
"startInFirst": {
"line": 129,
"column": 1,
Expand All @@ -57,8 +57,8 @@
"tokens": 34
},
{
"firstFile": "root2\\Submission.java",
"secondFile": "root1\\Submission.java",
"firstFile": "root1\\Submission.java",
"secondFile": "root2\\Submission.java",
"startInFirst": {
"line": 165,
"column": 1,
Expand All @@ -82,8 +82,8 @@
"tokens": 33
},
{
"firstFile": "root2\\Submission.java",
"secondFile": "root1\\Submission.java",
"firstFile": "root1\\Submission.java",
"secondFile": "root2\\Submission.java",
"startInFirst": {
"line": 112,
"column": 1,
Expand Down

0 comments on commit 74e483d

Please sign in to comment.