Tabs.sample 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { mount } from "@vue/test-utils"
  2. import tabs from "../Tabs"
  3. import tab from "../Tab"
  4. const factory = () =>
  5. mount(tabs, {
  6. slots: {
  7. default: [
  8. `<Tab id="tab1" href="#" :label="'tab 1'" :icon="'testicon1'" :selected=true><div id="tab1render">tab1</div></Tab>`,
  9. `<Tab id="tab2" href="#" :label="'tab 2'" :icon="'testicon2'"><div id="tab2render">tab1</div></Tab>`,
  10. `<Tab id="tab3" href="#" :label="'tab 3'" :icon="'testicon3'"><div id="tab3render">tab1</div></Tab>`,
  11. ],
  12. },
  13. stubs: {
  14. Tab: tab,
  15. },
  16. })
  17. describe("tabs", () => {
  18. test("mounts properly", async () => {
  19. const wrapper = factory()
  20. await wrapper.vm.$nextTick()
  21. expect(wrapper).toBeTruthy()
  22. })
  23. test("tab labels shown", async () => {
  24. const wrapper = factory()
  25. await wrapper.vm.$nextTick()
  26. const labels = wrapper.findAll("button span").wrappers.map((w) => w.text())
  27. expect(labels).toEqual(["tab 1", "tab 2", "tab 3"])
  28. })
  29. test("tab icons are shown", async () => {
  30. const wrapper = factory()
  31. await wrapper.vm.$nextTick()
  32. const labels = wrapper.findAll("li a i").wrappers.map((w) => w.text())
  33. expect(labels).toEqual(["testicon1", "testicon2", "testicon3"])
  34. })
  35. test("clicking on tab labels switches the selected page", async () => {
  36. const wrapper = factory()
  37. await wrapper.vm.$nextTick()
  38. wrapper.vm.selectTab({ id: "tab2" })
  39. await wrapper.vm.$nextTick()
  40. expect(wrapper.vm.$data.tabs[1].$data.active).toEqual(true)
  41. })
  42. test("switched tab page is rendered and the other page is not rendered", async () => {
  43. const wrapper = factory()
  44. await wrapper.vm.$nextTick()
  45. wrapper.vm.selectTab({ id: "tab2" })
  46. await wrapper.vm.$nextTick()
  47. expect(wrapper.vm.$data.tabs[0].$data.active).toEqual(false)
  48. expect(wrapper.vm.$data.tabs[1].$data.active).toEqual(true)
  49. expect(wrapper.vm.$data.tabs[2].$data.active).toEqual(false)
  50. })
  51. })