mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 19:29:15 +00:00
Fix all ui tests
This commit is contained in:
97
ui/build.mjs
97
ui/build.mjs
@@ -1,97 +0,0 @@
|
||||
import fs from 'fs-extra'
|
||||
import esbuild from 'esbuild'
|
||||
import babel from 'esbuild-plugin-babel'
|
||||
import browserSync from 'browser-sync'
|
||||
import historyApiFallback from 'connect-history-api-fallback'
|
||||
import dotenv from 'dotenv'
|
||||
import workboxBuild from 'workbox-build'
|
||||
|
||||
dotenv.config()
|
||||
const bs = browserSync.create()
|
||||
|
||||
const production = process.env.NODE_ENV == 'production'
|
||||
const watchMode = process.argv[2] == 'watch'
|
||||
|
||||
const ENVIRONMENT_VARIABLES = [
|
||||
'NODE_ENV',
|
||||
'PHOTOVIEW_API_ENDPOINT',
|
||||
'VERSION',
|
||||
'BUILD_DATE',
|
||||
'COMMIT_SHA',
|
||||
]
|
||||
|
||||
const defineEnv = ENVIRONMENT_VARIABLES.reduce((acc, key) => {
|
||||
acc[`process.env.${key}`] = process.env[key] ? `"${process.env[key]}"` : null
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
const esbuildOptions = {
|
||||
entryPoints: ['src/index.tsx', 'mapbox-gl/dist/mapbox-gl.css'],
|
||||
entryNames: '[name]',
|
||||
plugins: [
|
||||
babel({
|
||||
filter: /photoview\/ui\/src\/.*\.(js|tsx?)$/,
|
||||
}),
|
||||
],
|
||||
publicPath: process.env.UI_PUBLIC_URL || '/',
|
||||
outdir: 'dist',
|
||||
format: 'esm',
|
||||
bundle: true,
|
||||
platform: 'browser',
|
||||
splitting: true,
|
||||
minify: production,
|
||||
sourcemap: !production,
|
||||
loader: {
|
||||
'.js': 'jsx',
|
||||
'.svg': 'file',
|
||||
'.woff': 'file',
|
||||
'.woff2': 'file',
|
||||
'.ttf': 'file',
|
||||
'.eot': 'file',
|
||||
'.png': 'file',
|
||||
},
|
||||
define: defineEnv,
|
||||
incremental: watchMode,
|
||||
watch: {
|
||||
onRebuild(err) {
|
||||
if (err == null) {
|
||||
bs.reload()
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
fs.emptyDirSync('dist/')
|
||||
fs.copyFileSync('src/index.html', 'dist/index.html')
|
||||
fs.copyFileSync('src/manifest.webmanifest', 'dist/manifest.json')
|
||||
fs.copyFileSync('src/favicon.ico', 'dist/favicon.ico')
|
||||
fs.copySync('src/assets/', 'dist/assets/')
|
||||
|
||||
if (watchMode) {
|
||||
esbuild.build(esbuildOptions)
|
||||
|
||||
bs.init({
|
||||
server: {
|
||||
baseDir: './dist',
|
||||
middleware: [historyApiFallback()],
|
||||
},
|
||||
port: 1234,
|
||||
open: false,
|
||||
})
|
||||
} else {
|
||||
const build = async () => {
|
||||
await esbuild.build(esbuildOptions)
|
||||
|
||||
console.log('esbuild done')
|
||||
|
||||
await workboxBuild.generateSW({
|
||||
globDirectory: 'dist/',
|
||||
globPatterns: ['**/*.{png,svg,woff2,ttf,eot,woff,js,ico,html,json,css}'],
|
||||
swDest: 'dist/service-worker.js',
|
||||
})
|
||||
|
||||
console.log('workbox done')
|
||||
console.log('build complete')
|
||||
}
|
||||
build()
|
||||
}
|
||||
@@ -43,7 +43,7 @@
|
||||
"url-join": "^4.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "craco start",
|
||||
"start": "BROWSER=none craco start",
|
||||
"build": "craco build",
|
||||
"test": "npm run lint && npm run jest -- --watchAll=false",
|
||||
"test:ci": "npm run lint && npm run jest:ci",
|
||||
|
||||
@@ -65,7 +65,7 @@ const RECOGNIZE_UNLABELED_FACES_MUTATION = gql`
|
||||
}
|
||||
`
|
||||
|
||||
const FaceDetailsButton = styled.button<{ labeled: boolean }>`
|
||||
const FaceDetailsWrapper = styled.div<{ labeled: boolean }>`
|
||||
color: ${({ labeled }) => (labeled ? 'black' : '#aaa')};
|
||||
width: 150px;
|
||||
margin: 12px auto 24px;
|
||||
@@ -81,8 +81,6 @@ const FaceDetailsButton = styled.button<{ labeled: boolean }>`
|
||||
}
|
||||
`
|
||||
|
||||
const FaceLabel = styled.span``
|
||||
|
||||
type FaceDetailsProps = {
|
||||
group: myFaces_myFaceGroups
|
||||
}
|
||||
@@ -127,20 +125,20 @@ export const FaceDetails = ({ group }: FaceDetailsProps) => {
|
||||
let label
|
||||
if (!editLabel) {
|
||||
label = (
|
||||
<FaceDetailsButton
|
||||
<FaceDetailsWrapper
|
||||
labeled={!!group.label}
|
||||
onClick={() => setEditLabel(true)}
|
||||
>
|
||||
<FaceImagesCount>{group.imageFaceCount}</FaceImagesCount>
|
||||
<FaceLabel>
|
||||
<button>
|
||||
{group.label ?? t('people_page.face_group.unlabeled', 'Unlabeled')}
|
||||
</FaceLabel>
|
||||
</button>
|
||||
{/* <EditIcon name="pencil" /> */}
|
||||
</FaceDetailsButton>
|
||||
</FaceDetailsWrapper>
|
||||
)
|
||||
} else {
|
||||
label = (
|
||||
<FaceDetailsButton labeled={!!group.label}>
|
||||
<FaceDetailsWrapper labeled={!!group.label}>
|
||||
<TextField
|
||||
className="w-[160px]"
|
||||
loading={loading}
|
||||
@@ -163,7 +161,7 @@ export const FaceDetails = ({ group }: FaceDetailsProps) => {
|
||||
resetLabel()
|
||||
}}
|
||||
/>
|
||||
</FaceDetailsButton>
|
||||
</FaceDetailsWrapper>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -93,9 +93,9 @@ test('single face group', async () => {
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByText('Loading media')).not.toHaveClass('active')
|
||||
// expect(screen.queryByText('Loading more media')).not.toHaveClass('active')
|
||||
expect(screen.queryByText('Face Group Name')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(screen.getByText('Face Group Name')).toBeInTheDocument()
|
||||
expect(screen.getAllByRole('img')).toHaveLength(2)
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ import React from 'react'
|
||||
import PresentNavigationOverlay from './PresentNavigationOverlay'
|
||||
import { fireEvent, render, screen, act } from '@testing-library/react'
|
||||
|
||||
jest.useFakeTimers()
|
||||
jest.useFakeTimers('modern')
|
||||
|
||||
describe('PresentNavigationOverlay component', () => {
|
||||
test('simple render', () => {
|
||||
@@ -44,6 +44,7 @@ describe('PresentNavigationOverlay component', () => {
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(3000)
|
||||
})
|
||||
|
||||
expect(screen.getByLabelText('Next image')).toHaveClass('hide')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -10,14 +10,14 @@ import {
|
||||
} from '@testing-library/react'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
|
||||
jest.mock('../../Pages/LoginPage/LoginPage.tsx', () => () => (
|
||||
<div>mocked login page</div>
|
||||
))
|
||||
|
||||
require('../../localization').setupLocalization()
|
||||
|
||||
describe('routes', () => {
|
||||
test('unauthorized root path should navigate to login page', async () => {
|
||||
jest.mock('../../Pages/LoginPage/LoginPage.tsx', () => () => (
|
||||
<div>mocked login page</div>
|
||||
))
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/']}>
|
||||
<Routes />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export default jest.fn(() => ({
|
||||
export default () => ({
|
||||
finished: true,
|
||||
containerElem: jest.fn(),
|
||||
}))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user