-
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 ModalRemoveSelectedContacts tests
- Loading branch information
1 parent
9e88921
commit 99c9d0e
Showing
2 changed files
with
86 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
82 changes: 82 additions & 0 deletions
82
src/components/chats/FlowsTrigger/__tests__/ModalRemoveSelectedContacts.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,82 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { expect, describe, it, beforeEach, vi } from 'vitest'; | ||
|
||
import ModalRemoveSelectedContacts from '../ModalRemoveSelectedContacts.vue'; | ||
|
||
const contactsMock = [{ uuid: '1', name: 'John Doe' }]; | ||
|
||
describe('ModalRemoveSelectedContacts', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(ModalRemoveSelectedContacts, { | ||
props: { contacts: contactsMock }, | ||
}); | ||
}); | ||
|
||
it('renders correctly when contacts are provided', () => { | ||
expect( | ||
wrapper | ||
.findComponent('[data-testid="modal-remove-selected-contacts"]') | ||
.exists(), | ||
).toBe(true); | ||
|
||
expect( | ||
wrapper | ||
.findComponent('[data-testid="selected-contacts-section"]') | ||
.exists(), | ||
).toBe(true); | ||
|
||
expect( | ||
wrapper.findComponent('[data-testid="confirm-button"]').exists(), | ||
).toBe(true); | ||
|
||
expect( | ||
wrapper.findComponent('[data-testid="cancel-button"]').exists(), | ||
).toBe(true); | ||
}); | ||
|
||
it('emits close event when cancel button is clicked', async () => { | ||
await wrapper.find('[data-testid="cancel-button"]').trigger('click'); | ||
expect(wrapper.emitted('close')).toBeTruthy(); | ||
}); | ||
|
||
it('adds contact to contactsToRemove when removeModalContact is called', async () => { | ||
const contact = contactsMock[0]; | ||
|
||
const selectedContactsSection = wrapper.findComponent( | ||
'[data-testid="selected-contacts-section"]', | ||
); | ||
|
||
selectedContactsSection.vm.$emit('remove-contact', contact); | ||
|
||
await wrapper.vm.$nextTick(); | ||
|
||
expect(wrapper.vm.contactsToRemove[0].uuid).toEqual(contact.uuid); | ||
expect(wrapper.vm.contactsToRemove[0].name).toEqual(contact.name); | ||
}); | ||
|
||
it('computes newContacts excluding contactsToRemove', async () => { | ||
await wrapper.setProps({ | ||
contacts: [...contactsMock, { uuid: '2', name: 'Jane Doe' }], | ||
}); | ||
|
||
await wrapper.setData({ contactsToRemove: [contactsMock[0]] }); | ||
|
||
expect(wrapper.vm.newContacts).toEqual([{ uuid: '2', name: 'Jane Doe' }]); | ||
}); | ||
|
||
it('should emit remove-contacts on click confirm button', async () => { | ||
await wrapper.setProps({ | ||
contacts: [...contactsMock, { uuid: '2', name: 'Jane Doe' }], | ||
}); | ||
|
||
await wrapper.setData({ contactsToRemove: [contactsMock[0]] }); | ||
|
||
await wrapper.find('[data-testid="confirm-button"]').trigger('click'); | ||
|
||
expect(wrapper.emitted('remove-contacts')[0][0]).toStrictEqual([ | ||
contactsMock[0], | ||
]); | ||
}); | ||
}); |