-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #136 from miksrv/develop
Migrate to next.js 15, added UI Unit tests
- Loading branch information
Showing
16 changed files
with
8,681 additions
and
695 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
Binary file not shown.
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
npmRegistryServer: https://registry.npmjs.org | ||
|
||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-4.5.0.cjs |
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,43 @@ | ||
import React from 'react' | ||
|
||
import '@testing-library/jest-dom' | ||
|
||
import Footer from './Footer' | ||
|
||
import { formatDate } from '@/tools/date' | ||
import { render, screen } from '@testing-library/react' | ||
|
||
jest.mock('@/package.json', () => ({ | ||
name: 'TestApp', | ||
version: '1.0.0' | ||
})) | ||
|
||
jest.mock('@/tools/date', () => ({ | ||
formatDate: jest.fn() | ||
})) | ||
|
||
jest.mock('@/update', () => new Date(2023, 0, 1, 12, 0, 0)) // 1 января 2023 года, 12:00 | ||
|
||
describe('Footer Component', () => { | ||
it('displays the correct copyright information', () => { | ||
;(formatDate as jest.Mock).mockImplementation((date, format) => | ||
format === 'YYYY' ? '2023' : '01.01.2023, 12:00' | ||
) | ||
|
||
render(<Footer />) | ||
|
||
expect(screen.getByText('Copyright © TestApp 2023')).toBeInTheDocument() | ||
}) | ||
|
||
it('displays the correct version information', () => { | ||
;(formatDate as jest.Mock).mockImplementation((date, format) => | ||
format === 'DD.MM.YYYY, HH:mm' ? '01.01.2023, 12:00' : '2023' | ||
) | ||
|
||
render(<Footer />) | ||
|
||
expect(screen.getByText('Version')).toBeInTheDocument() | ||
expect(screen.getByText('1.0.0')).toBeInTheDocument() | ||
expect(screen.getByText('(01.01.2023, 12:00)')).toBeInTheDocument() | ||
}) | ||
}) |
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
36 changes: 36 additions & 0 deletions
36
client/components/wind-direction-icon/WindDirectionIcon.test.tsx
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,36 @@ | ||
import React from 'react' | ||
|
||
import '@testing-library/jest-dom' | ||
|
||
import styles from './styles.module.sass' | ||
import WindDirectionIcon from './WindDirectionIcon' | ||
|
||
import { render } from '@testing-library/react' | ||
|
||
describe('WindDirectionIcon Component', () => { | ||
it('renders SVG element with correct viewBox attribute', () => { | ||
const { container } = render(<WindDirectionIcon />) | ||
const svgElement = container.querySelector('svg') | ||
expect(svgElement).toBeInTheDocument() | ||
expect(svgElement).toHaveAttribute('viewBox', '0 0 30 30') | ||
}) | ||
|
||
it('applies default rotation when direction is not provided', () => { | ||
const { container } = render(<WindDirectionIcon />) | ||
const svgElement = container.querySelector('svg') | ||
expect(svgElement).toHaveStyle('transform: rotate(0deg)') | ||
}) | ||
|
||
it('applies correct rotation based on direction prop', () => { | ||
const testDirection = 45 | ||
const { container } = render(<WindDirectionIcon direction={testDirection} />) | ||
const svgElement = container.querySelector('svg') | ||
expect(svgElement).toHaveStyle(`transform: rotate(${testDirection}deg)`) | ||
}) | ||
|
||
it('applies correct CSS class for styling', () => { | ||
const { container } = render(<WindDirectionIcon />) | ||
const svgElement = container.querySelector('svg') | ||
expect(svgElement).toHaveClass(styles.weatherIcon) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,47 +1,25 @@ | ||
import type { Config } from '@jest/types' | ||
import type { Config } from 'jest' | ||
|
||
const config: Config.InitialOptions = { | ||
collectCoverage: true, | ||
collectCoverageFrom: [ | ||
'**/*.{js,jsx,ts,tsx}', | ||
'!**/*.d.ts', | ||
'!**/node_modules/**', | ||
'!<rootDir>/out/**', | ||
'!<rootDir>/.next/**', | ||
'!<rootDir>/*.config.js', | ||
'!<rootDir>/coverage/**' | ||
], | ||
coverageProvider: 'v8', | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: 'tsconfig.node.json' | ||
} | ||
}, | ||
const config: Config = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'jsdom', | ||
moduleNameMapper: { | ||
'^.+\\.(png|jpg|jpeg|gif|webp|avif|ico|bmp|svg)$': 'identity-obj-proxy', | ||
|
||
// Handle CSS imports (with CSS modules) | ||
// https://jestjs.io/docs/webpack#mocking-css-modules | ||
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy', | ||
|
||
// Handle module aliases | ||
'^@/(.*)$': '<rootDir>/$1', | ||
'^@/api/(.*)$': '<rootDir>/api/$1', | ||
'^@/components/(.*)$': '<rootDir>/components/$1', | ||
'^@/functions/(.*)$': '<rootDir>/functions/$1', | ||
'^@/public/(.*)$': '<rootDir>/public/$1', | ||
'^@/styles/(.*)$': '<rootDir>/styles/$1' | ||
'\\.(css|sass|scss)$': 'identity-obj-proxy', | ||
'\\.(jpg|jpeg|png)$': 'identity-obj-proxy', | ||
'^@/(.*)$': '<rootDir>/$1' | ||
}, | ||
setupFilesAfterEnv: ['<rootDir>/setupTests.config.tsx'], | ||
silent: true, // hide all warnings | ||
testEnvironment: 'jsdom', | ||
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'], | ||
transform: { | ||
// Use babel-jest to transpile tests with the next/babel preset | ||
// https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object | ||
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }] | ||
'^.+\\.tsx?$': [ | ||
'ts-jest', | ||
{ | ||
babel: true, | ||
tsconfig: 'tsconfig.jest.json' | ||
} | ||
] | ||
}, | ||
transformIgnorePatterns: ['/node_modules/', '^.+\\.module\\.(css|sass|scss)$'] | ||
collectCoverageFrom: ['components/**/*.{ts,tsx}', '!components/**/*.d.ts', '!components/**/*.test.tsx', '!*.d.ts'], | ||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], | ||
transformIgnorePatterns: ['node_modules/(?!(module-to-transform)/)', '/.next/'] | ||
} | ||
|
||
export default 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
Oops, something went wrong.