From fa1afe8ce92fc33c324f69f352403c116659d9b0 Mon Sep 17 00:00:00 2001 From: virgilchiriac Date: Wed, 12 Jun 2024 13:54:31 +0200 Subject: [PATCH] add dumb tests for some DOs --- .../collaborative-text-editor.do.spec.ts | 35 ++++++++ .../board/domain/drawing-element.do.spec.ts | 44 ++++++++++ .../domain/external-tool-element.do.spec.ts | 44 ++++++++++ .../board/domain/file-element.do.spec.ts | 54 ++++++++++++ .../board/domain/link-element.do.spec.ts | 74 ++++++++++++++++ .../media-external-tool-element.do.spec.ts | 39 +++++++++ .../board/domain/rich-text-element.do.spec.ts | 55 ++++++++++++ .../board/domain/submission-item.do.spec.ts | 87 +++++++++++++++++++ 8 files changed, 432 insertions(+) create mode 100644 apps/server/src/modules/board/domain/collaborative-text-editor.do.spec.ts create mode 100644 apps/server/src/modules/board/domain/drawing-element.do.spec.ts create mode 100644 apps/server/src/modules/board/domain/external-tool-element.do.spec.ts create mode 100644 apps/server/src/modules/board/domain/file-element.do.spec.ts create mode 100644 apps/server/src/modules/board/domain/link-element.do.spec.ts create mode 100644 apps/server/src/modules/board/domain/media-board/media-external-tool-element.do.spec.ts create mode 100644 apps/server/src/modules/board/domain/rich-text-element.do.spec.ts create mode 100644 apps/server/src/modules/board/domain/submission-item.do.spec.ts diff --git a/apps/server/src/modules/board/domain/collaborative-text-editor.do.spec.ts b/apps/server/src/modules/board/domain/collaborative-text-editor.do.spec.ts new file mode 100644 index 00000000000..d4f46c4fea5 --- /dev/null +++ b/apps/server/src/modules/board/domain/collaborative-text-editor.do.spec.ts @@ -0,0 +1,35 @@ +import { CollaborativeTextEditorElement, isCollaborativeTextEditorElement } from './collaborative-text-editor.do'; +import { BoardNodeProps } from './types'; + +describe('CollaborativeTextEditorElement', () => { + let collaborativeTextEditorElement: CollaborativeTextEditorElement; + + const boardNodeProps: BoardNodeProps = { + id: '1', + path: '', + level: 1, + position: 1, + children: [], + createdAt: new Date(), + updatedAt: new Date(), + }; + + beforeEach(() => { + collaborativeTextEditorElement = new CollaborativeTextEditorElement({ + ...boardNodeProps, + children: [], + }); + }); + + it('should be instance of CollaborativeTextEditorElement', () => { + expect(isCollaborativeTextEditorElement(collaborativeTextEditorElement)).toBe(true); + }); + + it('should not be instance of CollaborativeTextEditorElement', () => { + expect(isCollaborativeTextEditorElement({})).toBe(false); + }); + + it('should not have child', () => { + expect(collaborativeTextEditorElement.canHaveChild()).toBe(false); + }); +}); diff --git a/apps/server/src/modules/board/domain/drawing-element.do.spec.ts b/apps/server/src/modules/board/domain/drawing-element.do.spec.ts new file mode 100644 index 00000000000..7f21bf50375 --- /dev/null +++ b/apps/server/src/modules/board/domain/drawing-element.do.spec.ts @@ -0,0 +1,44 @@ +import { DrawingElement, isDrawingElement } from './drawing-element.do'; +import { BoardNodeProps } from './types'; + +describe('DrawingElement', () => { + let drawingElement: DrawingElement; + + const boardNodeProps: BoardNodeProps = { + id: '1', + path: '', + level: 1, + position: 1, + children: [], + createdAt: new Date(), + updatedAt: new Date(), + }; + + beforeEach(() => { + drawingElement = new DrawingElement({ + ...boardNodeProps, + description: 'Test description', + }); + }); + + it('should be instance of DrawingElement', () => { + expect(isDrawingElement(drawingElement)).toBe(true); + }); + + it('should not be instance of DrawingElement', () => { + expect(isDrawingElement({})).toBe(false); + }); + + it('should return description', () => { + expect(drawingElement.description).toBe('Test description'); + }); + + it('should set description', () => { + drawingElement.description = 'New description'; + expect(drawingElement.description).toBe('New description'); + }); + + it('should not have child', () => { + expect(drawingElement.canHaveChild()).toBe(false); + }); +}); diff --git a/apps/server/src/modules/board/domain/external-tool-element.do.spec.ts b/apps/server/src/modules/board/domain/external-tool-element.do.spec.ts new file mode 100644 index 00000000000..d4058b76fc9 --- /dev/null +++ b/apps/server/src/modules/board/domain/external-tool-element.do.spec.ts @@ -0,0 +1,44 @@ +import { ExternalToolElement, isExternalToolElement } from './external-tool-element.do'; +import { BoardNodeProps } from './types'; + +describe('ExternalToolElement', () => { + let externalToolElement: ExternalToolElement; + + const boardNodeProps: BoardNodeProps = { + id: '1', + path: '', + level: 1, + position: 1, + children: [], + createdAt: new Date(), + updatedAt: new Date(), + }; + + beforeEach(() => { + externalToolElement = new ExternalToolElement({ + ...boardNodeProps, + contextExternalToolId: 'test-id', + }); + }); + + it('should be instance of ExternalToolElement', () => { + expect(isExternalToolElement(externalToolElement)).toBe(true); + }); + + it('should not be instance of ExternalToolElement', () => { + expect(isExternalToolElement({})).toBe(false); + }); + + it('should return contextExternalToolId', () => { + expect(externalToolElement.contextExternalToolId).toBe('test-id'); + }); + + it('should set contextExternalToolId', () => { + externalToolElement.contextExternalToolId = 'new-id'; + expect(externalToolElement.contextExternalToolId).toBe('new-id'); + }); + + it('should not have child', () => { + expect(externalToolElement.canHaveChild()).toBe(false); + }); +}); diff --git a/apps/server/src/modules/board/domain/file-element.do.spec.ts b/apps/server/src/modules/board/domain/file-element.do.spec.ts new file mode 100644 index 00000000000..31a93ec48cd --- /dev/null +++ b/apps/server/src/modules/board/domain/file-element.do.spec.ts @@ -0,0 +1,54 @@ +import { FileElement, isFileElement } from './file-element.do'; +import { BoardNodeProps } from './types'; + +describe('FileElement', () => { + let fileElement: FileElement; + + const boardNodeProps: BoardNodeProps = { + id: '1', + path: '', + level: 1, + position: 1, + children: [], + createdAt: new Date(), + updatedAt: new Date(), + }; + + beforeEach(() => { + fileElement = new FileElement({ + ...boardNodeProps, + alternativeText: 'Test alt text', + caption: 'Test caption', + }); + }); + + it('should be instance of FileElement', () => { + expect(isFileElement(fileElement)).toBe(true); + }); + + it('should not be instance of FileElement', () => { + expect(isFileElement({})).toBe(false); + }); + + it('should return alternativeText', () => { + expect(fileElement.alternativeText).toBe('Test alt text'); + }); + + it('should set alternativeText', () => { + fileElement.alternativeText = 'New alt text'; + expect(fileElement.alternativeText).toBe('New alt text'); + }); + + it('should return caption', () => { + expect(fileElement.caption).toBe('Test caption'); + }); + + it('should set caption', () => { + fileElement.caption = 'New caption'; + expect(fileElement.caption).toBe('New caption'); + }); + + it('should not have child', () => { + expect(fileElement.canHaveChild()).toBe(false); + }); +}); diff --git a/apps/server/src/modules/board/domain/link-element.do.spec.ts b/apps/server/src/modules/board/domain/link-element.do.spec.ts new file mode 100644 index 00000000000..c900cdba889 --- /dev/null +++ b/apps/server/src/modules/board/domain/link-element.do.spec.ts @@ -0,0 +1,74 @@ +import { LinkElement, isLinkElement } from './link-element.do'; +import { BoardNodeProps } from './types/board-node-props'; + +describe('LinkElement', () => { + let linkElement: LinkElement; + + const boardNodeProps: BoardNodeProps = { + id: '1', + path: '', + level: 1, + position: 1, + children: [], + createdAt: new Date(), + updatedAt: new Date(), + }; + + beforeEach(() => { + linkElement = new LinkElement({ + ...boardNodeProps, + url: 'https://example.com', + title: 'Example', + description: 'Example description', + imageUrl: 'https://example.com/image.jpg', + }); + }); + + it('should be instance of LinkElement', () => { + expect(isLinkElement(linkElement)).toBe(true); + }); + + it('should not be instance of LinkElement', () => { + expect(isLinkElement({})).toBe(false); + }); + + it('should return url', () => { + expect(linkElement.url).toBe('https://example.com'); + }); + + it('should set url', () => { + linkElement.url = 'https://newurl.com'; + expect(linkElement.url).toBe('https://newurl.com'); + }); + + it('should return title', () => { + expect(linkElement.title).toBe('Example'); + }); + + it('should set title', () => { + linkElement.title = 'New title'; + expect(linkElement.title).toBe('New title'); + }); + + it('should return description', () => { + expect(linkElement.description).toBe('Example description'); + }); + + it('should set description', () => { + linkElement.description = 'New description'; + expect(linkElement.description).toBe('New description'); + }); + + it('should return imageUrl', () => { + expect(linkElement.imageUrl).toBe('https://example.com/image.jpg'); + }); + + it('should set imageUrl', () => { + linkElement.imageUrl = 'https://newurl.com/newimage.jpg'; + expect(linkElement.imageUrl).toBe('https://newurl.com/newimage.jpg'); + }); + + it('should not have child', () => { + expect(linkElement.canHaveChild()).toBe(false); + }); +}); diff --git a/apps/server/src/modules/board/domain/media-board/media-external-tool-element.do.spec.ts b/apps/server/src/modules/board/domain/media-board/media-external-tool-element.do.spec.ts new file mode 100644 index 00000000000..d5e0642107b --- /dev/null +++ b/apps/server/src/modules/board/domain/media-board/media-external-tool-element.do.spec.ts @@ -0,0 +1,39 @@ +import { MediaExternalToolElement, isMediaExternalToolElement } from './media-external-tool-element.do'; +import { BoardNodeProps } from '../types'; + +describe('MediaExternalToolElement', () => { + let mediaExternalToolElement: MediaExternalToolElement; + + const boardNodeProps: BoardNodeProps = { + id: '1', + path: '', + level: 1, + position: 1, + children: [], + createdAt: new Date(), + updatedAt: new Date(), + }; + + beforeEach(() => { + mediaExternalToolElement = new MediaExternalToolElement({ + ...boardNodeProps, + contextExternalToolId: 'test-id', + }); + }); + + it('should be instance of MediaExternalToolElement', () => { + expect(isMediaExternalToolElement(mediaExternalToolElement)).toBe(true); + }); + + it('should not be instance of MediaExternalToolElement', () => { + expect(isMediaExternalToolElement({})).toBe(false); + }); + + it('should return contextExternalToolId', () => { + expect(mediaExternalToolElement.contextExternalToolId).toBe('test-id'); + }); + + it('should not have child', () => { + expect(mediaExternalToolElement.canHaveChild()).toBe(false); + }); +}); diff --git a/apps/server/src/modules/board/domain/rich-text-element.do.spec.ts b/apps/server/src/modules/board/domain/rich-text-element.do.spec.ts new file mode 100644 index 00000000000..8996839e930 --- /dev/null +++ b/apps/server/src/modules/board/domain/rich-text-element.do.spec.ts @@ -0,0 +1,55 @@ +import { InputFormat } from '@shared/domain/types'; +import { RichTextElement, isRichTextElement } from './rich-text-element.do'; +import { BoardNodeProps } from './types'; + +describe('RichTextElement', () => { + let richTextElement: RichTextElement; + + const boardNodeProps: BoardNodeProps = { + id: '1', + path: '', + level: 1, + position: 1, + children: [], + createdAt: new Date(), + updatedAt: new Date(), + }; + + beforeEach(() => { + richTextElement = new RichTextElement({ + ...boardNodeProps, + text: 'Test text', + inputFormat: InputFormat.RICH_TEXT_CK5, + }); + }); + + it('should be instance of RichTextElement', () => { + expect(isRichTextElement(richTextElement)).toBe(true); + }); + + it('should not be instance of RichTextElement', () => { + expect(isRichTextElement({})).toBe(false); + }); + + it('should return text', () => { + expect(richTextElement.text).toBe('Test text'); + }); + + it('should set text', () => { + richTextElement.text = 'New text'; + expect(richTextElement.text).toBe('New text'); + }); + + it('should return inputFormat', () => { + expect(richTextElement.inputFormat).toBe(InputFormat.RICH_TEXT_CK5); + }); + + it('should set inputFormat', () => { + richTextElement.inputFormat = InputFormat.PLAIN_TEXT; + expect(richTextElement.inputFormat).toBe(InputFormat.PLAIN_TEXT); + }); + + it('should not have child', () => { + expect(richTextElement.canHaveChild()).toBe(false); + }); +}); diff --git a/apps/server/src/modules/board/domain/submission-item.do.spec.ts b/apps/server/src/modules/board/domain/submission-item.do.spec.ts new file mode 100644 index 00000000000..df9316708bd --- /dev/null +++ b/apps/server/src/modules/board/domain/submission-item.do.spec.ts @@ -0,0 +1,87 @@ +import { SubmissionItem } from './submission-item.do'; +import { BoardNodeProps } from './types'; +import { fileElementFactory, linkElementFactory, richTextElementFactory } from '../testing'; + +describe('SubmissionItem', () => { + const boardNodeProps: BoardNodeProps = { + id: '1', + path: '', + level: 1, + position: 1, + children: [], + createdAt: new Date(), + updatedAt: new Date(), + }; + + describe('constructor', () => { + it('should create an instance of SubmissionItem', () => { + const submissionItem = new SubmissionItem({ ...boardNodeProps, completed: false, userId: '' }); + expect(submissionItem).toBeInstanceOf(SubmissionItem); + }); + }); + + describe('canHaveChild', () => { + const setup = () => { + const submissionItem = new SubmissionItem({ ...boardNodeProps, completed: false, userId: '' }); + + const linkElement = linkElementFactory.build(); + const fileElement = fileElementFactory.build(); + const richTextElement = richTextElementFactory.build(); + + return { submissionItem, linkElement, fileElement, richTextElement }; + }; + + it('should return true for RichTextElement child', () => { + const { submissionItem, richTextElement } = setup(); + + const result = submissionItem.canHaveChild(richTextElement); + + expect(result).toBe(true); + }); + + it('should return true for FileElement child', () => { + const { submissionItem, fileElement } = setup(); + + const result = submissionItem.canHaveChild(fileElement); + + expect(result).toBe(true); + }); + + it('should return false for non-RichTextElement and non-FileElement child', () => { + const { submissionItem, linkElement } = setup(); + + const result = submissionItem.canHaveChild(linkElement); + + expect(result).toBe(false); + }); + }); + + describe('completed property', () => { + it('should get completed prop', () => { + const submissionItem = new SubmissionItem({ ...boardNodeProps, completed: false, userId: '' }); + expect(submissionItem.completed).toBe(false); + }); + + it('should set completed prop', () => { + const submissionItem = new SubmissionItem({ ...boardNodeProps, completed: false, userId: '' }); + + submissionItem.completed = true; + expect(submissionItem.completed).toBe(true); + }); + }); + + describe('userId property', () => { + it('should get userId', () => { + const submissionItem = new SubmissionItem({ ...boardNodeProps, completed: false, userId: '' }); + expect(submissionItem.userId).toBe(''); + }); + + it('should set userId', () => { + const submissionItem = new SubmissionItem({ ...boardNodeProps, completed: false, userId: '' }); + + const userId = 'testUserId'; + submissionItem.userId = userId; + expect(submissionItem.userId).toBe(userId); + }); + }); +});