# Pull Request Template ## Description Replaces the messageMixin with the new useMessage composable Fixes https://linear.app/chatwoot/issue/CW-3475/rewrite-messagemixin-mixin-to-a-composable ## Type of change Please delete options that are not relevant. - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected) - [ ] This change requires a documentation update
72 lines
2.2 KiB
JavaScript
72 lines
2.2 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { reactive, nextTick } from 'vue';
|
|
import { useMessage } from '../useMessage';
|
|
|
|
describe('useMessage', () => {
|
|
it('should handle deleted messages', () => {
|
|
const message = reactive({
|
|
content_attributes: { deleted: true },
|
|
attachments: [],
|
|
});
|
|
|
|
const { messageContentAttributes, hasAttachments } = useMessage(message);
|
|
|
|
expect(messageContentAttributes.value).toEqual({ deleted: true });
|
|
expect(hasAttachments.value).toBe(false);
|
|
});
|
|
|
|
it('should handle non-deleted messages with attachments', () => {
|
|
const message = reactive({
|
|
content_attributes: {},
|
|
attachments: ['attachment1', 'attachment2'],
|
|
});
|
|
|
|
const { messageContentAttributes, hasAttachments } = useMessage(message);
|
|
|
|
expect(messageContentAttributes.value).toEqual({});
|
|
expect(hasAttachments.value).toBe(true);
|
|
});
|
|
|
|
it('should handle messages without content_attributes', () => {
|
|
const message = reactive({
|
|
attachments: [],
|
|
});
|
|
|
|
const { messageContentAttributes, hasAttachments } = useMessage(message);
|
|
|
|
expect(messageContentAttributes.value).toEqual({});
|
|
expect(hasAttachments.value).toBe(false);
|
|
});
|
|
|
|
it('should handle messages with empty attachments array', () => {
|
|
const message = reactive({
|
|
content_attributes: { someAttribute: 'value' },
|
|
attachments: [],
|
|
});
|
|
|
|
const { messageContentAttributes, hasAttachments } = useMessage(message);
|
|
|
|
expect(messageContentAttributes.value).toEqual({ someAttribute: 'value' });
|
|
expect(hasAttachments.value).toBe(false);
|
|
});
|
|
|
|
it('should update reactive properties when message changes', async () => {
|
|
const message = reactive({
|
|
content_attributes: {},
|
|
attachments: [],
|
|
});
|
|
|
|
const { messageContentAttributes, hasAttachments } = useMessage(message);
|
|
|
|
expect(messageContentAttributes.value).toEqual({});
|
|
expect(hasAttachments.value).toBe(false);
|
|
|
|
message.content_attributes = { updated: true };
|
|
message.attachments.push('newAttachment');
|
|
await nextTick();
|
|
|
|
expect(messageContentAttributes.value).toEqual({ updated: true });
|
|
expect(hasAttachments.value).toBe(true);
|
|
});
|
|
});
|