Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: UI - Unit test cases for OptionsPanel #20

Open
wants to merge 70 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
ab82c41
UI - Jest setup and required packages installed
Bangarraju-Microsoft Nov 11, 2024
b4d1806
added templframe test file
Nov 12, 2024
c8e3716
made edits
Nov 12, 2024
c2114b8
Unit test Task9877
UtkarshMishra-Microsoft Nov 19, 2024
3cc9073
added tableTab test file
Nov 20, 2024
6a7d40c
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Nov 20, 2024
452f5f4
Ravi_dkm_unit_testcases
RaviKiran-Microsoft Nov 20, 2024
f572f6f
Added pageNumberTab test file
Nov 21, 2024
ba80e23
Ravi_dkm_unit_testcase_orderBy
RaviKiran-Microsoft Nov 22, 2024
de1bb56
Added PagesTab Test file.
Kamini-Microsoft Nov 22, 2024
c08d8fe
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Kamini-Microsoft Nov 22, 2024
4724599
dialogoConfirm Test case file added.
Kamini-Microsoft Nov 28, 2024
a6f548f
task 9879 is completed dateFilterDropdownMenu
Nov 29, 2024
4de17e2
imageCarousel and meta data table test files added
Dec 2, 2024
89189b6
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Dec 2, 2024
a11311e
Deleted Coverage Folder and Chages in JestConfig
Bangarraju-Microsoft Dec 2, 2024
578a3f8
ChatRoom.test unit test cases
Dec 3, 2024
9e5c3e6
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Dec 3, 2024
ea27fb7
reverted tsConfig Changes and removed un used file and added test sui…
Bangarraju-Microsoft Dec 3, 2024
1fb5594
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Bangarraju-Microsoft Dec 3, 2024
c672d15
Unit test cases for chatRoom, sidecar,snackbarError,snackbarSuccess
Dec 3, 2024
be440fd
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Dec 3, 2024
b4220c6
Unit test cases for snackbar unit test cases
Dec 3, 2024
a2e1c89
Unit test cases for chatRoom
Dec 4, 2024
ada8e07
add SearchResultCardtest
Dec 5, 2024
3c157b9
Added aiKnowledgeTab component test file.
Kamini-Microsoft Dec 5, 2024
b787560
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Kamini-Microsoft Dec 5, 2024
d533a2d
Added test cases for chatRoom and sideCar
Dec 6, 2024
ea83d60
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Dec 6, 2024
eaa5f0d
Added dialogContentComponent test file.
Kamini-Microsoft Dec 6, 2024
29d444f
remove console
Bangarraju-Microsoft Dec 6, 2024
69bea99
customDatePicker
UtkarshMishra-Microsoft Dec 6, 2024
b23f229
iframe pagination documnet viewer
Dec 6, 2024
f9f5ea1
iframe pagination documnet viewer
Dec 6, 2024
96af209
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Bangarraju-Microsoft Dec 6, 2024
a467276
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Dec 6, 2024
bea4f34
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Bangarraju-Microsoft Dec 6, 2024
b0c5cbe
removed unwanted files from coverage
Bangarraju-Microsoft Dec 6, 2024
d27a307
added ChatPage test file
Dec 6, 2024
93fb05c
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Dec 6, 2024
6bd8317
removed merge coflict issues
Bangarraju-Microsoft Dec 6, 2024
5fad682
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Bangarraju-Microsoft Dec 6, 2024
ad2101d
chatRoom test cases
Dec 6, 2024
023c71a
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Dec 6, 2024
bb9f5e6
chatRoom test cases
Dec 6, 2024
5c57eba
UT - DialogContentComponent, Footer and jest config changes
Bangarraju-Microsoft Dec 9, 2024
26543db
Dompurify - Dependencey added
Bangarraju-Microsoft Dec 9, 2024
e395af8
Ravi_dkm_unit_testcases_HeaderMenuTabs
RaviKiran-Microsoft Dec 9, 2024
565dbd7
dialogTitleBartest
UtkarshMishra-Microsoft Dec 10, 2024
896e93c
iframecomponent
Dec 10, 2024
f537b90
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Pradheep-Microsoft Dec 10, 2024
f3df25a
dialogTitleBartest
UtkarshMishra-Microsoft Dec 10, 2024
e5ffd08
dialogTitleBartest
UtkarshMishra-Microsoft Dec 10, 2024
3d97aa8
removed coverage folder
Bangarraju-Microsoft Dec 16, 2024
c35019b
added coverage folder in gitignore
Bangarraju-Microsoft Dec 16, 2024
772ce5a
UT - import.meta issue fixed
Bangarraju-Microsoft Dec 17, 2024
2e58bfd
UT - Window.ENV.AI_KNOWLEDGE_FIELDS issue fixed
Bangarraju-Microsoft Dec 17, 2024
e6a9390
Feedback DocViewer Pagination Searchbox
Pradheep-Microsoft Dec 20, 2024
242c9de
UT - ChatRoom unit test cases
Bangarraju-Microsoft Dec 20, 2024
15efad2
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Bangarraju-Microsoft Dec 20, 2024
74239c1
Unit test case searchbox docviewer feebbackform
Pradheep-Microsoft Dec 20, 2024
7670668
Merge branch 'PSL-US-9859-UT' of https://github.com/microsoft/Documen…
Pradheep-Microsoft Dec 20, 2024
182479b
searchbox
Pradheep-Microsoft Dec 23, 2024
3824f85
documentViewer
Pradheep-Microsoft Dec 23, 2024
2eb50d7
searchBox source file update
Pradheep-Microsoft Dec 23, 2024
d303ea9
documentviewer
Pradheep-Microsoft Dec 26, 2024
d81adc6
filter-test
UtkarshMishra-Microsoft Dec 31, 2024
903a44f
sidecar-test
UtkarshMishra-Microsoft Jan 2, 2025
3244f2e
FeedbackForm-Test
UtkarshMishra-Microsoft Jan 2, 2025
e1ee3a0
SearchBox-test
UtkarshMishra-Microsoft Jan 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion App/frontend-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ dist-ssr
*.sw?

