Skip to content

Commit

Permalink
test: add pinia to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohan Bansal committed Dec 6, 2024
1 parent 69c3c7a commit fcb714c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
7 changes: 6 additions & 1 deletion atable/tests/cell.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, it, expect } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { describe, it, expect, beforeEach } from 'vitest'
import { mount } from '@vue/test-utils'

import ATable from '@/components/ATable.vue'
Expand Down Expand Up @@ -45,6 +46,10 @@ describe('table cell component', () => {
config: { view: 'list' },
}

beforeEach(() => {
setActivePinia(createPinia())
})

it('update data when cell is focused', async () => {
const wrapper = mount(ATable, { props })

Expand Down
15 changes: 10 additions & 5 deletions atable/tests/modal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, it, expect } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
import { describe, it, expect, beforeEach } from 'vitest'
import { mount } from '@vue/test-utils'

import ATable from '@/components/ATable.vue'
Expand Down Expand Up @@ -45,6 +46,10 @@ describe('table modal component', () => {
config: { view: 'list' },
}

beforeEach(() => {
setActivePinia(createPinia())
})

it('spawn modal component', async () => {
const wrapper = mount(ATable, { props })

Expand All @@ -54,7 +59,7 @@ describe('table modal component', () => {
cellElement!.trigger('click')
await wrapper.vm.$nextTick()

expect(wrapper.vm.tableData.modal.visible).toBe(true)
expect(wrapper.vm.store.modal.visible).toBe(true)
})

it('click inside to keep modal component alive', async () => {
Expand All @@ -69,7 +74,7 @@ describe('table modal component', () => {
// click inside
const $table = wrapper.find('.atable')
$table.trigger('click')
expect(wrapper.vm.tableData.modal.visible).toBe(true)
expect(wrapper.vm.store.modal.visible).toBe(true)
})

it('click outside to dismiss modal component', async () => {
Expand All @@ -83,7 +88,7 @@ describe('table modal component', () => {

// click outside
window.dispatchEvent(new MouseEvent('click'))
expect(wrapper.vm.tableData.modal.visible).toBe(false)
expect(wrapper.vm.store.modal.visible).toBe(false)
})

it('press escape to dismiss modal component', async () => {
Expand All @@ -97,6 +102,6 @@ describe('table modal component', () => {

// press escape
window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }))
expect(wrapper.vm.tableData.modal.visible).toBe(false)
expect(wrapper.vm.store.modal.visible).toBe(false)
})
})
7 changes: 6 additions & 1 deletion atable/tests/row.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, it, expect } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
import { describe, it, expect, beforeEach } from 'vitest'
import { mount } from '@vue/test-utils'

import ATable from '@/components/ATable.vue'
Expand Down Expand Up @@ -39,6 +40,10 @@ describe('table row component', () => {
},
]

beforeEach(() => {
setActivePinia(createPinia())
})

it('verify no expand symbol on list table config', async () => {
const wrapper = mount(ATable, {
props: {
Expand Down
7 changes: 6 additions & 1 deletion atable/tests/table.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, it, expect } from 'vitest'
import { createPinia, setActivePinia } from 'pinia'
import { describe, it, expect, beforeEach } from 'vitest'
import { mount } from '@vue/test-utils'

import ATable from '@/components/ATable.vue'
Expand Down Expand Up @@ -45,6 +46,10 @@ describe('table component', () => {
config: { view: 'list' },
}

beforeEach(() => {
setActivePinia(createPinia())
})

it('verify header row', async () => {
const wrapper = mount(ATable, { props: defaultProps })
expect(wrapper.vm).toBeTruthy()
Expand Down

0 comments on commit fcb714c

Please sign in to comment.