mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 23:56:42 +08:00
fix(a11y): label dialog close buttons (#654)
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
// 定义输入参数
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
// 是否显示
|
/** 覆盖关闭按钮默认的右上角定位 class。 */
|
||||||
innerClass: String,
|
innerClass: String,
|
||||||
})
|
})
|
||||||
// 定义触发的自定义事件
|
|
||||||
const emit = defineEmits(['click', 'update:modelValue'])
|
const emit = defineEmits(['click', 'update:modelValue'])
|
||||||
// 按钮点击
|
|
||||||
function onClick() {
|
function onClick() {
|
||||||
emit('update:modelValue', false)
|
emit('update:modelValue', false)
|
||||||
emit('click')
|
emit('click')
|
||||||
@@ -15,6 +16,7 @@ function onClick() {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<IconBtn
|
<IconBtn
|
||||||
|
:aria-label="t('common.close')"
|
||||||
:class="props.innerClass ? props.innerClass : 'absolute right-3 top-3 z-10'"
|
:class="props.innerClass ? props.innerClass : 'absolute right-3 top-3 z-10'"
|
||||||
@click.stop="onClick"
|
@click.stop="onClick"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import DialogCloseBtn from '@/@core/components/DialogCloseBtn.vue'
|
||||||
|
import i18n from '@/plugins/i18n'
|
||||||
|
import { screen, waitFor } from '@testing-library/vue'
|
||||||
|
import userEvent from '@testing-library/user-event'
|
||||||
|
import { renderWithProviders } from '@tests/support/render'
|
||||||
|
import { afterEach, describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
i18n.global.locale.value = 'zh-CN'
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('DialogCloseBtn', () => {
|
||||||
|
it('keeps its visual and event contracts while exposing a localized name', async () => {
|
||||||
|
const user = userEvent.setup()
|
||||||
|
const { container, emitted, rerender } = await renderWithProviders(DialogCloseBtn)
|
||||||
|
const button = screen.getByRole('button', { name: '关闭' })
|
||||||
|
|
||||||
|
expect(button).toHaveClass('absolute', 'right-3', 'top-3', 'z-10')
|
||||||
|
const icon = container.querySelector('svg.v-icon')
|
||||||
|
expect(icon).not.toBeNull()
|
||||||
|
expect(icon).toHaveAttribute('aria-hidden', 'true')
|
||||||
|
await waitFor(() =>
|
||||||
|
expect(icon?.querySelector('path')).toHaveAttribute(
|
||||||
|
'd',
|
||||||
|
'M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12z',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
i18n.global.locale.value = 'en-US'
|
||||||
|
await waitFor(() => expect(screen.getByRole('button', { name: 'Close' })).toBe(button))
|
||||||
|
|
||||||
|
await user.click(button)
|
||||||
|
expect(emitted()['update:modelValue']).toEqual([[false]])
|
||||||
|
expect(emitted().click).toEqual([[]])
|
||||||
|
|
||||||
|
await rerender({ innerClass: 'dialog-close-custom' })
|
||||||
|
expect(button).toHaveClass('dialog-close-custom')
|
||||||
|
expect(button).not.toHaveClass('absolute', 'right-3', 'top-3', 'z-10')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -220,7 +220,9 @@ describe('SiteImportDialog', () => {
|
|||||||
await fireEvent.click(await screen.findByRole('button', { name: '开始导入' }))
|
await fireEvent.click(await screen.findByRole('button', { name: '开始导入' }))
|
||||||
expect(await screen.findByText('导入过程中出现 1 个错误')).toBeInTheDocument()
|
expect(await screen.findByText('导入过程中出现 1 个错误')).toBeInTheDocument()
|
||||||
|
|
||||||
await fireEvent.click(screen.getByRole('button', { name: '关闭' }))
|
const resultCloseButton = screen.getByText('关闭').closest('button')
|
||||||
|
expect(resultCloseButton).not.toBeNull()
|
||||||
|
await fireEvent.click(resultCloseButton!)
|
||||||
expect(events.update).toHaveBeenCalledWith(false)
|
expect(events.update).toHaveBeenCalledWith(false)
|
||||||
expect(events.importSuccess).not.toHaveBeenCalled()
|
expect(events.importSuccess).not.toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user