buildandpush_dpsfronapp.ps1
rollout.ps1
rollout.ps1
coverage
5 changes: 5 additions & 0 deletions App/frontend-app/__mocks__/dompurify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const DOMPurify = {
sanitize: jest.fn((input: string) => input), // Mock implementation that returns the input
};

export default DOMPurify; // Use default export
4 changes: 4 additions & 0 deletions App/frontend-app/__mocks__/fileMock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// __mocks__/fileMock.ts
const fileMock = 'test-file-stub';

export default fileMock;
19 changes: 19 additions & 0 deletions App/frontend-app/__mocks__/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { initReactI18next } from "react-i18next";

const i18nMock = {
createInstance: () => ({
use: () => i18nMock,
init: (config: Record<string, any>) => {
// Simulate a no-op init method
},
t: (key: string, options?: Record<string, any>) => {
// Return a mock translation string with interpolation handling
if (options?.year) {
return `© ${options.year}`;
}
return key;
},
}),
};

export default i18nMock;
17 changes: 17 additions & 0 deletions App/frontend-app/__mocks__/react-markdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// __mocks__/react-markdown.tsx

import React from 'react';

// Mock implementation of react-markdown
const mockNode = {
children: [{ value: 'console.log("Test Code");' }]
};
const mockProps = { className: 'language-javascript' };

const ReactMarkdown: React.FC<{ children: React.ReactNode , components: any }> = ({ children,components }) => {
return <div data-testid="reactMockDown">
{components && components.code({ node: mockNode, ...mockProps })}
{children}</div>; // Simply render the children
};

export default ReactMarkdown;
106 changes: 75 additions & 31 deletions App/frontend-app/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,77 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "jsdom",
setupFilesAfterEnv: ["<rootDir>/jest-setup.ts"],
// Test all files either suffixed with "-test.js", "-test.jsx", "-test.ts", "-test.tsx", or
// having ".test.js", ".test.jsx", ".test.ts", ".test.tsx" extensions
testRegex: ".*[-.]test\\.(js|ts)x?$",

// Generate coverage reports in textm HTML, lcov and clover format
coverageReporters: ["text", "html", "lcov", "clover"],

// Use the default
reporters: ["default"],

