-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup base unit and integration testing functionality with Jest
- Loading branch information
1 parent
d3dcefd
commit e3a1464
Showing
16 changed files
with
2,995 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pnpm lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="@types/jest" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
|
||
interface ImageProps extends React.ImgHTMLAttributes<HTMLImageElement> { | ||
src: string; | ||
alt: string; | ||
} | ||
|
||
// Mock Next.js `Image` component using a standard `img` element | ||
const NextImage: React.FC<ImageProps> = ({ src, alt, ...props }) => { | ||
return <img src={src} alt={alt} {...props} />; | ||
}; | ||
|
||
export default NextImage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as React from 'react'; | ||
|
||
type LinkProps = React.AnchorHTMLAttributes<HTMLAnchorElement> & { | ||
href: string; | ||
}; | ||
|
||
// Mock Next.js `Link` component using a standard `a` element | ||
const Link: React.FC<LinkProps> = ({ href, children, ...props }) => { | ||
return ( | ||
<a data-testid='link-mock' href={href} {...props}> | ||
{children} | ||
</a> | ||
); | ||
}; | ||
|
||
export default Link; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Config } from 'jest'; | ||
import nextJest from 'next/jest'; | ||
|
||
const createJestConfig = nextJest({ | ||
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment | ||
dir: './', | ||
}); | ||
|
||
const config: Config = { | ||
// Automatically clear mock calls, instances, contexts and results before every test | ||
clearMocks: true, | ||
// Indicates whether the coverage information should be collected while executing the test | ||
collectCoverage: true, | ||
// The directory where Jest should output its coverage files | ||
coverageDirectory: 'coverage', | ||
// Indicates which provider should be used to instrument code for coverage | ||
coverageProvider: 'v8', | ||
// A list of paths to modules that run some code to configure or set up the testing framework before each test | ||
setupFilesAfterEnv: ['<rootDir>/src/testing/jest.setup.ts'], | ||
// The test environment that will be used for testing | ||
testEnvironment: 'jsdom', | ||
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module | ||
moduleNameMapper: { | ||
'^@/components/(.*)$': '<rootDir>/src/components/$1', | ||
}, | ||
}; | ||
|
||
export default createJestConfig(config); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const LINKEDIN_URL = 'https://www.linkedin.com/in/danielstals/'; | ||
|
||
export const CHAT_AVATAR_IMG_ALT = "Daniel's chat avatar"; | ||
|
||
export const PROMPT_TEMPLATE = ( | ||
question: string, | ||
chatHistory: string | undefined, | ||
context: string, | ||
) => `You are a friendly AI assistant augmented with an Upstash Vector Store. | ||
You impersonate the person in the profile. | ||
To help you answer the questions, a context and/or chat history will be provided. | ||
Answer the question at the end using only the information available in the context or chat history, either one is ok. | ||
Answer as completely as possible, and take special care in looking at the dates mentioned in the context. | ||
Whenever it makes sense, provide links to pages that contain more information about the topic from the given context. | ||
Format your messages in markdown format. | ||
------------- | ||
Chat history: | ||
${chatHistory} | ||
------------- | ||
Context: | ||
${context} | ||
------------- | ||
Question: ${question} | ||
Helpful answer:`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Learn more: https://github.com/testing-library/jest-dom | ||
import '@testing-library/jest-dom'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Centralised test utils and re-exports for flexibility and maintainability | ||
import { render as rtlRender } from '@testing-library/react'; | ||
|
||
export { rtlRender }; | ||
|
||
export * from '@testing-library/react'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { cn } from '../cn'; | ||
|
||
describe('cn', () => { | ||
it('should return an empty string when no arguments are provided', () => { | ||
const result = cn(); | ||
expect(result).toEqual(''); | ||
}); | ||
|
||
it('should concatenate multiple class names into a single string', () => { | ||
const result = cn('class1', 'class2', 'class3'); | ||
expect(result).toEqual('class1 class2 class3'); | ||
}); | ||
|
||
it('should ignore falsy values', () => { | ||
const result = cn('class1', null, undefined, 'class2', false, 'class3'); | ||
expect(result).toEqual('class1 class2 class3'); | ||
}); | ||
|
||
it('should handle arrays of class names', () => { | ||
const result = cn(['class1', 'class2'], ['class3', 'class4']); | ||
expect(result).toEqual('class1 class2 class3 class4'); | ||
}); | ||
|
||
it('should handle objects with class names as keys', () => { | ||
const result = cn({ class1: true, class2: false, class3: true }); | ||
expect(result).toEqual('class1 class3'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { getTimeDifferenceStrUntilUnixTimestamp } from '../format'; | ||
|
||
describe('getTimeDifferenceStrUntilUnixTimestamp', () => { | ||
it('should return the correct time difference string', () => { | ||
// Use a timestamp that represents a time difference of 1 day, 2 hours, 3 minutes, and 4 seconds from now | ||
const now = Date.now(); | ||
const oneDayInMs = 24 * 60 * 60 * 1000; | ||
const twoHoursInMs = 2 * 60 * 60 * 1000; | ||
const threeMinutesInMs = 3 * 60 * 1000; | ||
const fourSecondsInMs = 4 * 1000; | ||
const unixTimestamp = now + oneDayInMs + twoHoursInMs + threeMinutesInMs + fourSecondsInMs; | ||
|
||
const expected = 'Je kunt weer berichten sturen over 1 dagen, 2 uren, 3 minuten, 4 seconden'; | ||
|
||
const result = getTimeDifferenceStrUntilUnixTimestamp(unixTimestamp); | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('should adapt the time differene string when certain time units are 0', () => { | ||
// Use a timestamp that represents a time difference of 2 hours and 30 minutes from now | ||
const now = Date.now(); | ||
const twoHoursInMs = 2 * 60 * 60 * 1000; | ||
const thirtyMinutesInMs = 30 * 60 * 1000; | ||
const unixTimestamp = now + twoHoursInMs + thirtyMinutesInMs; | ||
|
||
const expected = 'Je kunt weer berichten sturen over 2 uren, 30 minuten'; | ||
|
||
const result = getTimeDifferenceStrUntilUnixTimestamp(unixTimestamp); | ||
|
||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('should return null when the time difference is 0', () => { | ||
// Use a timestamp that represents the current time | ||
const now = Date.now(); | ||
const unixTimestamp = now; | ||
|
||
const result = getTimeDifferenceStrUntilUnixTimestamp(unixTimestamp); | ||
|
||
expect(result).toEqual(null); | ||
}); | ||
|
||
it('should return null difference string when the timestamp is in the past', () => { | ||
// Use a timestamp that represents a time difference of 1 day, 2 hours, 3 minutes, and 4 seconds before now | ||
|
||
const now = Date.now(); | ||
const oneDayInMs = 24 * 60 * 60 * 1000; | ||
const twoHoursInMs = 2 * 60 * 60 * 1000; | ||
const threeMinutesInMs = 3 * 60 * 1000; | ||
const fourSecondsInMs = 4 * 1000; | ||
|
||
const unixTimestamp = now - oneDayInMs - twoHoursInMs - threeMinutesInMs - fourSecondsInMs; | ||
|
||
const result = getTimeDifferenceStrUntilUnixTimestamp(unixTimestamp); | ||
|
||
expect(result).toEqual(null); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters