195 lines
4.7 KiB
JavaScript
195 lines
4.7 KiB
JavaScript
import { shallowMount } from "@vue/test-utils";
|
|
import listButton from "./list-button";
|
|
import { nextTick } from "vue";
|
|
|
|
describe("list-button.vue", () => {
|
|
it("Should return input type checkbox if isMultiSelect is true", async () => {
|
|
// Act
|
|
const wrapper = shallowMount(listButton, {
|
|
propsData: {
|
|
isMultiSelect: true,
|
|
},
|
|
});
|
|
|
|
// Assert
|
|
const input = wrapper.find("input");
|
|
|
|
expect(input.attributes().type).toEqual("checkbox");
|
|
});
|
|
|
|
it("Should return input type radio if isMultiSelect is false or not specified", async () => {
|
|
// Act
|
|
const wrapper = shallowMount(listButton, {
|
|
propsData: {
|
|
isMultiSelect: false,
|
|
},
|
|
});
|
|
|
|
// Assert
|
|
const input = wrapper.find("input");
|
|
|
|
expect(input.attributes().type).toEqual("radio");
|
|
});
|
|
|
|
it("Should return primary label text (buttonID)", async () => {
|
|
// Act
|
|
const wrapper = shallowMount(listButton, {
|
|
propsData: {
|
|
buttonID: "List Card Checkbox",
|
|
},
|
|
});
|
|
|
|
// Assert
|
|
const label = wrapper.find("label");
|
|
|
|
expect(label.attributes().for).toEqual("List Card Checkbox");
|
|
});
|
|
|
|
it("Should return screen reader text", async () => {
|
|
// Act
|
|
const wrapper = shallowMount(listButton, {
|
|
propsData: {
|
|
screenReaderOnlyText: "Screen Reader Only Text",
|
|
},
|
|
});
|
|
|
|
// Assert
|
|
const paragraph = wrapper.find("span.sr-only");
|
|
|
|
expect(paragraph.text()).toEqual("Screen Reader Only Text");
|
|
});
|
|
|
|
it("Should return text alignment class", async () => {
|
|
// Act
|
|
const wrapper = shallowMount(listButton, {
|
|
propsData: {
|
|
textPosition: "text-center",
|
|
},
|
|
});
|
|
|
|
// Assert
|
|
const paragraph = wrapper.find("span.m-0");
|
|
|
|
expect(paragraph.attributes("class")).toContain("text-center");
|
|
});
|
|
|
|
it("Should return aria-required state", async () => {
|
|
// Act
|
|
const wrapper = shallowMount(listButton, {
|
|
propsData: {
|
|
isRequired: true,
|
|
},
|
|
});
|
|
|
|
// Assert
|
|
const input = wrapper.find("input");
|
|
|
|
expect(input.attributes()["aria-required"]).toEqual("true");
|
|
});
|
|
|
|
it("Should return loader enabled true", async () => {
|
|
// Act
|
|
const wrapper = shallowMount(listButton, {
|
|
propsData: {
|
|
selectingInitiatesLoad: true,
|
|
},
|
|
});
|
|
|
|
// Assert
|
|
|
|
const label = wrapper.find("label");
|
|
|
|
wrapper.vm.handleCheckChange = jest.fn();
|
|
wrapper.vm.handleClick();
|
|
|
|
await nextTick();
|
|
|
|
const loader = wrapper.find("loader-stub");
|
|
|
|
expect(loader.exists()).toBe(true);
|
|
});
|
|
|
|
it("Should return loader color", async () => {
|
|
// Act
|
|
const wrapper = shallowMount(listButton, {
|
|
propsData: {
|
|
loaderColor: "blue",
|
|
selectingInitiatesLoad: true,
|
|
},
|
|
});
|
|
|
|
// Assert
|
|
|
|
const label = wrapper.find("label");
|
|
wrapper.vm.handleCheckChange = jest.fn();
|
|
wrapper.vm.handleClick();
|
|
await nextTick();
|
|
|
|
const loader = wrapper.find("loader-stub");
|
|
|
|
expect(loader.attributes("class")).toContain("blue");
|
|
});
|
|
|
|
it("Should return loader position", async () => {
|
|
// Act
|
|
const wrapper = shallowMount(listButton, {
|
|
propsData: {
|
|
loaderPosition: "right",
|
|
selectingInitiatesLoad: true,
|
|
},
|
|
});
|
|
|
|
// Assert
|
|
|
|
const label = wrapper.find("label");
|
|
|
|
wrapper.vm.handleCheckChange = jest.fn();
|
|
wrapper.vm.handleClick();
|
|
|
|
await nextTick();
|
|
|
|
const loader = wrapper.find("loader-stub");
|
|
|
|
expect(loader.attributes("class")).toContain("right");
|
|
});
|
|
|
|
it("Should emit button value on click", async () => {
|
|
// Act
|
|
const wrapper = shallowMount(listButton, {
|
|
propsData: {
|
|
isRadioHorizontal: true,
|
|
buttonLabel: "Windshield",
|
|
buttonID: "List Card Checkbox",
|
|
groupID: "radio-demo-1",
|
|
groupName: "radio 1",
|
|
buttonImage: "windshield-damage.svg",
|
|
isRequired: true,
|
|
isWide: false,
|
|
modelValue: ["List Card Checkbox"],
|
|
},
|
|
});
|
|
wrapper.vm.handleCheckChange();
|
|
// Assert
|
|
expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{buttonId: "List Card Checkbox", isChecked: Boolean}]);
|
|
});
|
|
|
|
it("Should set checkValue data if selectedButtonIDs has value(s)", async () => {
|
|
// Act
|
|
const wrapper = shallowMount(listButton, {
|
|
propsData: {
|
|
isRadioHorizontal: true,
|
|
buttonLabel: "Windshield",
|
|
buttonID: "List Card Checkbox",
|
|
groupID: "radio-demo-1",
|
|
groupName: "radio 1",
|
|
buttonImage: "windshield-damage.svg",
|
|
isRequired: true,
|
|
isWide: false,
|
|
modelValue: ["List Card Checkbox"],
|
|
selectedButtonIDs: ["Car-Front"]
|
|
},
|
|
});
|
|
// Assert
|
|
expect(wrapper.componentVM.checkValue).toEqual("Car-Front");
|
|
});
|
|
});
|