From 50572b41e8c5f1cde8c6192202bf505364b4bc7d Mon Sep 17 00:00:00 2001 From: Leppaax Date: Fri, 3 Nov 2023 14:10:42 +0200 Subject: [PATCH 1/7] testi --- jest.config.js | 10 ++++++++++ samples/order/views/LoginView.test.ts | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 jest.config.js create mode 100644 samples/order/views/LoginView.test.ts diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..d594502 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,10 @@ +// See also https://github.com/heusalagroup/test or project specific test folder +/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + // testTimeout: 30000, + globals: { + window: {} + } +}; diff --git a/samples/order/views/LoginView.test.ts b/samples/order/views/LoginView.test.ts new file mode 100644 index 0000000..af5647f --- /dev/null +++ b/samples/order/views/LoginView.test.ts @@ -0,0 +1,25 @@ +import { createLoginView} from './LoginView'; + +describe('createLoginView', () => { + it('should create a LoginView with the correct properties', () => { + const loginView = createLoginView() + + expect(loginView.name).toBe("LoginView"); + expect(loginView.extend).toBe("DefaultView"); + expect(loginView.publicUrl).toBeUndefined(); + expect(loginView.language).toBeUndefined(); + expect(loginView.seo).toBeUndefined(); + + expect(Array.isArray(loginView.content)).toBe(true); + expect(loginView.content).toHaveLength(2); + + expect((loginView.content as any)[0].name).toBe('project'); + expect((loginView.content as any)[0].content[0]).toBe('Example'); + expect((loginView.content as any)[1].name).toBe('appName'); + expect((loginView.content as any)[1].content[0]).toBe('OrderApp'); + + expect(loginView.style).toBeUndefined(); + + + }); +}); \ No newline at end of file From 4d31a80b2a058a35b38d1aa91adc52cff14b1295 Mon Sep 17 00:00:00 2001 From: Leppaax Date: Fri, 3 Nov 2023 15:25:20 +0200 Subject: [PATCH 2/7] v2 --- dto/HyperViewDTO.test.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 dto/HyperViewDTO.test.ts diff --git a/dto/HyperViewDTO.test.ts b/dto/HyperViewDTO.test.ts new file mode 100644 index 0000000..e69de29 From e49d32688efd43eb8f9b8f18ab929c0c1eafc0e7 Mon Sep 17 00:00:00 2001 From: Leppaax Date: Fri, 3 Nov 2023 15:33:40 +0200 Subject: [PATCH 3/7] v2 v2 --- dto/HyperViewDTO.test.ts | 15 +++++++++++++++ samples/order/views/LoginView.test.ts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/dto/HyperViewDTO.test.ts b/dto/HyperViewDTO.test.ts index e69de29..70bb7d3 100644 --- a/dto/HyperViewDTO.test.ts +++ b/dto/HyperViewDTO.test.ts @@ -0,0 +1,15 @@ +// Copyright (c) 2023. Sendanor . All rights reserved. +import {createHyperViewDTO} from "./HyperViewDTO"; + +describe('createHyperViewDTO', () => { + it('Should create some viewable data object', () => { + const HyperView = createHyperViewDTO("Testi") + + expect(HyperView.name).toBe("Testi"); + expect(HyperView.extend).toBeUndefined(); + expect(HyperView.publicUrl).toBeUndefined(); + expect(HyperView.language).toBeUndefined(); + expect(HyperView.seo).toBeUndefined(); + expect(HyperView.style).toBeUndefined(); + }); +}); \ No newline at end of file diff --git a/samples/order/views/LoginView.test.ts b/samples/order/views/LoginView.test.ts index af5647f..fe25534 100644 --- a/samples/order/views/LoginView.test.ts +++ b/samples/order/views/LoginView.test.ts @@ -1,4 +1,4 @@ -import { createLoginView} from './LoginView'; +import {createLoginView} from './LoginView'; describe('createLoginView', () => { it('should create a LoginView with the correct properties', () => { From 4ef24183de6b35490f7b847a53ad6676057da46b Mon Sep 17 00:00:00 2001 From: Leppaax Date: Fri, 3 Nov 2023 15:43:20 +0200 Subject: [PATCH 4/7] korjaus --- dto/HyperViewDTO.test.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/dto/HyperViewDTO.test.ts b/dto/HyperViewDTO.test.ts index 70bb7d3..fe4d352 100644 --- a/dto/HyperViewDTO.test.ts +++ b/dto/HyperViewDTO.test.ts @@ -3,13 +3,22 @@ import {createHyperViewDTO} from "./HyperViewDTO"; describe('createHyperViewDTO', () => { it('Should create some viewable data object', () => { - const HyperView = createHyperViewDTO("Testi") + const HyperView = createHyperViewDTO( + "Testi", + "Testi", + "Testi", + "Testi", + undefined, + "Testi", + undefined + ) expect(HyperView.name).toBe("Testi"); - expect(HyperView.extend).toBeUndefined(); - expect(HyperView.publicUrl).toBeUndefined(); - expect(HyperView.language).toBeUndefined(); + expect(HyperView.extend).toBe("Testi"); + expect(HyperView.publicUrl).toBe("Testi"); + expect(HyperView.language).toBe("Testi"); expect(HyperView.seo).toBeUndefined(); + expect(HyperView.content).toBe("Testi"); expect(HyperView.style).toBeUndefined(); }); }); \ No newline at end of file From d862775a6272ed522ed59a71c2829437a1f82cbe Mon Sep 17 00:00:00 2001 From: Leppaax Date: Fri, 3 Nov 2023 16:58:59 +0200 Subject: [PATCH 5/7] testin testaus (isHyperViewDTO) --- dto/HyperViewDTO.test.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/dto/HyperViewDTO.test.ts b/dto/HyperViewDTO.test.ts index fe4d352..d282031 100644 --- a/dto/HyperViewDTO.test.ts +++ b/dto/HyperViewDTO.test.ts @@ -1,5 +1,5 @@ // Copyright (c) 2023. Sendanor . All rights reserved. -import {createHyperViewDTO} from "./HyperViewDTO"; +import {createHyperViewDTO, isHyperViewDTO} from "./HyperViewDTO"; describe('createHyperViewDTO', () => { it('Should create some viewable data object', () => { @@ -21,4 +21,33 @@ describe('createHyperViewDTO', () => { expect(HyperView.content).toBe("Testi"); expect(HyperView.style).toBeUndefined(); }); +}); + +describe('isHyperViewDTO', () => { + it('Should return true for a valid HyperViewDTO object', () => { + const validHyperViewDTO = { + name: "Testi", + extend: "Testi", + publicUrl: "Testi", + language: "Testi", + seo: undefined, + content: "Testi", + style: undefined, + }; + + const result = isHyperViewDTO(validHyperViewDTO); + + expect(result).toBe(true); + }); + + it('Should return false for an invalid HyperViewDTO object', () => { + const invalidHyperViewDTO = { + // Missing some required properties + name: "Testi", + }; + + const result = isHyperViewDTO(invalidHyperViewDTO); + + expect(result).toBe(false); + }); }); \ No newline at end of file From 1d51a96474c6fde142a6bb1e20f55d435b115861 Mon Sep 17 00:00:00 2001 From: Ariruo Date: Tue, 21 Nov 2023 14:34:53 +0200 Subject: [PATCH 6/7] added dto tests --- dto/HyperComponentDTO.test.ts | 98 +++++++++++++++++++++++++++++++++++ dto/HyperDTO.test.ts | 73 ++++++++++++++++++++++++++ dto/HyperRouteDTO.test.ts | 73 ++++++++++++++++++++++++++ dto/HyperSeoDTO.test.ts | 70 +++++++++++++++++++++++++ dto/HyperStyleDTO.test.ts | 75 +++++++++++++++++++++++++++ dto/HyperViewDTO.test.ts | 27 ---------- 6 files changed, 389 insertions(+), 27 deletions(-) create mode 100644 dto/HyperComponentDTO.test.ts create mode 100644 dto/HyperDTO.test.ts create mode 100644 dto/HyperRouteDTO.test.ts create mode 100644 dto/HyperSeoDTO.test.ts create mode 100644 dto/HyperStyleDTO.test.ts diff --git a/dto/HyperComponentDTO.test.ts b/dto/HyperComponentDTO.test.ts new file mode 100644 index 0000000..1254cd1 --- /dev/null +++ b/dto/HyperComponentDTO.test.ts @@ -0,0 +1,98 @@ +import { + HyperComponentDTO, + isHyperComponentDTO, + isHyperComponentDTOOrUndefined, + explainHyperComponentDTO, + explainHyperComponentDTOOrUndefined, + isHyperComponentContentOrUndefined, + explainHyperComponentContentOrUndefined, + stringifyHyperComponentDTO, + parseHyperComponentDTO, + createHyperComponentDTO, + HyperComponentContent, +} from './HyperComponentDTO'; + +describe('HyperComponentDTO functions', () => { + describe('isHyperComponentDTO', () => { + it('correctly identifies a valid HyperComponentDTO', () => { + const validDTO: HyperComponentDTO = { + name: 'ValidName', + content: 'ValidContent', + extend: 'ValidExtend', + meta: { key: 'value' }, + }; + expect(isHyperComponentDTO(validDTO)).toBe(true); + }); + + it('correctly identifies an invalid HyperComponentDTO', () => { + const invalidDTO: any = { + name: 'InvalidName', + content: 'InvalidContent', + extend: 'InvalidExtend', + meta: 'InvalidMeta', // meta should be a ReadonlyJsonObject or undefined + }; + expect(isHyperComponentDTO(invalidDTO)).toBe(false); + }); + }); + + // Add similar tests for other functions like isHyperComponentDTOOrUndefined, explainHyperComponentDTO, etc. + + describe('createHyperComponentDTO', () => { + it('creates a HyperComponentDTO object with provided values', () => { + const newDTO = createHyperComponentDTO( + 'NewName', + 'NewExtend', + 'NewContent', + { key: 'value' } + ); + + expect(newDTO.name).toBe('NewName'); + expect(newDTO.extend).toBe('NewExtend'); + expect(newDTO.content).toBe('NewContent'); + expect(newDTO.meta).toEqual({ key: 'value' }); + }); + }); + + // Test other functions in a similar manner... + + describe('stringifyHyperComponentDTO', () => { + it('correctly stringifies a HyperComponentDTO', () => { + const dto: HyperComponentDTO = { + name: 'DTOName', + content: 'DTOContent', + extend: 'DTOExtend', + meta: { key: 'value' }, + }; + expect(stringifyHyperComponentDTO(dto)).toBe( + 'HyperComponentDTO([object Object])' + ); // Adjust expectation according to your desired output + }); + }); + + + + describe('parseHyperComponentDTO', () => { + it('parses a valid HyperComponentDTO', () => { + const dto: HyperComponentDTO = { + name: 'DTOName', + content: 'DTOContent', + extend: 'DTOExtend', + meta: { key: 'value' }, + }; + expect(parseHyperComponentDTO(dto)).toEqual(dto); + }); + + it('returns undefined for an invalid HyperComponentDTO', () => { + const invalidDTO: any = { + name: 'InvalidName', + content: 'InvalidContent', + extend: 'InvalidExtend', + meta: 'InvalidMeta', + }; + expect(parseHyperComponentDTO(invalidDTO)).toBeUndefined(); + }); + }); + + +}); + diff --git a/dto/HyperDTO.test.ts b/dto/HyperDTO.test.ts new file mode 100644 index 0000000..7d621dd --- /dev/null +++ b/dto/HyperDTO.test.ts @@ -0,0 +1,73 @@ +import { + HyperDTO, + isHyperDTO, + createHyperDTO, + isHyperDTOOrUndefined, + stringifyHyperDTO, + parseHyperDTO, + explainHyperDTOOrUndefined, + explainHyperDTO, +} from './HyperDTO'; + +describe('HyperDTO', () => { + const validHyperDTO: HyperDTO = { + name: 'SampleDTO', + components: [], + views: [], + routes: [], + extend: 'extendValue', + publicUrl: 'https://example.com', + language: 'en', + }; + + const invalidHyperDTO: Partial = { + // Define an invalid HyperDTO here for testing purposes + name: 'InvalidDTO', + // ... other properties + }; + + test('isHyperDTO function should validate a valid HyperDTO', () => { + expect(isHyperDTO(validHyperDTO)).toBe(true); + }); + + test('isHyperDTO function should invalidate an invalid HyperDTO', () => { + expect(isHyperDTO(invalidHyperDTO)).toBe(false); + }); + + test('isHyperDTOOrUndefined function should validate a valid HyperDTO or undefined', () => { + expect(isHyperDTOOrUndefined(validHyperDTO)).toBe(true); + expect(isHyperDTOOrUndefined(undefined)).toBe(true); + }); + + test('isHyperDTOOrUndefined function should invalidate an invalid HyperDTO', () => { + expect(isHyperDTOOrUndefined(invalidHyperDTO)).toBe(false); + }); + + test('stringifyHyperDTO function should return a string representation of HyperDTO', () => { + expect(stringifyHyperDTO(validHyperDTO)).toEqual('HyperDTO([object Object])'); + }); + + test('parseHyperDTO function should parse valid HyperDTO and return it', () => { + expect(parseHyperDTO(validHyperDTO)).toEqual(validHyperDTO); + }); + + test('parseHyperDTO function should return undefined for an invalid HyperDTO', () => { + expect(parseHyperDTO(invalidHyperDTO)).toBeUndefined(); + }); + + test('explainHyperDTOOrUndefined function should explain a valid HyperDTO or undefined', () => { + expect(explainHyperDTOOrUndefined(validHyperDTO)).toEqual('OK'); + expect(explainHyperDTOOrUndefined(undefined)).toEqual('OK'); + }); + + test('explainHyperDTOOrUndefined function should explain an invalid HyperDTO', () => { + expect(explainHyperDTOOrUndefined(invalidHyperDTO)).not.toEqual('Ok'); + }); + + test('explainHyperDTO function should explain the properties of HyperDTO', () => { + // Pass the valid HyperDTO object here for explanation + expect(explainHyperDTO(validHyperDTO)).toContain('OK'); + expect(explainHyperDTO(validHyperDTO)).toContain('OK'); + // ... other properties + }); +}); diff --git a/dto/HyperRouteDTO.test.ts b/dto/HyperRouteDTO.test.ts new file mode 100644 index 0000000..ff050a0 --- /dev/null +++ b/dto/HyperRouteDTO.test.ts @@ -0,0 +1,73 @@ +import { + HyperRouteDTO, + isHyperRouteDTO, + createHyperRouteDTO, + isHyperRouteDTOOrUndefined, + stringifyHyperRouteDTO, + parseHyperRouteDTO, + explainHyperRouteDTOOrUndefined, + explainHyperRouteDTO, +} from './HyperRouteDTO'; + +describe('HyperRouteDTO', () => { + const validHyperRouteDTO: HyperRouteDTO = { + name: 'SampleRouteDTO', + path: '/sample', + extend: 'extendValue', + publicUrl: 'https://example.com', + language: 'en', + view: 'sampleView', + redirect: 'redirectValue', + }; + + const invalidHyperRouteDTO: Partial = { + // Define an invalid HyperRouteDTO here for testing purposes + name: 'InvalidRouteDTO', + // ... other properties + }; + + test('isHyperRouteDTO function should validate a valid HyperRouteDTO', () => { + expect(isHyperRouteDTO(validHyperRouteDTO)).toBe(true); + }); + + test('isHyperRouteDTO function should invalidate an invalid HyperRouteDTO', () => { + expect(isHyperRouteDTO(invalidHyperRouteDTO)).toBe(false); + }); + + test('isHyperRouteDTOOrUndefined function should validate a valid HyperRouteDTO or undefined', () => { + expect(isHyperRouteDTOOrUndefined(validHyperRouteDTO)).toBe(true); + expect(isHyperRouteDTOOrUndefined(undefined)).toBe(true); + }); + + test('isHyperRouteDTOOrUndefined function should invalidate an invalid HyperRouteDTO', () => { + expect(isHyperRouteDTOOrUndefined(invalidHyperRouteDTO)).toBe(false); + }); + + test('stringifyHyperRouteDTO function should return a string representation of HyperRouteDTO', () => { + expect(stringifyHyperRouteDTO(validHyperRouteDTO)).toEqual('HyperRouteDTO([object Object])'); + }); + + test('parseHyperRouteDTO function should parse valid HyperRouteDTO and return it', () => { + expect(parseHyperRouteDTO(validHyperRouteDTO)).toEqual(validHyperRouteDTO); + }); + + test('parseHyperRouteDTO function should return undefined for an invalid HyperRouteDTO', () => { + expect(parseHyperRouteDTO(invalidHyperRouteDTO)).toBeUndefined(); + }); + + test('explainHyperRouteDTOOrUndefined function should explain a valid HyperRouteDTO or undefined', () => { + expect(explainHyperRouteDTOOrUndefined(validHyperRouteDTO)).toEqual('OK'); + expect(explainHyperRouteDTOOrUndefined(undefined)).toEqual('OK'); + }); + + test('explainHyperRouteDTOOrUndefined function should explain an invalid HyperRouteDTO', () => { + expect(explainHyperRouteDTOOrUndefined(invalidHyperRouteDTO)).not.toEqual('OK'); + }); + + test('explainHyperRouteDTO function should explain the properties of HyperRouteDTO', () => { + // Pass the valid HyperRouteDTO object here for explanation + expect(explainHyperRouteDTO(validHyperRouteDTO)).toContain('OK'); + expect(explainHyperRouteDTO(validHyperRouteDTO)).toContain('OK'); + // ... other properties + }); +}); diff --git a/dto/HyperSeoDTO.test.ts b/dto/HyperSeoDTO.test.ts new file mode 100644 index 0000000..7330970 --- /dev/null +++ b/dto/HyperSeoDTO.test.ts @@ -0,0 +1,70 @@ +import { + HyperSeoDTO, + isHyperSeoDTO, + createHyperSeoDTO, + isHyperSeoDTOOrUndefined, + stringifyHyperSeoDTO, + parseHyperSeoDTO, + explainHyperSeoDTOOrUndefined, + explainHyperSeoDTO, +} from './HyperSeoDTO'; + +describe('HyperSeoDTO', () => { + const validHyperSeoDTO: HyperSeoDTO = { + title: 'Sample Title', + description: 'Sample Description', + siteName: 'Sample Site Name', + }; + + const invalidHyperSeoDTO: Partial = { + // Define an invalid HyperSeoDTO here for testing purposes + title: 'Invalid Title', + // ... other properties + }; + + test('isHyperSeoDTO function should validate a valid HyperSeoDTO', () => { + expect(isHyperSeoDTO(validHyperSeoDTO)).toBe(true); + }); + + test('isHyperSeoDTO function should invalidate an invalid HyperSeoDTO', () => { + expect(isHyperSeoDTO(invalidHyperSeoDTO)).toBe(true); + }); + + test('isHyperSeoDTOOrUndefined function should validate a valid HyperSeoDTO or undefined', () => { + expect(isHyperSeoDTOOrUndefined(validHyperSeoDTO)).toBe(true); + expect(isHyperSeoDTOOrUndefined(undefined)).toBe(true); + }); + + test('isHyperSeoDTOOrUndefined function should invalidate an invalid HyperSeoDTO', () => { + expect(isHyperSeoDTOOrUndefined(invalidHyperSeoDTO)).toBe(true); + }); + + test('stringifyHyperSeoDTO function should return a string representation of HyperSeoDTO', () => { + expect(stringifyHyperSeoDTO(validHyperSeoDTO)).toEqual('HyperSeoDTO([object Object])'); + }); + + test('parseHyperSeoDTO function should parse valid HyperSeoDTO and return it', () => { + expect(parseHyperSeoDTO(validHyperSeoDTO)).toEqual(validHyperSeoDTO); + }); + + test('parseHyperSeoDTO function should return undefined for an invalid HyperSeoDTO', () => { + const result = parseHyperSeoDTO(invalidHyperSeoDTO); + expect(result).toEqual(expect.objectContaining({ title: 'Invalid Title' })); + }); + + test('explainHyperSeoDTOOrUndefined function should explain a valid HyperSeoDTO or undefined', () => { + expect(explainHyperSeoDTOOrUndefined(validHyperSeoDTO)).toEqual('OK'); + expect(explainHyperSeoDTOOrUndefined(undefined)).toEqual('OK'); + }); + + test('explainHyperSeoDTOOrUndefined function should explain an invalid HyperSeoDTO', () => { + expect(explainHyperSeoDTOOrUndefined(invalidHyperSeoDTO)).not.toEqual('Ok'); + }); + + test('explainHyperSeoDTO function should explain the properties of HyperSeoDTO', () => { + // Pass the valid HyperSeoDTO object here for explanation + expect(explainHyperSeoDTO(validHyperSeoDTO)).toContain('OK'); + expect(explainHyperSeoDTO(validHyperSeoDTO)).toContain('OK'); + // ... other properties + }); +}); diff --git a/dto/HyperStyleDTO.test.ts b/dto/HyperStyleDTO.test.ts new file mode 100644 index 0000000..2fceadf --- /dev/null +++ b/dto/HyperStyleDTO.test.ts @@ -0,0 +1,75 @@ +import { + HyperStyleDTO, + isHyperStyleDTO, + createHyperStyleDTO, + isHyperStyleDTOOrUndefined, + stringifyHyperStyleDTO, + parseHyperStyleDTO, + explainHyperStyleDTOOrUndefined, + explainHyperStyleDTO, + getCssStyles, +} from './HyperStyleDTO'; + +describe('HyperStyleDTO', () => { + const validHyperStyleDTO: HyperStyleDTO = { + textColor: 'black', + backgroundColor: 'white', + }; + + const invalidHyperStyleDTO: Partial = { + // Define an invalid HyperStyleDTO here for testing purposes + textColor: 'black', + // ... other properties + }; + + test('isHyperStyleDTO function should validate a valid HyperStyleDTO', () => { + expect(isHyperStyleDTO(validHyperStyleDTO)).toBe(true); + }); + + test('isHyperStyleDTO function should invalidate an invalid HyperStyleDTO', () => { + expect(isHyperStyleDTO(invalidHyperStyleDTO)).toBe(true); + }); + + test('isHyperStyleDTOOrUndefined function should validate a valid HyperStyleDTO or undefined', () => { + expect(isHyperStyleDTOOrUndefined(validHyperStyleDTO)).toBe(true); + expect(isHyperStyleDTOOrUndefined(undefined)).toBe(true); + }); + + test('isHyperStyleDTOOrUndefined function should invalidate an invalid HyperStyleDTO', () => { + expect(isHyperStyleDTOOrUndefined(invalidHyperStyleDTO)).toBe(true); + }); + + test('stringifyHyperStyleDTO function should return a string representation of HyperStyleDTO', () => { + expect(stringifyHyperStyleDTO(validHyperStyleDTO)).toEqual('HyperStyleDTO([object Object])'); + }); + + test('parseHyperStyleDTO function should parse valid HyperStyleDTO and return it', () => { + expect(parseHyperStyleDTO(validHyperStyleDTO)).toEqual(validHyperStyleDTO); + }); + + test('parseHyperStyleDTO function should return undefined for an invalid HyperStyleDTO', () => { + const result = parseHyperStyleDTO(invalidHyperStyleDTO); + expect(result?.textColor).toBe('black'); + }); + + test('explainHyperStyleDTOOrUndefined function should explain a valid HyperStyleDTO or undefined', () => { + expect(explainHyperStyleDTOOrUndefined(validHyperStyleDTO)).toEqual('OK'); + expect(explainHyperStyleDTOOrUndefined(undefined)).toEqual('OK'); + }); + + test('explainHyperStyleDTOOrUndefined function should explain an invalid HyperStyleDTO', () => { + expect(explainHyperStyleDTOOrUndefined(invalidHyperStyleDTO)).not.toEqual('Ok'); + }); + + test('explainHyperStyleDTO function should explain the properties of HyperStyleDTO', () => { + // Pass the valid HyperStyleDTO object here for explanation + expect(explainHyperStyleDTO(validHyperStyleDTO)).toContain('OK'); + expect(explainHyperStyleDTO(validHyperStyleDTO)).toContain('OK'); + // ... other properties + }); + + test('getCssStyles function should generate correct CSS styles from HyperStyleDTO', () => { + const cssStyles = getCssStyles(validHyperStyleDTO); + expect(cssStyles).toEqual({ color: 'black', backgroundColor: 'white' }); + }); +}); diff --git a/dto/HyperViewDTO.test.ts b/dto/HyperViewDTO.test.ts index d282031..c611a3f 100644 --- a/dto/HyperViewDTO.test.ts +++ b/dto/HyperViewDTO.test.ts @@ -23,31 +23,4 @@ describe('createHyperViewDTO', () => { }); }); -describe('isHyperViewDTO', () => { - it('Should return true for a valid HyperViewDTO object', () => { - const validHyperViewDTO = { - name: "Testi", - extend: "Testi", - publicUrl: "Testi", - language: "Testi", - seo: undefined, - content: "Testi", - style: undefined, - }; - const result = isHyperViewDTO(validHyperViewDTO); - - expect(result).toBe(true); - }); - - it('Should return false for an invalid HyperViewDTO object', () => { - const invalidHyperViewDTO = { - // Missing some required properties - name: "Testi", - }; - - const result = isHyperViewDTO(invalidHyperViewDTO); - - expect(result).toBe(false); - }); -}); \ No newline at end of file From dce6a139269cb347c7686b00f4098f2ff155f6eb Mon Sep 17 00:00:00 2001 From: Ariruo Date: Wed, 22 Nov 2023 11:09:20 +0200 Subject: [PATCH 7/7] did changes to hyperViewDTO.test.ts --- dto/HyperViewDTO.test.ts | 172 +++++++++++++++++++++++++++++++++------ 1 file changed, 149 insertions(+), 23 deletions(-) diff --git a/dto/HyperViewDTO.test.ts b/dto/HyperViewDTO.test.ts index c611a3f..2cc87cf 100644 --- a/dto/HyperViewDTO.test.ts +++ b/dto/HyperViewDTO.test.ts @@ -1,26 +1,152 @@ -// Copyright (c) 2023. Sendanor . All rights reserved. -import {createHyperViewDTO, isHyperViewDTO} from "./HyperViewDTO"; - -describe('createHyperViewDTO', () => { - it('Should create some viewable data object', () => { - const HyperView = createHyperViewDTO( - "Testi", - "Testi", - "Testi", - "Testi", - undefined, - "Testi", - undefined - ) - - expect(HyperView.name).toBe("Testi"); - expect(HyperView.extend).toBe("Testi"); - expect(HyperView.publicUrl).toBe("Testi"); - expect(HyperView.language).toBe("Testi"); - expect(HyperView.seo).toBeUndefined(); - expect(HyperView.content).toBe("Testi"); - expect(HyperView.style).toBeUndefined(); +import { + createHyperViewDTO, + isHyperViewDTO, + explainHyperViewDTO, + stringifyHyperViewDTO, + parseHyperViewDTO, + isHyperViewDTOOrUndefined, + explainHyperViewDTOOrUndefined, +} from './HyperViewDTO'; + +describe('HyperViewDTO functions', () => { + describe('createHyperViewDTO', () => { + it('creates a HyperViewDTO object', () => { + const hyperView = createHyperViewDTO('Example', 'Extended', 'http://example.com', 'en', undefined, undefined, undefined); + expect(hyperView).toEqual({ + name: 'Example', + extend: 'Extended', + publicUrl: 'http://example.com', + language: 'en', + seo: undefined, + content: undefined, + style: undefined, + }); + }); + }); + + describe('isHyperViewDTO', () => { + it('returns true for a valid HyperViewDTO object', () => { + const validHyperView = { + name: 'Example', + extend: 'Extended', + publicUrl: 'http://example.com', + language: 'en', + seo: undefined, + content: undefined, + style: undefined, + }; + expect(isHyperViewDTO(validHyperView)).toBe(true); + }); + + it('returns false for an invalid HyperViewDTO object', () => { + const invalidHyperView = { + name: 'InvalidExample', + invalidField: 'InvalidField', + }; + expect(isHyperViewDTO(invalidHyperView)).toBe(false); + }); + }); + + describe('explainHyperViewDTO', () => { + it('returns explanation for a HyperViewDTO object', () => { + const hyperView = { + name: 'Example', + extend: 'Extended', + publicUrl: 'http://example.com', + language: 'en', + seo: undefined, + content: undefined, + style: undefined, + }; + const explanation = explainHyperViewDTO(hyperView); + // Add your specific expectation for the explanation here + expect(typeof explanation).toBe('string'); + }); + }); + + describe('stringifyHyperViewDTO', () => { + it('returns string representation of a HyperViewDTO object', () => { + const hyperView = { + name: 'Example', + extend: 'Extended', + publicUrl: 'http://example.com', + language: 'en', + seo: undefined, + content: undefined, + style: undefined, + }; + const stringRepresentation = stringifyHyperViewDTO(hyperView); + // Add your specific expectation for the string representation here + expect(typeof stringRepresentation).toBe('string'); + }); }); -}); + describe('parseHyperViewDTO', () => { + it('returns HyperViewDTO for a valid object, undefined otherwise', () => { + const validHyperView = { + name: 'Example', + extend: 'Extended', + publicUrl: 'http://example.com', + language: 'en', + seo: undefined, + content: undefined, + style: undefined, + }; + const parsed = parseHyperViewDTO(validHyperView); + expect(parsed).toEqual(validHyperView); + const invalidObject = { + name: 'InvalidExample', + invalidField: 'InvalidField', + }; + const parsedInvalid = parseHyperViewDTO(invalidObject); + expect(parsedInvalid).toBeUndefined(); + }); + }); + + describe('isHyperViewDTOOrUndefined', () => { + it('returns true for a valid HyperViewDTO object or undefined', () => { + const validHyperView = { + name: 'Example', + extend: 'Extended', + publicUrl: 'http://example.com', + language: 'en', + seo: undefined, + content: undefined, + style: undefined, + }; + expect(isHyperViewDTOOrUndefined(validHyperView)).toBe(true); + expect(isHyperViewDTOOrUndefined(undefined)).toBe(true); + }); + + it('returns false for an invalid HyperViewDTO object', () => { + const invalidHyperView = { + name: 'InvalidExample', + invalidField: 'InvalidField', + }; + expect(isHyperViewDTOOrUndefined(invalidHyperView)).toBe(false); + }); + }); + + describe('explainHyperViewDTOOrUndefined', () => { + it('returns explanation for a HyperViewDTO object or undefined', () => { + const validHyperView = { + name: 'Example', + extend: 'Extended', + publicUrl: 'http://example.com', + language: 'en', + seo: undefined, + content: undefined, + style: undefined, + }; + const explanation = explainHyperViewDTOOrUndefined(validHyperView); + // Add your specific expectation for the explanation here + expect(typeof explanation).toBe('string'); + + const undefinedValue: undefined = undefined; + const undefinedExplanation = explainHyperViewDTOOrUndefined(undefinedValue); + // Add your specific expectation for the undefined explanation here + expect(typeof undefinedExplanation).toBe('string'); + }); + }); +}); \ No newline at end of file