From 6ec635d4c3b3e85fcabbb70936408e0d5414c766 Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Wed, 28 Aug 2024 12:37:48 +0200 Subject: [PATCH 1/3] install dependency --- report-viewer/package-lock.json | 81 +++++++++++++++++++++++---------- report-viewer/package.json | 1 + 2 files changed, 58 insertions(+), 24 deletions(-) diff --git a/report-viewer/package-lock.json b/report-viewer/package-lock.json index e328ce47b..8872d2f01 100644 --- a/report-viewer/package-lock.json +++ b/report-viewer/package-lock.json @@ -26,6 +26,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", @@ -816,6 +817,47 @@ "integrity": "sha512-XuySG1E38YScSJoMlqovLru4KTUNSjgVTIjyh7qMX6aNN5HY5Ct5LhRJdxO79JtTzKfzV/bnWpz+zquYrISsvw==", "dev": true }, + "node_modules/@pinia/testing": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/@pinia/testing/-/testing-0.1.5.tgz", + "integrity": "sha512-AcGzuotkzhRoF00htuxLfIPBBHVE6HjjB3YC5Y3os8vRgKu6ipknK5GBQq9+pduwYQhZ+BcCZDC9TyLAUlUpoQ==", + "dev": true, + "dependencies": { + "vue-demi": "^0.14.10" + }, + "funding": { + "url": "https://github.com/sponsors/posva" + }, + "peerDependencies": { + "pinia": ">=2.2.1" + } + }, + "node_modules/@pinia/testing/node_modules/vue-demi": { + "version": "0.14.10", + "resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.14.10.tgz", + "integrity": "sha512-nMZBOwuzabUO0nLgIcc6rycZEebF6eeUfaiQx9+WSk8e29IbLvPU9feI6tqW4kTo3hvoYAJkMh8n8D0fuISphg==", + "dev": true, + "hasInstallScript": true, + "bin": { + "vue-demi-fix": "bin/vue-demi-fix.js", + "vue-demi-switch": "bin/vue-demi-switch.js" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + }, + "peerDependencies": { + "@vue/composition-api": "^1.0.0-rc.1", + "vue": "^3.0.0-0 || ^2.6.0" + }, + "peerDependenciesMeta": { + "@vue/composition-api": { + "optional": true + } + } + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -3531,21 +3573,6 @@ "node": ">=16.17.0" } }, - "node_modules/husky": { - "version": "9.1.5", - "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.5.tgz", - "integrity": "sha512-rowAVRUBfI0b4+niA4SJMhfQwc107VLkBUgEYYAOQAbqDCnra1nYh83hF/MDmhYs9t9n1E3DuKOrs2LYNC+0Ag==", - "dev": true, - "bin": { - "husky": "bin.js" - }, - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/typicode" - } - }, "node_modules/iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", @@ -5211,12 +5238,12 @@ } }, "node_modules/pinia": { - "version": "2.1.7", - "resolved": "https://registry.npmjs.org/pinia/-/pinia-2.1.7.tgz", - "integrity": "sha512-+C2AHFtcFqjPih0zpYuvof37SFxMQ7OEG2zV9jRI12i9BOy3YQVAHwdKtyyc8pDcDyIc33WCIsZaCFWU7WWxGQ==", + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/pinia/-/pinia-2.2.2.tgz", + "integrity": "sha512-ja2XqFWZC36mupU4z1ZzxeTApV7DOw44cV4dhQ9sGwun+N89v/XP7+j7q6TanS1u1tdbK4r+1BUx7heMaIdagA==", "dependencies": { - "@vue/devtools-api": "^6.5.0", - "vue-demi": ">=0.14.5" + "@vue/devtools-api": "^6.6.3", + "vue-demi": "^0.14.10" }, "funding": { "url": "https://github.com/sponsors/posva" @@ -5236,9 +5263,9 @@ } }, "node_modules/pinia/node_modules/vue-demi": { - "version": "0.14.7", - "resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.14.7.tgz", - "integrity": "sha512-EOG8KXDQNwkJILkx/gPcoL/7vH+hORoBaKgGe+6W7VFMvCYJfmF2dGbvgDroVnI8LU7/kTu8mbjRZGBU1z9NTA==", + "version": "0.14.10", + "resolved": "https://registry.npmjs.org/vue-demi/-/vue-demi-0.14.10.tgz", + "integrity": "sha512-nMZBOwuzabUO0nLgIcc6rycZEebF6eeUfaiQx9+WSk8e29IbLvPU9feI6tqW4kTo3hvoYAJkMh8n8D0fuISphg==", "hasInstallScript": true, "bin": { "vue-demi-fix": "bin/vue-demi-fix.js", @@ -6114,6 +6141,12 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/sortablejs": { + "version": "1.15.2", + "resolved": "https://registry.npmjs.org/sortablejs/-/sortablejs-1.15.2.tgz", + "integrity": "sha512-FJF5jgdfvoKn1MAKSdGs33bIqLi3LmsgVTliuX6iITj834F+JRQZN90Z93yql8h0K2t0RwDPBmxwlbZfDcxNZA==", + "peer": true + }, "node_modules/source-map-js": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", @@ -6724,7 +6757,7 @@ "version": "5.5.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", - "dev": true, + "devOptional": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/report-viewer/package.json b/report-viewer/package.json index 2b8648b06..7133e1d16 100644 --- a/report-viewer/package.json +++ b/report-viewer/package.json @@ -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", From 72cb87895d94ff55764ea0b3c5eb170826afffc8 Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Wed, 28 Aug 2024 15:06:19 +0200 Subject: [PATCH 2/3] transform tests --- .../src/model/factories/ComparisonFactory.ts | 2 + .../model/factories/ComparisonFactory.test.ts | 86 ++++++++++--------- .../model/factories/OptionsFactory.test.ts | 25 ++---- .../model/factories/OverviewFactory.test.ts | 38 +++----- .../unit/model/factories/ValidComparison.json | 16 ++-- 5 files changed, 72 insertions(+), 95 deletions(-) diff --git a/report-viewer/src/model/factories/ComparisonFactory.ts b/report-viewer/src/model/factories/ComparisonFactory.ts index 0b4b774c3..ae85f219f 100644 --- a/report-viewer/src/model/factories/ComparisonFactory.ts +++ b/report-viewer/src/model/factories/ComparisonFactory.ts @@ -44,6 +44,8 @@ export class ComparisonFactory extends BaseFactory { slash(match.secondFile as string) ) + console.log(secondSubmissionId, match.secondFile, fileOfSecond) + if (fileOfFirst == undefined || fileOfSecond == undefined) { throw new Error( `The report viewer expected to find the file ${fileOfFirst == undefined ? match.firstFile : match.secondFile} in the submissions, but did not find it.` diff --git a/report-viewer/tests/unit/model/factories/ComparisonFactory.test.ts b/report-viewer/tests/unit/model/factories/ComparisonFactory.test.ts index eabfc58ea..a918f43ed 100644 --- a/report-viewer/tests/unit/model/factories/ComparisonFactory.test.ts +++ b/report-viewer/tests/unit/model/factories/ComparisonFactory.test.ts @@ -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() diff --git a/report-viewer/tests/unit/model/factories/OptionsFactory.test.ts b/report-viewer/tests/unit/model/factories/OptionsFactory.test.ts index b6719152c..5cbc82bee 100644 --- a/report-viewer/tests/unit/model/factories/OptionsFactory.test.ts +++ b/report-viewer/tests/unit/model/factories/OptionsFactory.test.ts @@ -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({ diff --git a/report-viewer/tests/unit/model/factories/OverviewFactory.test.ts b/report-viewer/tests/unit/model/factories/OverviewFactory.test.ts index 6104668ce..d5f9fb21d 100644 --- a/report-viewer/tests/unit/model/factories/OverviewFactory.test.ts +++ b/report-viewer/tests/unit/model/factories/OverviewFactory.test.ts @@ -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'], @@ -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() }) }) diff --git a/report-viewer/tests/unit/model/factories/ValidComparison.json b/report-viewer/tests/unit/model/factories/ValidComparison.json index 57453ca7b..2698402a2 100644 --- a/report-viewer/tests/unit/model/factories/ValidComparison.json +++ b/report-viewer/tests/unit/model/factories/ValidComparison.json @@ -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, @@ -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, @@ -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, @@ -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, From 107e8b77d5f7e1880377b9679bbfae54ab35c452 Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Wed, 28 Aug 2024 15:09:10 +0200 Subject: [PATCH 3/3] remove console log --- report-viewer/src/model/factories/ComparisonFactory.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/report-viewer/src/model/factories/ComparisonFactory.ts b/report-viewer/src/model/factories/ComparisonFactory.ts index ae85f219f..0b4b774c3 100644 --- a/report-viewer/src/model/factories/ComparisonFactory.ts +++ b/report-viewer/src/model/factories/ComparisonFactory.ts @@ -44,8 +44,6 @@ export class ComparisonFactory extends BaseFactory { slash(match.secondFile as string) ) - console.log(secondSubmissionId, match.secondFile, fileOfSecond) - if (fileOfFirst == undefined || fileOfSecond == undefined) { throw new Error( `The report viewer expected to find the file ${fileOfFirst == undefined ? match.firstFile : match.secondFile} in the submissions, but did not find it.`