Skip to content

Commit

Permalink
test: add component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdehaven committed Jan 2, 2024
1 parent 3fe8d37 commit b0a0d70
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions src/components/toolbar/MarkdownToolbar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const setProvideData = (
{ mode?: MarkdownMode, editable?: boolean, fullscreen?: boolean, htmlPreview?: boolean },
) => ({
// Bind the Symbol() as dynamic keys <https://test-utils.vuejs.org/api/#global-provide>
[MODE_INJECTION_KEY]: ref(mode),
[MODE_INJECTION_KEY]: ref(mode), // Note: split mode will be automatically switched to edit basd on the viewport
[EDITABLE_INJECTION_KEY]: ref(editable),
[FULLSCREEN_INJECTION_KEY]: ref(fullscreen),
[HTML_PREVIEW_INJECTION_KEY]: ref(htmlPreview),
Expand Down Expand Up @@ -78,6 +78,52 @@ describe('<MarkdownToolbar />', () => {
}
})

describe('toolbar-buttons', () => {
// Loop through the iterable buttons
for (const button of [...formatOptions, ...templateOptions]) {
it(`'${button.label}' button is visible`, async () => {
const wrapper = await mount(MarkdownToolbar, {
global: {
provide: setProvideData({
mode: 'edit',
editable: true,
}),
},
})

expect(wrapper.find(`[data-testid$="-option-${button.action}"]`).isVisible()).toBe(true)
})
}

// Now test the standalone buttons

it("'Fullscreen' button is visible", async () => {
const wrapper = await mount(MarkdownToolbar, {
global: {
provide: setProvideData({
mode: 'edit',
editable: true,
}),
},
})

expect(wrapper.findTestId('toggle-fullscreen').isVisible()).toBe(true)
})

it("'HTML Preview' button is visible", async () => {
const wrapper = await mount(MarkdownToolbar, {
global: {
provide: setProvideData({
mode: 'preview', // must be in preview or split mode
editable: true,
}),
},
})

expect(wrapper.findTestId('toggle-html-preview').isVisible()).toBe(true)
})
})

describe('emit events', () => {
describe('change-mode', () => {
it('changes the mode when one of the mode radio buttons is clicked', async () => {
Expand Down Expand Up @@ -207,7 +253,7 @@ describe('<MarkdownToolbar />', () => {
const wrapper = await mount(MarkdownToolbar, {
global: {
provide: setProvideData({
mode: 'preview',
mode: 'preview', // must be in preview or split mode
editable: true,
htmlPreview: false,
}),
Expand Down

0 comments on commit b0a0d70

Please sign in to comment.