-
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.
- Loading branch information
1 parent
36b93ca
commit 0c0cc65
Showing
2 changed files
with
68 additions
and
3 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
58 changes: 58 additions & 0 deletions
58
src/components/chats/FlowsTrigger/__tests__/SendFlow.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,58 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { expect, describe, it, vi, beforeEach } from 'vitest'; | ||
|
||
import SendFlow from '../SendFlow.vue'; | ||
import SelectFlow from '../SelectFlow.vue'; | ||
import SendFlowButton from '../SendFlowButton.vue'; | ||
|
||
vi.mock('@/services/api/resources/chats/flowsTrigger', () => ({ | ||
default: { | ||
getFlows: vi.fn(() => | ||
Promise.resolve([{ uuid: 'flow-1', name: 'Flow 1' }]), | ||
), | ||
}, | ||
})); | ||
|
||
describe('SendFlow', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(SendFlow, { | ||
global: { components: { SelectFlow, SendFlowButton } }, | ||
props: { contacts: [], selectedContact: {} }, | ||
}); | ||
}); | ||
|
||
it('renders correctly with initial state', async () => { | ||
await wrapper.setProps({ contacts: undefined, selectedContact: undefined }); | ||
expect(wrapper.findComponent('[data-testid="select-flow"]').exists()).toBe( | ||
true, | ||
); | ||
expect(wrapper.find('[data-testid="back-button"]').exists()).toBe(true); | ||
expect( | ||
wrapper.findComponent('[data-testid="send-flow-button"]').exists(), | ||
).toBe(true); | ||
}); | ||
|
||
it('updates selectedFlow when a flow is selected', async () => { | ||
const selectFlow = wrapper.findComponent('[data-testid="select-flow"]'); | ||
await selectFlow.vm.$emit('update:modelValue', 'flow-1'); | ||
expect(wrapper.vm.selectedFlow).toBe('flow-1'); | ||
}); | ||
|
||
it('shows and hides progress modal during flow sending process', async () => { | ||
const sendFlowButton = wrapper.findComponent( | ||
'[data-testid="send-flow-button"]', | ||
); | ||
await sendFlowButton.vm.$emit('send-flow-started'); | ||
expect(wrapper.vm.showProgressBar).toBe(true); | ||
|
||
await sendFlowButton.vm.$emit('send-flow-finished'); | ||
expect(wrapper.vm.showProgressBar).toBe(false); | ||
}); | ||
|
||
it('emits back event when back button is clicked', async () => { | ||
await wrapper.find('[data-testid="back-button"]').trigger('click'); | ||
expect(wrapper.emitted('back')).toHaveLength(1); | ||
}); | ||
}); |