Tab.sample 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { mount } from "@vue/test-utils"
  2. import tab from "../Tab"
  3. const factory = (props, data) => {
  4. if (data) {
  5. return mount(tab, {
  6. propsData: props,
  7. data: () => data,
  8. slots: {
  9. default: '<div id="testdiv"></div>',
  10. },
  11. })
  12. } else {
  13. return mount(tab, {
  14. propsData: props,
  15. slots: {
  16. default: '<div id="testdiv"></div>',
  17. },
  18. })
  19. }
  20. }
  21. describe("tab", () => {
  22. test("mounts properly when needed props are passed in", () => {
  23. const wrapper = factory({
  24. label: "TestLabel",
  25. icon: "TestIcon",
  26. id: "testid",
  27. selected: true,
  28. })
  29. expect(wrapper).toBeTruthy()
  30. })
  31. test("mounts properly when selected prop is not passed", () => {
  32. const wrapper = factory({
  33. label: "TestLabel",
  34. icon: "TestIcon",
  35. id: "testid",
  36. })
  37. expect(wrapper).toBeTruthy()
  38. })
  39. test("if 'selected' prop is not passed, it is set to false by default", () => {
  40. const wrapper = factory({
  41. label: "TestLabel",
  42. icon: "TestIcon",
  43. id: "testid",
  44. })
  45. expect(wrapper.props("selected")).toEqual(false)
  46. })
  47. test("if set active, the slot is shown", () => {
  48. const wrapper = factory(
  49. {
  50. label: "TestLabel",
  51. icon: "TestIcon",
  52. id: "testid",
  53. selected: true,
  54. },
  55. {
  56. active: true,
  57. }
  58. )
  59. expect(wrapper.find("#testdiv").isVisible()).toEqual(true)
  60. })
  61. test("if not set active, the slot is not rendered", () => {
  62. const wrapper = factory(
  63. {
  64. label: "TestLabel",
  65. icon: "TestIcon",
  66. id: "testid",
  67. },
  68. {
  69. active: false,
  70. }
  71. )
  72. expect(wrapper.find("#testdiv").isVisible()).toEqual(false)
  73. })
  74. })