Fixes https://github.com/chatwoot/chatwoot/issues/8436 Fixes https://github.com/chatwoot/chatwoot/issues/9767 Fixes https://github.com/chatwoot/chatwoot/issues/10156 Fixes https://github.com/chatwoot/chatwoot/issues/6031 Fixes https://github.com/chatwoot/chatwoot/issues/5696 Fixes https://github.com/chatwoot/chatwoot/issues/9250 Fixes https://github.com/chatwoot/chatwoot/issues/9762 --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
import { getCurrentInstance } from 'vue';
|
|
import { emitter } from 'shared/helpers/mitt';
|
|
import { useTrack, useAlert } from '../index';
|
|
|
|
vi.mock('vue', () => ({
|
|
getCurrentInstance: vi.fn(),
|
|
}));
|
|
vi.mock('shared/helpers/mitt', () => ({
|
|
emitter: {
|
|
emit: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
describe('useTrack', () => {
|
|
it('should return a function', () => {
|
|
const track = useTrack();
|
|
expect(typeof track).toBe('function');
|
|
});
|
|
});
|
|
|
|
describe('useAlert', () => {
|
|
it('should emit a newToastMessage event with the provided message and action', () => {
|
|
const message = 'Toast message';
|
|
const action = {
|
|
type: 'link',
|
|
to: '/app/accounts/1/conversations/1',
|
|
message: 'Navigate',
|
|
};
|
|
useAlert(message, action);
|
|
expect(emitter.emit).toHaveBeenCalledWith('newToastMessage', {
|
|
message,
|
|
action,
|
|
});
|
|
});
|
|
|
|
it('should emit a newToastMessage event with the provided message and no action if action is null', () => {
|
|
const message = 'Toast message';
|
|
useAlert(message);
|
|
expect(emitter.emit).toHaveBeenCalledWith('newToastMessage', {
|
|
message,
|
|
action: null,
|
|
});
|
|
});
|
|
});
|