Skip to content

Commit 7f231a2

Browse files
authored
fix(tag): 修订样式 (#3425)
* fix(tag): 修订样式 * fix(test): 修订单测 * fix(tag): 改用原样式变量 * fix: 修改github test异常 * fix(test): 修订单测
1 parent 06fac0e commit 7f231a2

9 files changed

Lines changed: 321 additions & 291 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
"@typescript-eslint/eslint-plugin": "^7.0.2",
164164
"@typescript-eslint/parser": "^7.0.2",
165165
"@vitejs/plugin-react": "^4.2.1",
166-
"@vitest/coverage-v8": "^2.0.4",
166+
"@vitest/coverage-v8": "^3.0.7",
167167
"@vitest/ui": "^2.0.4",
168168
"autoprefixer": "^10.4.17",
169169
"axios": "^1.6.7",

pnpm-lock.yaml

Lines changed: 257 additions & 231 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/packages/address/__test__/__snapshots__/address.spec.tsx.snap

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

src/packages/cell/__test__/__snapshots__/cell.spec.tsx.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ exports[`slot extra 1`] = `
9999
class="nut-cell-extra"
100100
>
101101
<div
102+
aria-checked="true"
103+
aria-disabled="false"
102104
class="nut-switch"
105+
role="switch"
106+
tabindex="0"
103107
>
104108
<div
105109
class="nut-switch-button nut-switch-button-open"

src/packages/checkbox/__test__/__snapshots__/checkbox.spec.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`should match snapshot 1`] = `
44
<DocumentFragment>
55
<div
6-
class="nut-checkbox nut-checkbox-reverse"
6+
class="nut-checkbox nut-checkbox-reverse nut-checkbox-active"
77
>
88
<div
99
class="nut-checkbox-icon-wrap"

src/packages/skeleton/__test__/__snapshots__/skeleton.spec.tsx.snap

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/packages/tag/tag.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131

3232
&-primary {
33-
background: #fa2c19;
33+
background: $tag-primary-background-color;
3434
}
3535

3636
&-info {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`timeselect props test 1`] = `"<div><div class="nut-overlay" style="z-index: 1000;"></div><div style="z-index: 1000;" class="nut-popup nut-popup-round nut-popup-bottom"><div class="nut-popup-title"><div class="nut-popup-title-wrapper"><div class="nut-popup-title-title">取件时间</div></div><div class="nut-popup-title-right nut-popup-title-right-top-right"><svg class="nut-icon nut-icon-Close " xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" aria-labelledby="Close" role="presentation"><path d="M512 557.23 783.57 828.8c8.32 8.32 21.76 8.32 30.3 0l14.93-14.93c8.32-8.32 8.32-21.76 0-30.3L557.23 512 828.8 240.43c8.32-8.32 8.32-21.76 0-30.3l-14.93-14.93c-8.32-8.32-21.76-8.32-30.3 0L512 466.77 240.43 195.2c-8.32-8.32-21.76-8.32-30.3 0l-14.93 14.93c-8.32 8.32-8.32 21.76 0 30.3L466.77 512 195.2 783.57c-8.32 8.32-8.32 21.76 0 30.3l14.93 14.93c8.32 8.32 21.76 8.32 30.3 0z" fill="currentColor"></path></svg></div></div><div class="nut-timeselect"><div class="nut-timeselect-content"><div class="nut-timeselect-content-left"><div class="nut-timepannel active">520</div><div class="nut-timepannel">521</div></div><div class="nut-timedetail"><span class="nut-timedetail-item">09:00-10:00</span><span class="nut-timedetail-item">10:00-11:00</span><span class="nut-timedetail-item">11:00-12:00</span></div></div></div></div></div>"`;
3+
exports[`timeselect props test 1`] = `"<div><div class="nut-overlay" style="z-index: 1000;"></div><div style="z-index: 1000;" class="nut-popup nut-popup-round nut-popup-bottom"><div class="nut-popup-title"><div class="nut-popup-title-wrapper"><div class="nut-popup-title-title">取件时间</div></div><div class="nut-popup-title-right nut-popup-title-right-top-right" role="button" aria-label="关闭" tabindex="-1"><svg class="nut-icon nut-icon-Close " xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" aria-labelledby="Close" role="presentation"><path d="M512 557.23 783.57 828.8c8.32 8.32 21.76 8.32 30.3 0l14.93-14.93c8.32-8.32 8.32-21.76 0-30.3L557.23 512 828.8 240.43c8.32-8.32 8.32-21.76 0-30.3l-14.93-14.93c-8.32-8.32-21.76-8.32-30.3 0L512 466.77 240.43 195.2c-8.32-8.32-21.76-8.32-30.3 0l-14.93 14.93c-8.32 8.32-8.32 21.76 0 30.3L466.77 512 195.2 783.57c-8.32 8.32-8.32 21.76 0 30.3l14.93 14.93c8.32 8.32 21.76 8.32 30.3 0z" fill="currentColor"></path></svg></div></div><div class="nut-timeselect"><div class="nut-timeselect-content"><div class="nut-timeselect-content-left"><div class="nut-timepannel active">520</div><div class="nut-timepannel">521</div></div><div class="nut-timedetail"><span class="nut-timedetail-item">09:00-10:00</span><span class="nut-timedetail-item">10:00-11:00</span><span class="nut-timedetail-item">11:00-12:00</span></div></div></div></div></div>"`;

src/packages/uploader/__tests__/uploader.spec.tsx

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react'
2-
import { render, fireEvent } from '@testing-library/react'
2+
import { render, fireEvent, waitFor, act } from '@testing-library/react'
33
import '@testing-library/jest-dom'
44

55
import { Uploader } from '../uploader'
@@ -275,9 +275,12 @@ test('simulates single file upload', async () => {
275275
})
276276
const input: any = container.querySelector('input')
277277

278-
await fireEvent.change(input, { target: { files: [file] } })
279-
280-
expect(handleUpload).toHaveBeenCalledTimes(1)
278+
await act(async () => {
279+
fireEvent.change(input, { target: { files: [file] } })
280+
})
281+
await waitFor(() => {
282+
expect(handleUpload).toHaveBeenCalledTimes(1)
283+
})
281284
expect(handleUpload).toHaveBeenCalledWith(file)
282285
})
283286
test('simulates single file upload fail', async () => {
@@ -292,9 +295,12 @@ test('simulates single file upload fail', async () => {
292295
})
293296
const input: any = container.querySelector('input')
294297

295-
await fireEvent.change(input, { target: { files: [file] } })
296-
297-
expect(handleUpload).toHaveBeenCalledTimes(1)
298+
await act(async () => {
299+
fireEvent.change(input, { target: { files: [file] } })
300+
})
301+
await waitFor(() => {
302+
expect(handleUpload).toHaveBeenCalledTimes(1)
303+
})
298304
expect(handleUpload).toHaveBeenCalledWith(file)
299305
await expect(handleUpload()).rejects.toThrow('Upload failed')
300306
})
@@ -321,9 +327,12 @@ test('simulates multiple file upload', async () => {
321327
const files = [file1, file2, file3]
322328
const input: any = container.querySelector('input')
323329

324-
await fireEvent.change(input, { target: { files } })
325-
326-
expect(handleUpload).toHaveBeenCalledTimes(2)
330+
await act(async () => {
331+
fireEvent.change(input, { target: { files } })
332+
})
333+
await waitFor(() => {
334+
expect(handleUpload).toHaveBeenCalledTimes(2)
335+
})
327336
expect(handleOverCount).toHaveBeenCalledTimes(1)
328337
expect(handleOverCount).toHaveBeenCalledWith(3)
329338
})
@@ -350,9 +359,13 @@ test('simulates file upload when autoupload is false', async () => {
350359
})
351360
const files = [file1, file2, file3]
352361
const input: any = container.querySelector('input')
353-
await fireEvent.change(input, { target: { files } })
362+
await act(async () => {
363+
fireEvent.change(input, { target: { files } })
364+
})
365+
await waitFor(() => {
366+
expect(handleOverCount).toHaveBeenCalledTimes(1)
367+
})
354368
expect(handleUpload).toHaveBeenCalledTimes(0)
355-
expect(handleOverCount).toHaveBeenCalledTimes(1)
356369
expect(handleOverCount).toHaveBeenCalledWith(3)
357370
})
358371
test('should render button', () => {
@@ -521,18 +534,30 @@ test('should handle beforeUpload function', async () => {
521534
const input: any = container.querySelector('input')
522535

523536
// 测试单个 PNG 文件上传
524-
await fireEvent.change(input, { target: { files: [pngFile] } })
525-
expect(beforeUpload).toHaveBeenCalledTimes(1)
537+
await act(async () => {
538+
fireEvent.change(input, { target: { files: [pngFile] } })
539+
})
540+
await waitFor(() => {
541+
expect(beforeUpload).toHaveBeenCalledTimes(1)
542+
})
526543
expect(handleUpload).toHaveBeenCalledWith(pngFile)
527544

528545
// 测试单个 JPG 文件被过滤
529-
await fireEvent.change(input, { target: { files: [jpgFile] } })
530-
expect(beforeUpload).toHaveBeenCalledTimes(2)
546+
await act(async () => {
547+
fireEvent.change(input, { target: { files: [jpgFile] } })
548+
})
549+
await waitFor(() => {
550+
expect(beforeUpload).toHaveBeenCalledTimes(2)
551+
})
531552
expect(handleUpload).not.toHaveBeenCalledWith(jpgFile)
532553

533554
// 测试多文件上传时的过滤
534-
await fireEvent.change(input, { target: { files: [pngFile, jpgFile] } })
535-
expect(beforeUpload).toHaveBeenCalledTimes(3)
555+
await act(async () => {
556+
fireEvent.change(input, { target: { files: [pngFile, jpgFile] } })
557+
})
558+
await waitFor(() => {
559+
expect(beforeUpload).toHaveBeenCalledTimes(3)
560+
})
536561
expect(handleUpload).toHaveBeenCalledTimes(2) // 只有 PNG 文件被上传
537562
})
538563

@@ -552,8 +577,11 @@ test('should handle beforeUpload returning empty array', async () => {
552577
})
553578

554579
const input: any = container.querySelector('input')
555-
await fireEvent.change(input, { target: { files: [file] } })
556-
557-
expect(beforeUpload).toHaveBeenCalled()
580+
await act(async () => {
581+
fireEvent.change(input, { target: { files: [file] } })
582+
})
583+
await waitFor(() => {
584+
expect(beforeUpload).toHaveBeenCalled()
585+
})
558586
expect(handleUpload).not.toHaveBeenCalled()
559587
})

0 commit comments

Comments
 (0)