forked from openWB/openwb-ui-settings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenwbBaseArrayInput.spec.js
67 lines (66 loc) · 2.1 KB
/
OpenwbBaseArrayInput.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { describe, it, expect } from "vitest";
import { shallowMount } from "@vue/test-utils";
import OpenwbBaseArrayInput from "../OpenwbBaseArrayInput.vue";
describe("OpenwbBaseArrayInput.vue", () => {
// check title prop
it("render title", () => {
const title = "Array Input Test";
const wrapper = shallowMount(OpenwbBaseArrayInput, {
props: { title },
});
const titleLabel = wrapper.find("label.col-form-label");
expect(titleLabel.html()).toContain(title);
});
// check help slot
it("show help symbol", () => {
const helpContent = "This is our help text.";
const wrapper = shallowMount(OpenwbBaseArrayInput, {
slots: {
help: helpContent,
},
});
const titleLabel = wrapper.find("label.col-form-label");
expect(titleLabel.html()).toContain("question-circle");
});
it("show help slot when title is clicked", async () => {
const title = "Number Input Test";
const helpContent = "This is our help text.";
const wrapper = shallowMount(OpenwbBaseArrayInput, {
props: { title },
slots: {
help: helpContent,
},
});
const titleLabel = wrapper.find("label.col-form-label");
expect(wrapper.find("span.alert.alert-info").exists()).toBe(false);
await titleLabel.trigger("click");
expect(wrapper.find("span.alert.alert-info").html()).toContain(
helpContent,
);
});
// check initial value
it("display initial value", () => {
const modelValue = ["1234", "2345"];
const wrapper = shallowMount(OpenwbBaseArrayInput, {
props: { modelValue },
});
const renderedTagList = wrapper.find(".tagList");
modelValue.forEach((element) => {
expect(renderedTagList.html()).toContain(element);
});
});
// check user input
it("add element", async () => {
const newTag = "1234";
const wrapper = shallowMount(OpenwbBaseArrayInput, {});
const renderedTextInput = wrapper.find("input[type=text]");
await renderedTextInput.setValue(newTag);
const renderedAddButton = wrapper.find(
".input-group-append font-awesome-icon-stub",
);
await renderedAddButton.trigger("click");
expect(wrapper.emitted("update:modelValue")[0]).toStrictEqual([
[newTag],
]);
});
});