feat: add generate and back actions to workspace toolbar

This commit is contained in:
2026-06-15 20:15:06 -06:00
parent 74687c1de1
commit efb46d9df0
2 changed files with 50 additions and 5 deletions

View File

@@ -0,0 +1,41 @@
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import WorkspaceToolbar from './WorkspaceToolbar.vue'
function mountToolbar(lessonCount: number): ReturnType<typeof mount> {
return mount(WorkspaceToolbar, {
props: { lessonCount, warningCount: 0, saveStatus: 'idle' },
})
}
describe('WorkspaceToolbar', () => {
it('renders the lesson count', () => {
const wrapper = mountToolbar(3)
expect(wrapper.text()).toContain('共 3 课')
})
it('emits generate when the generate button is clicked', async () => {
const wrapper = mountToolbar(3)
await wrapper.get('button[data-testid="generate"]').trigger('click')
expect(wrapper.emitted('generate')).toHaveLength(1)
})
it('emits back when the back button is clicked', async () => {
const wrapper = mountToolbar(0)
await wrapper.get('button[data-testid="back"]').trigger('click')
expect(wrapper.emitted('back')).toHaveLength(1)
})
it('keeps generate and back enabled even with no lessons', () => {
const wrapper = mountToolbar(0)
expect(wrapper.get('button[data-testid="generate"]').attributes('disabled')).toBeUndefined()
expect(wrapper.get('button[data-testid="back"]').attributes('disabled')).toBeUndefined()
})
it('disables print, export and clear when there are no lessons', () => {
const wrapper = mountToolbar(0)
expect(wrapper.get('button[data-testid="print"]').attributes('disabled')).toBeDefined()
expect(wrapper.get('button[data-testid="export"]').attributes('disabled')).toBeDefined()
expect(wrapper.get('button[data-testid="clear"]').attributes('disabled')).toBeDefined()
})
})