-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
report-viewer/tests/unit/components/base/NameElement.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |