-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
add970b
commit 38b59e3
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
packages/component-library/src/components/form/mt-colorpicker/mt-colorpicker.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { mount } from "@vue/test-utils"; | ||
import userEvent from "@testing-library/user-event"; | ||
import MtColorpicker from "./mt-colorpicker.vue"; | ||
|
||
async function createWrapper(customOptions = {}) { | ||
return mount(MtColorpicker, { | ||
...customOptions, | ||
}); | ||
} | ||
|
||
describe("src/app/component/form/mt-datepicker", () => { | ||
let wrapper: undefined | Awaited<ReturnType<typeof createWrapper>>; | ||
|
||
afterEach(() => { | ||
if (wrapper) { | ||
wrapper.unmount(); | ||
} | ||
}); | ||
|
||
it("opens with keyboard", async () => { | ||
const user = userEvent.setup(); | ||
wrapper = await createWrapper({ | ||
props: { | ||
modelValue: "#0fcff5", | ||
}, | ||
attachTo: document.body, | ||
}); | ||
|
||
// Simulate tabbing to focus the input element | ||
await user.tab(); | ||
const colorPickerInput = wrapper.find(".mt-colorpicker__input"); | ||
const inputElement = colorPickerInput.element as HTMLInputElement; | ||
|
||
expect(inputElement).toHaveFocus(); | ||
|
||
// Simulate pressing Enter to open modal | ||
await user.keyboard("{Enter}"); | ||
const dropdown = document.querySelector(".mt-floating-ui__content"); | ||
expect(dropdown).toBeDefined(); | ||
}); | ||
|
||
it("allows value changes with keyboard", async () => { | ||
const user = userEvent.setup(); | ||
wrapper = await createWrapper({ | ||
props: { | ||
modelValue: "#0fcff5", | ||
}, | ||
attachTo: document.body, | ||
}); | ||
|
||
// Simulate tabbing to focus the input element | ||
await user.tab(); | ||
const colorPickerInput = wrapper.find(".mt-colorpicker__input"); | ||
const inputElement = colorPickerInput.element as HTMLInputElement; | ||
|
||
// Simulate pressing Enter to open modal | ||
await user.keyboard("{Enter}"); | ||
|
||
// Focus color slider | ||
await userEvent.keyboard("{Tab}"); | ||
|
||
// Change value with arrow key | ||
await userEvent.keyboard("{arrowleft}"); | ||
|
||
expect(inputElement.value).toBe("#10cef4"); | ||
}); | ||
}); |