From af4fcb9dc81a91fdfc7b55b0367a4c92ca7846ae Mon Sep 17 00:00:00 2001
From: "Deepak Pradhan (Varun)" <37866666+varun2948@users.noreply.github.com>
Date: Tue, 20 Feb 2024 17:32:00 +0545
Subject: [PATCH] test (frontend): case config, add test cases (#1231)
* feat: Test cases configuration changes for vitest
* feat(Test): Button test cases added with docstring
* feat(Testcases): added a small test cases to check if test is working
---
src/frontend/package.json | 5 +-
.../src/components/__test__/Button.test.jsx | 69 +++++++++++++++++++
src/frontend/src/components/common/Button.tsx | 1 +
src/frontend/src/sum.js | 3 +
src/frontend/tests/App.test.jsx | 8 +++
src/frontend/tests/App.test.tsx | 38 ----------
src/frontend/tests/CreateProject.test.tsx | 20 ------
src/frontend/tsconfig.json | 2 +-
src/frontend/vite.config.ts | 1 +
9 files changed, 87 insertions(+), 60 deletions(-)
create mode 100644 src/frontend/src/components/__test__/Button.test.jsx
create mode 100644 src/frontend/src/sum.js
create mode 100644 src/frontend/tests/App.test.jsx
delete mode 100644 src/frontend/tests/App.test.tsx
delete mode 100644 src/frontend/tests/CreateProject.test.tsx
diff --git a/src/frontend/package.json b/src/frontend/package.json
index ac9f85ee11..c192510b6d 100755
--- a/src/frontend/package.json
+++ b/src/frontend/package.json
@@ -7,7 +7,10 @@
"build:start": "cd dist && PORT=8080 npx serve",
"start": "env-cmd -f .env.dev vite dev",
"start:live": "vite dev",
- "test": "vitest tests/",
+ "test": "vitest",
+ "test:watch": "vitest --watch",
+ "test:ui": "vitest --ui",
+ "test:coverage": "vitest --coverage",
"lint": "eslint --fix --ext .js,.jsx,.ts,.tsx src"
},
"license": "GPL-3.0-only",
diff --git a/src/frontend/src/components/__test__/Button.test.jsx b/src/frontend/src/components/__test__/Button.test.jsx
new file mode 100644
index 0000000000..68fd096221
--- /dev/null
+++ b/src/frontend/src/components/__test__/Button.test.jsx
@@ -0,0 +1,69 @@
+import { describe, expect, test } from 'vitest';
+import { render, screen, fireEvent } from '@testing-library/react';
+import Button from '../common/Button';
+import { useState } from 'react';
+
+describe('Button', () => {
+ test('renders', () => {
+ render();
+ expect(screen.getByText('NEXT')).toBeDefined();
+ });
+ /**
+ * Test suite for the Button component
+ */
+ describe('Button', () => {
+ /**
+ * Test to verify that the Button component renders with the correct text
+ */
+ test('renders', () => {
+ render();
+ expect(screen.getByText('NEXT')).toBeDefined();
+ });
+
+ /**
+ * Test to verify that the count increases when the button is clicked
+ */
+ test('should increase count by 1', () => {
+ // Arrange
+ const ButtonWithCount = () => {
+ const [count, setCount] = useState(0);
+ return (
+ <>
+
{count}
+
+