Skip to content

Commit 4035658

Browse files
committed
Added a basic test
1 parent 2add933 commit 4035658

File tree

7 files changed

+9277
-1639
lines changed

7 files changed

+9277
-1639
lines changed

__tests__/App.test.js

Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
import { createLocalVue, shallowMount } from "@vue/test-utils";
2+
import VueI18n from "vue-i18n";
3+
import App from "@/App.vue";
4+
import { languages } from "@/i18n";
5+
const messages = Object.assign(languages);
6+
7+
describe("App.vue", () => {
8+
let wrapper;
9+
let localVue;
10+
11+
beforeEach(() => {
12+
localVue = createLocalVue();
13+
localVue.use(VueI18n);
14+
const i18n = new VueI18n({
15+
locale: "en", // set locale
16+
fallbackLocale: "el",
17+
messages, // set locale messages
18+
});
19+
20+
wrapper = shallowMount(App, {
21+
localVue,
22+
i18n,
23+
});
24+
});
25+
26+
it("initializes with correct elements", () => {
27+
expect(wrapper.vm.currentFrame).toBe(0);
28+
expect(wrapper.vm.images).toEqual({
29+
demokritos: "demokritos.jpg",
30+
introBackground: "introFrame/bg.jpg",
31+
introButton: "en/introFrame/button-go.png",
32+
introRobot: "introFrame/robot.png",
33+
introText1: "en/introFrame/text1.png",
34+
introText2: "en/introFrame/text2.png",
35+
introText3: "en/introFrame/text3.png",
36+
"robot-hi": "robot-hi.png",
37+
scify: "SciFY.png",
38+
"text-bubble": "text-bubble.png",
39+
tryMeBackground: "tryMeFrame/bg.jpg",
40+
tryMeButton: "en/tryMeFrame/buttonIcon.png",
41+
});
42+
expect(wrapper.vm.jsonData).toEqual({
43+
data: [
44+
{
45+
color: "red",
46+
id: 1,
47+
img: "instances/apple_red_50_yes.jpg",
48+
stem: true,
49+
weight: 50,
50+
},
51+
{
52+
color: "green",
53+
id: 2,
54+
img: "instances/orange_green_35_yes.jpg",
55+
stem: true,
56+
weight: 35,
57+
},
58+
{
59+
color: "golden",
60+
id: 3,
61+
img: "instances/apple_gold_150_no.jpg",
62+
stem: false,
63+
weight: 150,
64+
},
65+
{
66+
color: "orange",
67+
id: 4,
68+
img: "instances/orange_orange_56_yes.jpg",
69+
stem: true,
70+
weight: 56,
71+
},
72+
{
73+
color: "orange",
74+
id: 5,
75+
img: "instances/orange_orange_80_no.jpg",
76+
stem: false,
77+
weight: 80,
78+
},
79+
{
80+
color: "red",
81+
id: 6,
82+
img: "instances/apple_red_45_yes.jpg",
83+
stem: true,
84+
weight: 45,
85+
},
86+
{
87+
color: "red",
88+
id: 7,
89+
img: "instances/apple_red_65_yes.jpg",
90+
stem: true,
91+
weight: 65,
92+
},
93+
{
94+
color: "orange",
95+
id: 8,
96+
img: "instances/orange_orange_37_no.jpg",
97+
stem: false,
98+
weight: 37,
99+
},
100+
{
101+
color: "green",
102+
id: 9,
103+
img: "instances/apple_green_50_yes.jpg",
104+
stem: true,
105+
weight: 50,
106+
},
107+
{
108+
color: "orange",
109+
id: 10,
110+
img: "instances/orange_orange_62_no.jpg",
111+
stem: false,
112+
weight: 62,
113+
},
114+
],
115+
default: {
116+
data: [
117+
{
118+
color: "red",
119+
id: 1,
120+
img: "instances/apple_red_50_yes.jpg",
121+
stem: true,
122+
weight: 50,
123+
},
124+
{
125+
color: "green",
126+
id: 2,
127+
img: "instances/orange_green_35_yes.jpg",
128+
stem: true,
129+
weight: 35,
130+
},
131+
{
132+
color: "golden",
133+
id: 3,
134+
img: "instances/apple_gold_150_no.jpg",
135+
stem: false,
136+
weight: 150,
137+
},
138+
{
139+
color: "orange",
140+
id: 4,
141+
img: "instances/orange_orange_56_yes.jpg",
142+
stem: true,
143+
weight: 56,
144+
},
145+
{
146+
color: "orange",
147+
id: 5,
148+
img: "instances/orange_orange_80_no.jpg",
149+
stem: false,
150+
weight: 80,
151+
},
152+
{
153+
color: "red",
154+
id: 6,
155+
img: "instances/apple_red_45_yes.jpg",
156+
stem: true,
157+
weight: 45,
158+
},
159+
{
160+
color: "red",
161+
id: 7,
162+
img: "instances/apple_red_65_yes.jpg",
163+
stem: true,
164+
weight: 65,
165+
},
166+
{
167+
color: "orange",
168+
id: 8,
169+
img: "instances/orange_orange_37_no.jpg",
170+
stem: false,
171+
weight: 37,
172+
},
173+
{
174+
color: "green",
175+
id: 9,
176+
img: "instances/apple_green_50_yes.jpg",
177+
stem: true,
178+
weight: 50,
179+
},
180+
{
181+
color: "orange",
182+
id: 10,
183+
img: "instances/orange_orange_62_no.jpg",
184+
stem: false,
185+
weight: 62,
186+
},
187+
],
188+
features: ["Apple", "Orange"],
189+
},
190+
features: ["Apple", "Orange"],
191+
});
192+
expect(wrapper.vm.allData).toEqual([
193+
{
194+
color: "red",
195+
id: 1,
196+
img: "instances/apple_red_50_yes.jpg",
197+
stem: true,
198+
weight: 50,
199+
},
200+
{
201+
color: "green",
202+
id: 2,
203+
img: "instances/orange_green_35_yes.jpg",
204+
stem: true,
205+
weight: 35,
206+
},
207+
{
208+
color: "golden",
209+
id: 3,
210+
img: "instances/apple_gold_150_no.jpg",
211+
stem: false,
212+
weight: 150,
213+
},
214+
{
215+
color: "orange",
216+
id: 4,
217+
img: "instances/orange_orange_56_yes.jpg",
218+
stem: true,
219+
weight: 56,
220+
},
221+
{
222+
color: "orange",
223+
id: 5,
224+
img: "instances/orange_orange_80_no.jpg",
225+
stem: false,
226+
weight: 80,
227+
},
228+
{
229+
color: "red",
230+
id: 6,
231+
img: "instances/apple_red_45_yes.jpg",
232+
stem: true,
233+
weight: 45,
234+
},
235+
{
236+
color: "red",
237+
id: 7,
238+
img: "instances/apple_red_65_yes.jpg",
239+
stem: true,
240+
weight: 65,
241+
},
242+
{
243+
color: "orange",
244+
id: 8,
245+
img: "instances/orange_orange_37_no.jpg",
246+
stem: false,
247+
weight: 37,
248+
},
249+
{
250+
color: "green",
251+
id: 9,
252+
img: "instances/apple_green_50_yes.jpg",
253+
stem: true,
254+
weight: 50,
255+
},
256+
{
257+
color: "orange",
258+
id: 10,
259+
img: "instances/orange_orange_62_no.jpg",
260+
stem: false,
261+
weight: 62,
262+
},
263+
]);
264+
expect(wrapper.vm.trainingSet).toEqual([]);
265+
expect(wrapper.vm.element).toEqual({
266+
color: "red",
267+
id: 1,
268+
img: "instances/apple_red_50_yes.jpg",
269+
stem: true,
270+
weight: 50,
271+
});
272+
expect(wrapper.vm.prediction).toBeNull();
273+
expect(wrapper.vm.features).toEqual(["Apple", "Orange"]);
274+
expect(wrapper.vm.robotText).toBeNull();
275+
expect(wrapper.vm.decisionTree).toBeNull();
276+
expect(wrapper.vm.lastTrainingInput).toBeNull();
277+
});
278+
279+
it("changes frame on introExit", () => {
280+
wrapper.vm.introExit();
281+
expect(wrapper.vm.currentFrame).toBe(1);
282+
});
283+
284+
it("changes frame on tryMeExit", () => {
285+
wrapper.vm.tryMeExit();
286+
expect(wrapper.vm.currentFrame).toBe(2);
287+
});
288+
289+
it("changes frame on nextButton", () => {
290+
wrapper.vm.nextButton();
291+
expect(wrapper.vm.currentFrame).toBe(3);
292+
});
293+
294+
it("changes frame on backButton", () => {
295+
wrapper.vm.backButton();
296+
expect(wrapper.vm.currentFrame).toBe(3);
297+
});
298+
299+
it("resets state on resetState", async () => {
300+
await wrapper.vm.resetState();
301+
expect(wrapper.vm.currentFrame).toBe(0);
302+
expect(wrapper.vm.prediction).toBeNull();
303+
expect(wrapper.vm.robotText).toBeNull();
304+
});
305+
});

jest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
testEnvironment: "jest-environment-jsdom",
3+
moduleFileExtensions: [
4+
"js",
5+
"json",
6+
// tell Jest to handle `*.vue` files
7+
"vue"
8+
],
9+
transform: {
10+
// process `*.vue` files with `vue-jest`
11+
".*\\.(vue)$": "@vue/vue2-jest",
12+
// process js with `babel-jest`
13+
"^.+\\.js$": "babel-jest"
14+
},
15+
moduleNameMapper: {
16+
"^@/(.*)$": "<rootDir>/src/$1",
17+
},
18+
};

0 commit comments

Comments
 (0)