-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add SelectedContactsSection tests
- Loading branch information
1 parent
0c0cc65
commit 67c13c8
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
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
56 changes: 56 additions & 0 deletions
56
src/components/chats/FlowsTrigger/__tests__/SelectedContactsSection.spec.js
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,56 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { expect, describe, it, beforeEach } from 'vitest'; | ||
|
||
import SelectedContactsSection from '../SelectedContactsSection.vue'; | ||
|
||
const contactsMock = [ | ||
{ uuid: '1', name: 'Contact 1' }, | ||
{ uuid: '2', name: 'Contact 2' }, | ||
]; | ||
|
||
describe('SelectedContactsSection', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(SelectedContactsSection, { props: { contacts: [] } }); | ||
}); | ||
|
||
it('renders only if contacts are provided', async () => { | ||
expect( | ||
wrapper.find('[data-testid="selected-contacts-section"]').exists(), | ||
).toBe(false); | ||
await wrapper.setProps({ contacts: [{ uuid: '1', name: 'Contact 1' }] }); | ||
expect( | ||
wrapper.find('[data-testid="selected-contacts-section"]').exists(), | ||
).toBe(true); | ||
}); | ||
|
||
it('displays contacts as tags', async () => { | ||
await wrapper.setProps({ contacts: contactsMock }); | ||
|
||
const tags = wrapper.findAllComponents('[data-testid="contact-tag"]'); | ||
expect(tags).toHaveLength(contactsMock.length); | ||
expect(tags[0].props('text')).toBe(contactsMock[0].name); | ||
expect(tags[1].props('text')).toBe(contactsMock[1].name); | ||
}); | ||
|
||
it('emits remove-contact event with correct contact on tag close', async () => { | ||
await wrapper.setProps({ contacts: [contactsMock[0]] }); | ||
|
||
const tag = wrapper.findComponent('[data-testid="contact-tag"]'); | ||
|
||
await tag.vm.$emit('close'); | ||
|
||
expect(wrapper.emitted('remove-contact')[0]).toEqual([contactsMock[0]]); | ||
}); | ||
|
||
it('emits click event when section is clicked or Enter is pressed', async () => { | ||
await wrapper.setProps({ contacts: [contactsMock[0]] }); | ||
|
||
await wrapper.trigger('click'); | ||
expect(wrapper.emitted('click')).toHaveLength(1); | ||
|
||
await wrapper.trigger('keypress.enter'); | ||
expect(wrapper.emitted('click')).toHaveLength(2); | ||
}); | ||
}); |