Skip to content

Commit 67c6a53

Browse files
Merge pull request #54 from COS301-SE-2024/update/vitests
Addition of Vitests for Unit Testing
2 parents 66ac4d6 + e66e339 commit 67c6a53

File tree

6 files changed

+103
-6
lines changed

6 files changed

+103
-6
lines changed

src/client/package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
"lint": "prettier --check . && eslint .",
1111
"format": "prettier --write .",
1212
"cy:open-ct": "cypress open --component",
13-
"cy:run-ct": "cypress run --e2e"
13+
"cy:run-ct": "cypress run --e2e",
14+
"test": "vitest run",
15+
"test:ui": "vitest --ui",
16+
"test:watch": "vitest"
1417
},
1518
"devDependencies": {
1619
"@cypress/code-coverage": "^3.12.39",
@@ -19,11 +22,14 @@
1922
"@neoconfetti/svelte": "^1.0.0",
2023
"@sveltejs/adapter-auto": "^3.0.0",
2124
"@sveltejs/kit": "^2.0.0",
22-
"@sveltejs/vite-plugin-svelte": "^3.0.0",
25+
"@sveltejs/vite-plugin-svelte": "^3.1.1",
2326
"@tailwindcss/typography": "^0.5.10",
27+
"@testing-library/jest-dom": "^6.4.5",
28+
"@testing-library/svelte": "^5.1.0",
2429
"@types/eslint": "^8.56.0",
2530
"@typescript-eslint/eslint-plugin": "^7.0.0",
2631
"@typescript-eslint/parser": "^7.0.0",
32+
"@vitest/ui": "^1.6.0",
2733
"autoprefixer": "^10.4.16",
2834
"cypress": "^13.10.0",
2935
"cypress-svelte-unit-test": "^3.3.4",
@@ -34,6 +40,7 @@
3440
"flowbite-svelte": "^0.46.1",
3541
"flowbite-svelte-icons": "^1.6.1",
3642
"istanbul-lib-coverage": "^3.2.2",
43+
"jsdom": "^24.1.0",
3744
"nyc": "^15.1.0",
3845
"postcss": "^8.4.33",
3946
"prettier": "^3.1.1",
@@ -44,7 +51,8 @@
4451
"tailwindcss": "^3.4.1",
4552
"tslib": "^2.4.1",
4653
"typescript": "^5.0.0",
47-
"vite": "^5.0.3"
54+
"vite": "^5.0.3",
55+
"vitest": "^1.6.0"
4856
},
4957
"type": "module",
5058
"dependencies": {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { render } from '@testing-library/svelte';
2+
import { expect, test } from 'vitest';
3+
import ActivityTimeline from '../lib/components/admin/+Activities.svelte';
4+
5+
test('renders activities correctly', () => {
6+
const { getByText } = render(ActivityTimeline);
7+
8+
// Check that each activity title and description is rendered
9+
const activities = [
10+
{
11+
title: 'Budget Planning Meeting',
12+
date: '15 Oct',
13+
activity:
14+
'Attend and contribute to the annual budget planning meeting to allocate resources for the upcoming academic year.'
15+
},
16+
{
17+
title: 'Faculty Evaluation',
18+
date: '18 Oct',
19+
activity:
20+
'Conduct evaluations for tenured and non-tenured faculty members, reviewing their performance and providing feedback.'
21+
},
22+
{
23+
title: 'Student Affairs Committee',
24+
date: '20 Oct',
25+
activity:
26+
'Participate in the Student Affairs Committee meeting to discuss and address student concerns and initiatives.'
27+
},
28+
{
29+
title: 'Campus Safety Review',
30+
date: '22 Oct',
31+
activity:
32+
'Review campus safety protocols and emergency procedures with the safety department to ensure the well-being of students and staff.'
33+
},
34+
{
35+
title: 'Strategic Planning Workshop',
36+
date: '25 Oct',
37+
activity:
38+
'Engage in a strategic planning workshop to set long-term goals and objectives for the university’s growth and development.'
39+
},
40+
{
41+
title: 'Alumni Networking Event',
42+
date: '30 Oct',
43+
activity:
44+
'Host an alumni networking event to strengthen relationships with former students and encourage their involvement in university activities.'
45+
}
46+
];
47+
48+
activities.forEach((activity) => {
49+
expect(getByText(activity.title)).toBeInTheDocument();
50+
expect(getByText(activity.activity)).toBeInTheDocument();
51+
});
52+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { render } from '@testing-library/svelte';
2+
import Degree from '../lib/components/admin/+Degrees.svelte';
3+
import { expect, test } from 'vitest';
4+
import { degrees } from '../routes/degrees';
5+
6+
degrees.forEach((degree) => {
7+
test(`displays the degree: ${degree.program}`, () => {
8+
const { getByText } = render(Degree, { degrees });
9+
expect(getByText(degree.program)).toBeVisible();
10+
});
11+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// sum.test.js
2+
import { render } from '@testing-library/svelte';
3+
import { expect, test } from 'vitest';
4+
import Workspaces from '../lib/components/admin/+Workspaces.svelte';
5+
6+
test('it renders the correct number of workspace cards', () => {
7+
const workspaces = [
8+
{ title: 'COS 333', description: 'Programming languages', image: 'COS333.png' },
9+
{ title: 'COS 314', description: 'Artificial Intelligence', image: 'COS314.png' },
10+
{ title: 'COS 344', description: 'Computer Graphics', image: 'COS344.png' }
11+
];
12+
13+
const { getByText } = render(Workspaces, { props: { workspaces } });
14+
15+
expect(getByText('COS 333')).toBeInTheDocument();
16+
expect(getByText('Programming languages')).toBeInTheDocument();
17+
expect(getByText('COS 314')).toBeInTheDocument();
18+
expect(getByText('Artificial Intelligence')).toBeInTheDocument();
19+
expect(getByText('COS 344')).toBeInTheDocument();
20+
expect(getByText('Computer Graphics')).toBeInTheDocument();
21+
});

src/client/vite.config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { sveltekit } from '@sveltejs/kit/vite';
2-
import { defineConfig } from 'vite';
2+
import { defineConfig } from 'vitest/config';
3+
import { svelteTesting } from '@testing-library/svelte/vite';
34

45
export default defineConfig({
5-
plugins: [sveltekit()],
6-
6+
plugins: [sveltekit(), svelteTesting()],
7+
test: {
8+
environment: 'jsdom',
9+
setupFiles: ['./vitest-setup.js']
10+
},
711
ssr: {
812
noExternal: ['three']
913
}

src/client/vitest-setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom/vitest';

0 commit comments

Comments
 (0)