// Postprocess test result to create a Bamboo format compatible report
// testResultsProcessor: "jest-bamboo-reporter",

moduleNameMapper: {
// Alias @/ imports
"@/(.*)": "<rootDir>/src/$1",
// Alias #/ imports
"#/(.*)": "<rootDir>/test/$1",
// SCSS files
"\\.scss$": "identity-obj-proxy",
import type { Config } from '@jest/types'

const config: Config.InitialOptions = {
verbose: true,

preset: 'ts-jest',
//testEnvironment: 'jsdom', // For React DOM testing
testEnvironment: 'jest-environment-jsdom',
testEnvironmentOptions: {
customExportConditions: ['']
},
moduleNameMapper: {
'\\.(css|less|scss)$': 'identity-obj-proxy', // For mocking static file imports
'^react-markdown$': '<rootDir>/__mocks__/react-markdown.tsx',
'^dompurify$': '<rootDir>/__mocks__/dompurify.js', // Point to the mock
'\\.(jpg|jpeg|png|gif|svg)$': '<rootDir>/__mocks__/fileMock.ts',
"^i18next$": "<rootDir>/__mocks__/i18n.ts",

},
setupFilesAfterEnv: ['<rootDir>/src/test/setupTests.ts'], // For setting up testing environment like jest-dom
transform: {
'^.+\\.ts(x)?$': ['ts-jest',
{
diagnostics: {
ignoreCodes: [1343]
},
astTransformers: {
before: [
{
path: 'node_modules/ts-jest-mock-import-meta', // or, alternatively, 'ts-jest-mock-import-meta' directly, without node_modules.
options: { metaObjectReplacement: { env : { 'VITE_API_ENDPOINT' : 'https://mock-api-endpoint.com' }} }
}
]
}
}

], // For TypeScript files
'^.+\\.js$': 'babel-jest', // For JavaScript files if you have Babel
},

setupFiles: ['<rootDir>/jest.polyfills.js'],
collectCoverage: true,
collectCoverageFrom: ['src/**/*.{ts,tsx}'], // Adjust the path as needed
//coverageReporters: ['json', 'lcov', 'text', 'clover'],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},

coveragePathIgnorePatterns: [
'<rootDir>/node_modules/', // Ignore node_modules
'<rootDir>/__mocks__/', // Ignore mocks
'<rootDir>/src/state/',
'<rootDir>/src/api/',
'<rootDir>/src/mocks/',
'<rootDir>/src/test/',
'<rootDir>/src/assets/',
'<rootDir>/src/utils/',
'<rootDir>/src/types/',

'<rootDir>/src/App.tsx',
'<rootDir>/src/AppContext.tsx',
'<rootDir>/src/AppRoutes.tsx',
'<rootDir>/src/main.tsx',
'<rootDir>/src/styles.tsx',
'<rootDir>/src/vite-env.d.ts',
'<rootDir>/src/components/uploadButton/uploadButton2.tsx',
'<rootDir>/src/components/searchResult/old.tsx',
'<rootDir>/src/components/chat/modelSwitch.tsx',
],
}

// Project's path which coverage will be reported
collectCoverageFrom: ["src/**/*.ts", "src/**/*.tsx"],
coveragePathIgnorePatterns: [],
modulePathIgnorePatterns: [],
testPathIgnorePatterns: [],
};
export default config
28 changes: 28 additions & 0 deletions App/frontend-app/jest.polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @note The block below contains polyfills for Node.js globals
* required for Jest to function when running JSDOM tests.
* These HAVE to be require's and HAVE to be in this exact
* order, since "undici" depends on the "TextEncoder" global API.
*
* Consider migrating to a more modern test runner if
* you don't want to deal with this.
*/

const { TextDecoder, TextEncoder } = require('node:util')

Object.defineProperties(globalThis, {
TextDecoder: { value: TextDecoder },
TextEncoder: { value: TextEncoder },
})

const { Blob } = require('node:buffer')
const { fetch, Headers, FormData, Request, Response } = require('undici')

Object.defineProperties(globalThis, {
fetch: { value: fetch, writable: true },
Blob: { value: Blob },
Headers: { value: Headers },
FormData: { value: FormData },
Request: { value: Request },
Response: { value: Response },
})
Loading
Loading