Merge branch 'develop' into chore-repalce-configMixin-with-useConfig-composable

This commit is contained in:
Fayaz Ahmed
2024-08-28 08:26:01 +05:30
committed by GitHub
197 changed files with 6133 additions and 3812 deletions
@@ -1,71 +0,0 @@
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);
});
});
@@ -1,22 +0,0 @@
import { computed } from 'vue';
/**
* Composable for handling message-related computations.
* @param {Object} message - The message object to be processed.
* @returns {Object} An object containing computed properties for message content and attachments.
*/
export function useMessage(message) {
const messageContentAttributes = computed(() => {
const { content_attributes: attribute = {} } = message;
return attribute;
});
const hasAttachments = computed(() => {
return !!(message.attachments && message.attachments.length > 0);
});
return {
messageContentAttributes,
hasAttachments,
};
}