Skip to content

Commit 82ee56b

Browse files
Merge pull request #107 from microsoft/psl-frontend-testcases
Client Advisor | Frontend test cases added
2 parents 3aaf46b + 16c8e6e commit 82ee56b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+6176
-649
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Unit Tests - Client Advisor
2+
3+
on:
4+
push:
5+
branches: [main, dev]
6+
# Trigger on changes in these specific paths
7+
paths:
8+
- 'ClientAdvisor/**'
9+
pull_request:
10+
branches: [main, dev]
11+
types:
12+
- opened
13+
- ready_for_review
14+
- reopened
15+
- synchronize
16+
paths:
17+
- 'ClientAdvisor/**'
18+
19+
jobs:
20+
test_client_advisor:
21+
22+
name: Client Advisor Tests
23+
runs-on: ubuntu-latest
24+
# The if condition ensures that this job only runs if changes are in the ClientAdvisor folder
25+
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Set up Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: "3.11"
32+
- name: Set up Node.js
33+
uses: actions/setup-node@v3
34+
with:
35+
node-version: '20'
36+
- name: Install Frontend Dependencies
37+
run: |
38+
cd ClientAdvisor/App/frontend
39+
npm install
40+
- name: Run Frontend Tests with Coverage
41+
run: |
42+
cd ClientAdvisor/App/frontend
43+
npm run test -- --coverage
44+
- uses: actions/upload-artifact@v4
45+
with:
46+
name: client-advisor-frontend-coverage
47+
path: |
48+
ClientAdvisor/App/frontend/coverage/
49+
ClientAdvisor/App/frontend/coverage/lcov-report/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const DOMPurify = {
2+
sanitize: jest.fn((input: string) => input), // Mock implementation that returns the input
3+
};
4+
5+
export default DOMPurify; // Use default export
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// __mocks__/fileMock.ts
2+
const fileMock = 'test-file-stub';
3+
4+
export default fileMock;

ClientAdvisor/App/frontend/__mocks__/mockAPIData.ts

Lines changed: 164 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// __mocks__/react-markdown.tsx
2+
3+
import React from 'react';
4+
5+
// Mock implementation of react-markdown
6+
const mockNode = {
7+
children: [{ value: 'console.log("Test Code");' }]
8+
};
9+
const mockProps = { className: 'language-javascript' };
10+
11+
const ReactMarkdown: React.FC<{ children: React.ReactNode , components: any }> = ({ children,components }) => {
12+
return <div data-testid="reactMockDown">
13+
{components && components.code({ node: mockNode, ...mockProps })}
14+
{children}</div>; // Simply render the children
15+
};
16+
17+
export default ReactMarkdown;

ClientAdvisor/App/frontend/jest.config.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,47 @@ import type { Config } from '@jest/types'
22

33
const config: Config.InitialOptions = {
44
verbose: true,
5+
6+
preset: 'ts-jest',
7+
//testEnvironment: 'jsdom', // For React DOM testing
8+
testEnvironment: 'jest-environment-jsdom',
9+
testEnvironmentOptions: {
10+
customExportConditions: ['']
11+
},
12+
moduleNameMapper: {
13+
'\\.(css|less|scss)$': 'identity-obj-proxy', // For mocking static file imports
14+
'^react-markdown$': '<rootDir>/__mocks__/react-markdown.tsx',
15+
'^dompurify$': '<rootDir>/__mocks__/dompurify.js', // Point to the mock
16+
'\\.(jpg|jpeg|png|gif|svg)$': '<rootDir>/__mocks__/fileMock.ts',
17+
18+
},
19+
setupFilesAfterEnv: ['<rootDir>/src/test/setupTests.ts'], // For setting up testing environment like jest-dom
520
transform: {
6-
'^.+\\.tsx?$': 'ts-jest'
21+
'^.+\\.ts(x)?$': 'ts-jest', // For TypeScript files
22+
'^.+\\.js$': 'babel-jest', // For JavaScript files if you have Babel
723
},
8-
setupFilesAfterEnv: ['<rootDir>/polyfills.js']
24+
25+
setupFiles: ['<rootDir>/jest.polyfills.js'],
26+
collectCoverage: true,
27+
//collectCoverageFrom: ['src/**/*.{ts,tsx}'], // Adjust the path as needed
28+
//coverageReporters: ['json', 'lcov', 'text', 'clover'],
29+
coverageThreshold: {
30+
global: {
31+
branches: 80,
32+
functions: 80,
33+
lines: 80,
34+
statements: 80,
35+
},
36+
},
37+
38+
coveragePathIgnorePatterns: [
39+
'<rootDir>/node_modules/', // Ignore node_modules
40+
'<rootDir>/__mocks__/', // Ignore mocks
41+
'<rootDir>/src/state/',
42+
'<rootDir>/src/api/',
43+
'<rootDir>/src/mocks/',
44+
//'<rootDir>/src/test/',
45+
],
946
}
1047

1148
export default config
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @note The block below contains polyfills for Node.js globals
3+
* required for Jest to function when running JSDOM tests.
4+
* These HAVE to be require's and HAVE to be in this exact
5+
* order, since "undici" depends on the "TextEncoder" global API.
6+
*
7+
* Consider migrating to a more modern test runner if
8+
* you don't want to deal with this.
9+
*/
10+
11+
const { TextDecoder, TextEncoder } = require('node:util')
12+
13+
Object.defineProperties(globalThis, {
14+
TextDecoder: { value: TextDecoder },
15+
TextEncoder: { value: TextEncoder },
16+
})
17+
18+
const { Blob } = require('node:buffer')
19+
const { fetch, Headers, FormData, Request, Response } = require('undici')
20+
21+
Object.defineProperties(globalThis, {
22+
fetch: { value: fetch, writable: true },
23+
Blob: { value: Blob },
24+
Headers: { value: Headers },
25+
FormData: { value: FormData },
26+
Request: { value: Request },
27+
Response: { value: Response },
28+
})

ClientAdvisor/App/frontend/src/api/models.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,7 @@ export interface ClientIdRequest {
140140
clientName: string;
141141
}
142142

143-
143+
export interface GroupedChatHistory {
144+
month: string
145+
entries: Conversation[]
146+
}

ClientAdvisor/App/frontend/src/components/Answer/Answer.module.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,10 @@ sup {
201201
margin-bottom: 5px;
202202
}
203203
}
204+
@media screen and (-ms-high-contrast: active), (forced-colors: active) {
205+
.answerContainer{
206+
border: 2px solid WindowText;
207+
background-color: Window;
208+
color: WindowText;
209+
}
210+
}

0 commit comments

Comments
 (0)