aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jest.config.ts9
-rw-r--r--package.json12
-rw-r--r--tests/base.test.ts3
-rw-r--r--tests/models/ProfileQuestion.test.tsx80
-rw-r--r--tsconfig.json2
5 files changed, 103 insertions, 3 deletions
diff --git a/jest.config.ts b/jest.config.ts
index b477474..282bda6 100644
--- a/jest.config.ts
+++ b/jest.config.ts
@@ -7,7 +7,16 @@
export default {
preset: 'ts-jest',
testEnvironment: 'jsdom',
+ // setupFilesAfterEnv: ['./setupTests.ts'],
+ globals: {
+ "ts-jest": {
+ "tsConfig": "./tsconfig.build.json"
+ }
+ },
moduleNameMapper: {
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
+ '^@/(.*)$': '<rootDir>/src/$1',
+
},
+
}; \ No newline at end of file
diff --git a/package.json b/package.json
index 8b704ab..dd0468f 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,8 @@
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
- "preview": "vite preview"
+ "preview": "vite preview",
+ "test": "jest"
},
"dependencies": {
"@emotion/react": "^11.14.0",
@@ -52,7 +53,6 @@
"date-fns": "^3.6.0",
"embla-carousel-react": "^8.6.0",
"input-otp": "^1.4.2",
- "jest": "^29.7.0",
"lucide-react": "^0.503.0",
"motion": "^12.12.1",
"next-themes": "^0.4.6",
@@ -75,6 +75,10 @@
"devDependencies": {
"@eslint/js": "^9.17.0",
"@tailwindcss/postcss": "^4.1.10",
+ "@testing-library/dom": "^10.4.0",
+ "@testing-library/jest-dom": "^6.6.3",
+ "@testing-library/react": "^16.3.0",
+ "@types/jest": "^30.0.0",
"@types/node": "^22.14.1",
"@types/react": "^18.3.20",
"@types/react-dom": "^18.3.6",
@@ -86,9 +90,13 @@
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-refresh": "^0.4.20",
"globals": "^15.15.0",
+ "jest": "^29.7.0",
+ "jest-environment-jsdom": "^29.7.0",
"postcss": "^8.5.6",
"tailwindcss": "^4.1.10",
"terser": "^5.43.1",
+ "ts-jest": "^29.4.0",
+ "ts-node": "^10.9.2",
"typescript": "~5.6.2",
"typescript-eslint": "^8.31.0",
"vite": "^6.3.2",
diff --git a/tests/base.test.ts b/tests/base.test.ts
new file mode 100644
index 0000000..e2f56a6
--- /dev/null
+++ b/tests/base.test.ts
@@ -0,0 +1,3 @@
+test('1 + 1 equals 2', () => {
+ expect(1 + 1).toBe(2);
+}); \ No newline at end of file
diff --git a/tests/models/ProfileQuestion.test.tsx b/tests/models/ProfileQuestion.test.tsx
new file mode 100644
index 0000000..cc825eb
--- /dev/null
+++ b/tests/models/ProfileQuestion.test.tsx
@@ -0,0 +1,80 @@
+import {render, screen,} from '@testing-library/react';
+import {describe, it} from '@jest/globals';
+import {ProfileQuestionFull} from "@/pages/Questions"
+import '@testing-library/jest-dom'; // needed for .toBeInTheDocument()
+import {ProfileQuestion} from "@/models/questionSlice";
+import {Provider} from "react-redux";
+import {store} from "@/store";
+import {App} from "@/models/app";
+import {setApp} from "@/models/appSlice.ts";
+import '@testing-library/jest-dom';
+
+const q: ProfileQuestion = {
+ "question_id": "0471eb56de8247cda7468e473bab87f2",
+ "ext_question_id": "rd:105019",
+ "question_type": "MC",
+ "country_iso": "us",
+ "language_iso": "eng",
+ "question_text": "Which of the following is your primary bank? ",
+ "choices": [
+ {
+ "choice_id": "1",
+ "choice_text": "Ally Bank",
+ "order": 0,
+ "exclusive": false
+ },
+ {
+ "choice_id": "2",
+ "choice_text": "Bank of America",
+ "order": 1,
+ "exclusive": false
+ },
+ {
+ "choice_id": "27",
+ "choice_text": "BB&T",
+ "order": 2,
+ "exclusive": false
+ },
+ ],
+ "selector": "SA",
+ "importance": {
+ "task_count": 3,
+ "task_score": 0.006180190564957855,
+ "marketplace_task_count": {
+ "rd": 3
+ }
+ },
+ "categories": [],
+ "task_count": 3,
+ "task_score": 0.006180190564957855,
+ "marketplace_task_count": {
+ "rd": 3
+ },
+ "active": true
+} as ProfileQuestion
+
+// GRL Snippet configuration options
+// const settings: App = {
+// targetId: 'grl-widget',
+// bpid: "invalid-bpid-from-snippet",
+// bpuid: "invalid-bpuid-from-snippet",
+// offerwall: "37d1da64",
+// walletMode: true,
+// panelName: null,
+// leaderboard: false,
+// currentPage: "offerwall"
+// } as App
+// store.dispatch(setApp(settings))
+
+describe('ProfileQuestionFull', () => {
+
+ it('renders the correct title', () => {
+ render(
+ <Provider store={store}>
+ <ProfileQuestionFull question={q} submitAnswerEvt={() => {}}/>
+ </Provider>
+ );
+ const element = screen.getByText(/Which of the following is your primary bank/i);
+ expect(element).toBeInTheDocument();
+ });
+}); \ No newline at end of file
diff --git a/tsconfig.json b/tsconfig.json
index bdddda8..fb0f824 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -19,7 +19,7 @@
"baseUrl": ".",
"paths": {
"@/*": [
- "./src/*"
+ "src/*", "tests/*"
]
}
}