Skip to content

Enhance/add jest cases #924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion report-viewer/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = {
testEnvironment: 'jsdom',
transform: {
"^.+\\.vue$": "@vue/vue3-jest",
"^.+\\js$": "babel-jest"
"^.+\\js$": "babel-jest",
"^.+\\.(css|scss|png|jpg|svg)$": "jest-transform-stub"
},
moduleFileExtensions: ['vue', 'js', 'json', 'jsx', 'ts', 'tsx', 'node'],
moduleNameMapper: {
Expand Down
18 changes: 18 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 @@ -45,6 +45,7 @@
"eslint-plugin-vue": "^8.7.1",
"jest": "^29.4.0",
"jest-environment-jsdom": "^29.4.2",
"jest-transform-stub": "^2.0.0",
"lint-staged": "^13.1.0",
"prettier": "^2.8.4",
"ts-jest": "^29.0.5",
Expand Down
2 changes: 1 addition & 1 deletion report-viewer/src/components/CodePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
>
<div class="file-title mover">
<p style="width: 90%" @click="$emit('toggleCollapse')">
<hand class="filer-header">{{ title }}</hand>
<a class="filer-header">{{ title }}</a>
</p>
<button
class="collapse-button"
Expand Down
12 changes: 8 additions & 4 deletions report-viewer/tests/unit/components/LineOfCode.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { mount } from '@vue/test-utils'
import { shallowMount } from '@vue/test-utils'
import LineOfCode from '@/components/LineOfCode.vue'

test("loc", () => {
const wrapper = mount(LineOfCode, {
const wrapper = shallowMount(LineOfCode, {
props: {
visible: true,
text: "Hello World",
lineNumber: 3,
color: "white"
}
})
});
const preText = wrapper.find({ ref: 'lineRef'});
expect(preText.text()).toContain('Hello World');
expect(preText.text()).toContain('3');

expect(wrapper.text()).toContain('Hello World');
wrapper.vm.$emit('lineSelected');
expect(wrapper.emitted().lineSelected).toBeTruthy();
})
26 changes: 26 additions & 0 deletions report-viewer/tests/unit/components/MatchTable.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {shallowMount} from '@vue/test-utils'
import MatchTable from "@/components/MatchTable.vue";
import store from "@/store/store";

beforeEach(()=>{
let fileIdToDisplayNameMap = store.state.fileIdToDisplayName;
fileIdToDisplayNameMap.set("A","A");
fileIdToDisplayNameMap.set("C","C");
})

test("MT", () => {
const wrapper = shallowMount(MatchTable,{
props: {
id1: "A",
id2: "C",
matches: [{firstFile:"A\\GSTiling.java",secondFile:"C\\GSTiling.java",startInFirst:6,endInFirst:247,startInSecond:13,endInSecond:254,tokens:345,color:"\\hsla(0, 80%, 50%, 0.3)"}],
},
});
const matchesInfo = wrapper.findAll(".td-content p");
expect(matchesInfo[0].text()).toContain("A\\GSTiling.java");
expect(matchesInfo[1].text()).toContain("(6 - 247)");
expect(matchesInfo[2].text()).toContain("C\\GSTiling.java");
expect(matchesInfo[3].text()).toContain("(13 - 254)");
const matchToken = wrapper.findAll("td");
expect(parseInt(matchToken[2].text())).toBe(345);
})
138 changes: 138 additions & 0 deletions report-viewer/tests/unit/model/Overview.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import {Overview} from "@/model/Overview";
import {Metric} from "@/model/Metric";
import {Cluster} from "@/model/Cluster";
test('overview', () => {
const submissionFolderPath:Array<string> = ["C:\\Users\\23651\\Desktop\\JPlag\\core\\src\\test\\resources\\de\\jplag\\samples\\PartialPlagiarism"]
const baseCodeFolderPath: string = "";
const language: string = "Javac based AST plugin";
const fileExtensions: Array<string> = [".java",".JAVA"];
const matchSensitivity: number = 9;
const dateOfExecution: string = "14/12/22";
const durationOfExecution: number = 40;
const metrics: Array<Metric> = [{
"metricName": "AVG",
"distribution": [1, 0, 2, 0, 0, 0, 0, 3, 0, 4],
"metricThreshold": 0,
"comparisons": [
{
"firstSubmissionId": "A",
"secondSubmissionId": "C",
"similarity": 0.9966329966329966
},
{
"firstSubmissionId": "D",
"secondSubmissionId": "A",
"similarity": 0.7787255393878575
},
{
"firstSubmissionId": "D",
"secondSubmissionId": "C",
"similarity": 0.7787255393878575
},
{
"firstSubmissionId": "B",
"secondSubmissionId": "D",
"similarity": 0.2827868852459016
},
{
"firstSubmissionId": "B",
"secondSubmissionId": "A",
"similarity": 0.2457689477557027
},
{
"firstSubmissionId": "B",
"secondSubmissionId": "C",
"similarity": 0.2457689477557027
},
{
"firstSubmissionId": "E",
"secondSubmissionId": "A",
"similarity": 0
},
{
"firstSubmissionId": "E",
"secondSubmissionId": "D",
"similarity": 0
},
{
"firstSubmissionId": "E",
"secondSubmissionId": "B",
"similarity": 0
},
{
"firstSubmissionId": "E",
"secondSubmissionId": "C",
"similarity": 0
}
],
"description": "Average of both program coverages. This is the default similarity which works in most cases: Matches with a high average similarity indicate that the programs work in a very similar way."
},{
"metricName": "MAX",
"distribution": [5, 1, 0, 0, 0, 0, 0, 0, 0, 4],
"metricThreshold": 0,
"comparisons": [
{
"firstSubmissionId": "A",
"secondSubmissionId": "C",
"similarity": 0.9966329966329966
},
{
"firstSubmissionId": "B",
"secondSubmissionId": "A",
"similarity": 0.9766081871345029
},
{
"firstSubmissionId": "B",
"secondSubmissionId": "C",
"similarity": 0.9766081871345029
},
{
"firstSubmissionId": "D",
"secondSubmissionId": "A",
"similarity": 0.9639751552795031
},
{
"firstSubmissionId": "D",
"secondSubmissionId": "C",
"similarity": 0.9639751552795031
},
{
"firstSubmissionId": "B",
"secondSubmissionId": "D",
"similarity": 0.8070175438596491
},
{
"firstSubmissionId": "E",
"secondSubmissionId": "A",
"similarity": 0
},
{
"firstSubmissionId": "E",
"secondSubmissionId": "D",
"similarity": 0
},
{
"firstSubmissionId": "E",
"secondSubmissionId": "B",
"similarity": 0
},
{
"firstSubmissionId": "E",
"secondSubmissionId": "C",
"similarity": 0
}
],
"description": "Maximum of both program coverages. This ranking is especially useful if the programs are very different in size. This can happen when dead code was inserted to disguise the origin of the plagiarized program."
}];
const clusters: Array<Cluster> = [];
const submissionIdsToComparisonFileName: Map<string,Map<string,string>> = new Map<string, Map<string, string>>();
const overview: Overview = new Overview(submissionFolderPath,baseCodeFolderPath,language,fileExtensions,matchSensitivity,
dateOfExecution,durationOfExecution,metrics,clusters,submissionIdsToComparisonFileName);
expect(overview.language).toMatch("Javac based AST plugin");
expect(overview.matchSensitivity).toBe(9);
expect(overview.dateOfExecution).toMatch("14/12/22");
expect(overview.durationOfExecution).toBe(40);
expect(overview.metrics.length).toBe(2);
expect(overview.metrics[0].metricName).toMatch("AVG");
expect(overview.metrics[1].metricName).toMatch("MAX");
})
Loading