Skip to content

Commit 10550b3

Browse files
luizhf42gustavosbarreto
authored andcommitted
test(ui): add RoleSelect tests and snapshot
1 parent 4d59d33 commit 10550b3

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { mount, VueWrapper } from "@vue/test-utils";
2+
import { createVuetify } from "vuetify";
3+
import { expect, describe, it, beforeEach } from "vitest";
4+
import RoleSelect from "@/components/Team/RoleSelect.vue";
5+
import { BasicRole } from "@/interfaces/INamespace";
6+
7+
describe("RoleSelect", () => {
8+
let wrapper: VueWrapper<InstanceType<typeof RoleSelect>>;
9+
const vuetify = createVuetify();
10+
11+
beforeEach(async () => {
12+
wrapper = mount(RoleSelect, {
13+
global: {
14+
plugins: [vuetify],
15+
},
16+
props: {
17+
modelValue: "administrator" as BasicRole,
18+
},
19+
});
20+
});
21+
22+
it("Is a Vue instance", () => {
23+
expect(wrapper.vm).toBeTruthy();
24+
});
25+
26+
it("Renders the component", () => {
27+
expect(wrapper.html()).toMatchSnapshot();
28+
});
29+
30+
it("renders the role select component", () => {
31+
expect(wrapper.find('[data-test="role-select"]').exists()).toBe(true);
32+
});
33+
34+
it("displays the initial model value", async () => {
35+
const selectComponent = wrapper.findComponent({ name: "VSelect" });
36+
expect(selectComponent.props("modelValue")).toBe("administrator");
37+
});
38+
39+
it("has correct values for each role", () => {
40+
const select = wrapper.findComponent({ name: "VSelect" });
41+
const items = select.props("items");
42+
43+
expect(items[0]).toEqual({
44+
title: "Administrator",
45+
value: "administrator",
46+
description: expect.stringContaining("Full access to the namespace"),
47+
});
48+
49+
expect(items[1]).toEqual({
50+
title: "Operator",
51+
value: "operator",
52+
description: expect.stringContaining("Can manage and operate devices"),
53+
});
54+
55+
expect(items[2]).toEqual({
56+
title: "Observer",
57+
value: "observer",
58+
description: expect.stringContaining("Can view device details"),
59+
});
60+
});
61+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`RoleSelect > Renders the component 1`] = `
4+
"<div data-v-444f7389="" class="v-input v-input--horizontal v-input--center-affix v-input--density-default v-theme--light v-locale--is-ltr v-input--dirty v-text-field v-select v-select--single v-select--selected" data-test="role-select">
5+
<!---->
6+
<div class="v-input__control">
7+
<div class="v-field v-field--active v-field--appended v-field--center-affix v-field--dirty v-field--variant-filled v-theme--light v-locale--is-ltr" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="v-menu-v-2">
8+
<div class="v-field__overlay"></div>
9+
<div class="v-field__loader">
10+
<div class="v-progress-linear v-theme--light v-locale--is-ltr" style="top: 0px; height: 0px; --v-progress-linear-height: 2px;" role="progressbar" aria-hidden="true" aria-valuemin="0" aria-valuemax="100">
11+
<!---->
12+
<div class="v-progress-linear__background"></div>
13+
<div class="v-progress-linear__buffer" style="width: 0%;"></div>
14+
<transition-stub name="fade-transition" appear="false" persisted="false" css="true">
15+
<div class="v-progress-linear__indeterminate">
16+
<div class="v-progress-linear__indeterminate long"></div>
17+
<div class="v-progress-linear__indeterminate short"></div>
18+
</div>
19+
</transition-stub>
20+
<!---->
21+
</div>
22+
</div>
23+
<!---->
24+
<div class="v-field__field" data-no-activator=""><label class="v-label v-field-label v-field-label--floating" for="input-v-0" aria-hidden="false">
25+
<!---->Role
26+
</label><label class="v-label v-field-label" for="input-v-0">
27+
<!---->Role
28+
</label>
29+
<!---->
30+
<div class="v-field__input" data-no-activator="">
31+
<!---->
32+
<!---->
33+
<div class="v-select__selection"><span class="v-select__selection-text">Administrator<!----></span></div><input size="1" type="text" id="input-v-0" aria-describedby="input-v-0-messages" inputmode="none" aria-label="Open" title="Open" required="" value="administrator">
34+
</div>
35+
<!---->
36+
</div>
37+
<!---->
38+
<div class="v-field__append-inner">
39+
<!----><i class="mdi-menu-down mdi v-icon notranslate v-theme--light v-icon--size-default v-select__menu-icon" aria-hidden="true"></i>
40+
<!---->
41+
</div>
42+
<div class="v-field__outline">
43+
<!---->
44+
<!---->
45+
</div>
46+
</div>
47+
</div>
48+
<!---->
49+
<div id="input-v-0-messages" class="v-input__details" role="alert" aria-live="polite">
50+
<transition-group-stub name="slide-y-transition" tag="div" appear="false" persisted="false" css="true" class="v-messages">
51+
<!---->
52+
</transition-group-stub>
53+
<!---->
54+
</div>
55+
</div>"
56+
`;

0 commit comments

Comments
 (0)