Skip to content

Commit 0b5e2ff

Browse files
Merge branch 'dev' into PSL-update-dockeryml-file
2 parents 796c9b2 + 0ec2443 commit 0b5e2ff

41 files changed

Lines changed: 9477 additions & 1606 deletions

Some content is hidden

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

.github/workflows/docker-build-and-push.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,25 @@ jobs:
3636
username: ${{ secrets.ACR_DEV_USERNAME }}
3737
password: ${{ secrets.ACR_DEV_PASSWORD }}
3838

39-
- name: Set Docker image tag
40-
id: docker_tag
41-
run: |
42-
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
43-
echo "TAG=latest" >> $GITHUB_ENV
44-
elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then
45-
echo "TAG=dev" >> $GITHUB_ENV
46-
elif [[ "${{ github.ref }}" == "refs/heads/demo" ]]; then
47-
echo "TAG=demo" >> $GITHUB_ENV
48-
else
49-
echo "TAG=pullrequest-ignore" >> $GITHUB_ENV
50-
fi
51-
52-
- name: Build and push Docker image optionally
53-
run: |
54-
docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/webapp:${{ env.TAG }} -f WebApp.Dockerfile .
55-
if [[ "${{ env.TAG }}" == "latest" || "${{ env.TAG }}" == "dev" || "${{ env.TAG }}" == "demo" ]]; then
56-
docker push ${{ secrets.ACR_LOGIN_SERVER }}/webapp:${{ env.TAG }}
57-
else
58-
echo "Skipping Docker push for tag: ${{ env.TAG }}"
59-
fi
60-
39+
- name: Get current date
40+
id: date
41+
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
42+
43+
- name: Get registry
44+
id: registry
45+
run: echo "registry=${{ github.ref_name == 'main' && secrets.ACR_LOGIN_SERVER || secrets.ACR_DEV_LOGIN_SERVER }}" >> $GITHUB_OUTPUT
46+
47+
- name: Determine Tag Name Based on Branch
48+
id: determine_tag
49+
run: echo "tagname=${{ github.ref_name == 'main' && 'latest' || github.ref_name == 'dev' && 'dev' || github.ref_name == 'demo' && 'demo' || github.head_ref || 'default' }}" >> $GITHUB_OUTPUT
50+
51+
- name: Build Docker Image and optionally push
52+
uses: docker/build-push-action@v6
53+
with:
54+
context: .
55+
file: WebApp.Dockerfile
56+
push: ${{ github.ref_name == 'main' || github.ref_name == 'dev' || github.ref_name == 'demo' }}
57+
tags: |
58+
${{ steps.registry.outputs.registry }}/webapp:${{ steps.determine_tag.outputs.tagname }}
59+
${{ steps.registry.outputs.registry }}/webapp:${{ steps.determine_tag.outputs.tagname }}_${{ steps.date.outputs.date }}_${{ github.run_number }}
60+

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ __pycache__/
77
static
88
scripts/config.json
99
venv
10-
myenv
10+
myenv
11+
frontend/coverage

frontend/__mocks__/dompurify.ts

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

frontend/__mocks__/fileMock.ts

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;

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;

frontend/jest.config.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,55 @@ 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+
30+
collectCoverageFrom: ['src/**/*.{ts,tsx,js,jsx}'],
31+
coverageThreshold: {
32+
global: {
33+
branches: 80,
34+
functions: 80,
35+
lines: 80,
36+
statements: 80,
37+
},
38+
},
39+
40+
coveragePathIgnorePatterns: [
41+
'<rootDir>/node_modules/', // Ignore node_modules
42+
'<rootDir>/__mocks__/', // Ignore mocks
43+
'<rootDir>/src/state/',
44+
'<rootDir>/src/api/',
45+
'<rootDir>/src/mocks/',
46+
//'<rootDir>/src/test/',
47+
'<rootDir>/src/components/QuestionInput/index.ts',
48+
'<rootDir>/src/components/Answer/index.ts',
49+
'<rootDir>/src/pages/NoPage.tsx',
50+
'<rootDir>/src/index.tsx',
51+
'<rootDir>/src/vite-env.d.ts',
52+
'<rootDir>/src/helpers/'
53+
],
954
}
1055

1156
export default config

frontend/jest.polyfills.js

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+
})

0 commit comments

Comments
 (0)