Skip to content

Commit

Permalink
test name element
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0nox committed Feb 12, 2024
1 parent d72af09 commit b37d7ef
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions report-viewer/tests/unit/components/base/NameElement.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { flushPromises, mount } from '@vue/test-utils'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import NameElement from '@/components/NameElement.vue'
import { store } from '@/stores/store'

const store = {
state: {
isAnon: false
},
getDisplayName(id: string) {
return id
},
isAnonymous() {
return this.state.isAnon
},
addAnonymous() {
this.state.isAnon = true
},
removeAnonymous() {
this.state.isAnon = false
}
}

describe('Test Name Display Element', () => {
beforeEach(() => {
vi.mock('@/stores/store', () => ({
store: vi.fn(() => {
return store
})
}))
})

it('Test correct display', () => {
const wrapper = mount(NameElement, {
props: {
id: 'id'
}
})

expect(wrapper.text()).toContain('id')
})

it('Test Anonymization', async () => {
const deleteFunction = vi.spyOn(store, 'removeAnonymous')
const addFunction = vi.spyOn(store, 'addAnonymous')
const wrapper = mount(NameElement, {
props: {
id: 'id'
}
})

wrapper.find('div.invisible').trigger('click')
await flushPromises()
expect(addFunction).toHaveBeenCalled()
wrapper.find('div.invisible').trigger('click')
await flushPromises()
expect(deleteFunction).toHaveBeenCalled()
})
})

0 comments on commit b37d7ef

Please sign in to comment.