From 56e4f838644fa6ee6ba8e23a907474c37eb21eb5 Mon Sep 17 00:00:00 2001 From: Miska Vivolin <78149945+MiskaVivolin@users.noreply.github.com> Date: Tue, 21 Nov 2023 16:24:25 +0200 Subject: [PATCH 01/10] Delete jest.config.js --- jest.config.js | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 jest.config.js diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 4ebbfc3..0000000 --- a/jest.config.js +++ /dev/null @@ -1,10 +0,0 @@ -// 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: {} - } -}; From 5637daabf9dfd3e714669b93795d79fb6b6aab6a Mon Sep 17 00:00:00 2001 From: Leppaax Date: Fri, 3 Nov 2023 14:10:42 +0200 Subject: [PATCH 02/10] 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 1b7712c8f7225f28b58c8cd43b56e059faf23636 Mon Sep 17 00:00:00 2001 From: Leppaax Date: Fri, 3 Nov 2023 15:25:20 +0200 Subject: [PATCH 03/10] 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 943aca71085c086f7c242bf283b4ec099cbcf9fc Mon Sep 17 00:00:00 2001 From: Leppaax Date: Fri, 3 Nov 2023 15:33:40 +0200 Subject: [PATCH 04/10] 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 407dfe9c15c230c2edddd9c8887194c10b18ed90 Mon Sep 17 00:00:00 2001 From: Leppaax Date: Fri, 3 Nov 2023 15:43:20 +0200 Subject: [PATCH 05/10] 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 bb2f44c5711ea848c843d39a0bfc0652a0710524 Mon Sep 17 00:00:00 2001 From: Leppaax Date: Fri, 3 Nov 2023 16:58:59 +0200 Subject: [PATCH 06/10] 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 6f2160e25d7ac5c692346f86a8c6192eb908e695 Mon Sep 17 00:00:00 2001 From: Miska Date: Tue, 21 Nov 2023 15:42:48 +0200 Subject: [PATCH 07/10] added tests for several functions --- samples/loading/LoadingAppDefinition.test.ts | 42 +++++++++++++ samples/loading/components/Text.test.ts | 15 +++++ .../loading/components/TextComponent.test.ts | 12 ++++ samples/loading/routes/AnyRoute.test.ts | 23 +++++++ samples/loading/routes/LoadingRoute.test.ts | 15 +++++ samples/loading/views/DefaultView.test.ts | 15 +++++ samples/loading/views/LoadingView.test.ts | 21 +++++++ samples/order/OrderAppDefinition.test.ts | 29 +++++++++ samples/order/components/Text.test.ts | 15 +++++ .../order/components/TextComponent.test.ts | 12 ++++ samples/order/routes/AnyRoute.test.ts | 23 +++++++ samples/order/routes/LoginRoute.test.ts | 16 +++++ samples/order/views/DefaultView.test.ts | 15 +++++ samples/order/views/LoginView.test.ts | 31 ++++------ utils/components/mergeHyperComponent.test.ts | 28 +++++++++ .../populateHyperComponentDTO.test.ts | 60 +++++++++++++++++++ .../views/findAndPopulateHyperViewDTO.test.ts | 1 + 17 files changed, 355 insertions(+), 18 deletions(-) create mode 100644 samples/loading/LoadingAppDefinition.test.ts create mode 100644 samples/loading/components/Text.test.ts create mode 100644 samples/loading/components/TextComponent.test.ts create mode 100644 samples/loading/routes/AnyRoute.test.ts create mode 100644 samples/loading/routes/LoadingRoute.test.ts create mode 100644 samples/loading/views/DefaultView.test.ts create mode 100644 samples/loading/views/LoadingView.test.ts create mode 100644 samples/order/OrderAppDefinition.test.ts create mode 100644 samples/order/components/Text.test.ts create mode 100644 samples/order/components/TextComponent.test.ts create mode 100644 samples/order/routes/AnyRoute.test.ts create mode 100644 samples/order/routes/LoginRoute.test.ts create mode 100644 samples/order/views/DefaultView.test.ts create mode 100644 utils/components/mergeHyperComponent.test.ts create mode 100644 utils/components/populateHyperComponentDTO.test.ts diff --git a/samples/loading/LoadingAppDefinition.test.ts b/samples/loading/LoadingAppDefinition.test.ts new file mode 100644 index 0000000..66ca7bf --- /dev/null +++ b/samples/loading/LoadingAppDefinition.test.ts @@ -0,0 +1,42 @@ +import { createLoadingAppDefinition, LOADING_ROUTE_NAME } from './LoadingAppDefinition'; +import { createAnyRoute } from './routes/AnyRoute'; +import { createLoadingRoute } from './routes/LoadingRoute'; +import { createTextComponent } from './components/TextComponent'; +import { createDefaultView } from './views/DefaultView'; +import { createLoadingView } from './views/LoadingView'; + +describe('createLoadingAppDefinition', () => { + test('creates a valid LoadingAppDefinition HyperDTO', () => { + const myAppName = 'MyLoadingApp'; + const publicUrl = 'mockPublicUrl'; + const language = 'en'; + + const loadingAppDefinition = createLoadingAppDefinition(myAppName, publicUrl, language); + + expect(loadingAppDefinition).toBeDefined(); + expect(loadingAppDefinition.name).toBe(myAppName); + expect(loadingAppDefinition.routes).toBeDefined(); + expect(loadingAppDefinition.routes.length).toBe(2); // Assuming 2 routes are added + + const expectedLoadingRoute = createLoadingRoute(LOADING_ROUTE_NAME); + const expectedAnyRoute = createAnyRoute(LOADING_ROUTE_NAME); + + expect(loadingAppDefinition.routes).toContainEqual(expectedLoadingRoute); + expect(loadingAppDefinition.routes).toContainEqual(expectedAnyRoute); + + expect(loadingAppDefinition.publicUrl).toBe(publicUrl); + expect(loadingAppDefinition.language).toBe(language); + expect(loadingAppDefinition.components).toBeDefined(); + expect(loadingAppDefinition.components.length).toBe(1); // Assuming 1 component is added + expect(loadingAppDefinition.views).toBeDefined(); + expect(loadingAppDefinition.views.length).toBe(2); // Assuming 2 views are added + + const expectedTextComponent = createTextComponent(); + const expectedDefaultView = createDefaultView(); + const expectedLoadingView = createLoadingView(); + + expect(loadingAppDefinition.components).toContainEqual(expectedTextComponent); + expect(loadingAppDefinition.views).toContainEqual(expectedDefaultView); + expect(loadingAppDefinition.views).toContainEqual(expectedLoadingView); + }); +}); \ No newline at end of file diff --git a/samples/loading/components/Text.test.ts b/samples/loading/components/Text.test.ts new file mode 100644 index 0000000..74ee009 --- /dev/null +++ b/samples/loading/components/Text.test.ts @@ -0,0 +1,15 @@ +import { createText } from './Text'; + +describe('createText', () => { + test('creates a valid Text HyperComponentDTO', () => { + const name = 'SampleText'; + const textContent = 'This is some sample text.'; + + const textComponent = createText(name, textContent); + + expect(textComponent).toBeDefined(); + expect(textComponent.name).toBe(name); + expect(textComponent.content).toEqual([textContent]); + expect(textComponent.meta).toBe(undefined); + }); +}); \ No newline at end of file diff --git a/samples/loading/components/TextComponent.test.ts b/samples/loading/components/TextComponent.test.ts new file mode 100644 index 0000000..e0d40b7 --- /dev/null +++ b/samples/loading/components/TextComponent.test.ts @@ -0,0 +1,12 @@ +import { createTextComponent, TEXT_COMPONENT_NAME } from './TextComponent'; + +describe('createTextComponent', () => { + test('creates a valid TextComponent HyperComponentDTO', () => { + const textComponent = createTextComponent(); + + expect(textComponent).toBeDefined(); + expect(textComponent.name).toBe(TEXT_COMPONENT_NAME); + expect(textComponent.content).toEqual([]); + expect(textComponent.meta).toBe(undefined); + }); +}); \ No newline at end of file diff --git a/samples/loading/routes/AnyRoute.test.ts b/samples/loading/routes/AnyRoute.test.ts new file mode 100644 index 0000000..1d992a0 --- /dev/null +++ b/samples/loading/routes/AnyRoute.test.ts @@ -0,0 +1,23 @@ +import { createAnyRoute, ANY_ROUTE_NAME } from './AnyRoute'; + +describe('createAnyRoute', () => { + test('creates a valid AnyRoute HyperRouteDTO with redirect', () => { + const redirect = '/some-redirect-path'; + + const anyRoute = createAnyRoute(redirect); + + expect(anyRoute).toBeDefined(); + expect(anyRoute.name).toBe(ANY_ROUTE_NAME); + expect(anyRoute.path).toBe('*'); + expect(anyRoute.redirect).toBe(redirect); + }); + + test('creates a valid AnyRoute HyperRouteDTO without redirect', () => { + const anyRoute = createAnyRoute(''); + + expect(anyRoute).toBeDefined(); + expect(anyRoute.name).toBe(ANY_ROUTE_NAME); + expect(anyRoute.path).toBe('*'); + expect(anyRoute.redirect).toBe(""); + }); +}); \ No newline at end of file diff --git a/samples/loading/routes/LoadingRoute.test.ts b/samples/loading/routes/LoadingRoute.test.ts new file mode 100644 index 0000000..3c19047 --- /dev/null +++ b/samples/loading/routes/LoadingRoute.test.ts @@ -0,0 +1,15 @@ +import { createLoadingRoute } from './LoadingRoute'; +import { createHyperRouteDTO, HyperRouteDTO } from '../../../dto/HyperRouteDTO'; + +describe('createLoadingRoute', () => { + test('creates a valid LoadingRoute HyperRouteDTO', () => { + const routeName = 'LoadingRoute'; + + const loadingRoute = createLoadingRoute(routeName); + + expect(loadingRoute).toBeDefined(); + expect(loadingRoute.name).toBe(routeName); + expect(loadingRoute.path).toBe('/'); + expect(loadingRoute.redirect).toBeUndefined(); + }); +}); \ No newline at end of file diff --git a/samples/loading/views/DefaultView.test.ts b/samples/loading/views/DefaultView.test.ts new file mode 100644 index 0000000..9394628 --- /dev/null +++ b/samples/loading/views/DefaultView.test.ts @@ -0,0 +1,15 @@ +import { createDefaultView, DEFAULT_VIEW_NAME } from './DefaultView'; +import { createHyperStyleDTO, HyperStyleDTO } from '../../../dto/HyperStyleDTO'; +import { DARK_BACKGROUND_COLOR, DARK_TEXT_COLOR } from '../constants/colors'; + +describe('createDefaultView', () => { + test('creates a valid DefaultView HyperViewDTO', () => { + const defaultView = createDefaultView(); + + expect(defaultView).toBeDefined(); + expect(defaultView.name).toBe(DEFAULT_VIEW_NAME); + + const expectedStyle: HyperStyleDTO = createHyperStyleDTO(DARK_TEXT_COLOR, DARK_BACKGROUND_COLOR); + expect(defaultView.style).toEqual(expectedStyle); + }); +}); \ No newline at end of file diff --git a/samples/loading/views/LoadingView.test.ts b/samples/loading/views/LoadingView.test.ts new file mode 100644 index 0000000..ea717f1 --- /dev/null +++ b/samples/loading/views/LoadingView.test.ts @@ -0,0 +1,21 @@ +import { createLoadingView, LOADING_VIEW_NAME } from './LoadingView'; +import { createText } from '../components/Text'; + +describe('createLoadingView', () => { + test('creates a valid LoadingView HyperViewDTO', () => { + const loadingView = createLoadingView(); + + expect(loadingView).toBeDefined(); + expect(loadingView.name).toBe(LOADING_VIEW_NAME); + + expect(loadingView.content).toBeDefined(); + expect(Array.isArray(loadingView.content)).toBe(true); + + if (Array.isArray(loadingView.content) && loadingView.content.length > 0) { + const expectedTextComponent = createText('loadingText', '...loading...'); + expect(loadingView.content[0]).toEqual(expectedTextComponent); + } else { + console.warn('LoadingView content is undefined or empty'); + } + }); +}); \ No newline at end of file diff --git a/samples/order/OrderAppDefinition.test.ts b/samples/order/OrderAppDefinition.test.ts new file mode 100644 index 0000000..2af807d --- /dev/null +++ b/samples/order/OrderAppDefinition.test.ts @@ -0,0 +1,29 @@ +import { createOrderAppDefinitions } from './OrderAppDefinition'; +import { createAnyRoute } from './routes/AnyRoute'; +import { createLoginRoute } from './routes/LoginRoute'; +import { createTextComponent } from './components/TextComponent'; +import { createDefaultView } from './views/DefaultView'; +import { createLoginView } from './views/LoginView'; + +describe('createOrderAppDefinitions', () => { + test('creates a valid OrderAppDefinition HyperDTO', () => { + const myAppName = 'MyOrderApp'; + const publicUrl = 'http://example.com'; + const language = 'en'; + + const orderAppDefinitions = createOrderAppDefinitions(myAppName, publicUrl, language); + + expect(orderAppDefinitions).toBeDefined(); + expect(orderAppDefinitions.name).toBe(myAppName); + + const expectedLoginRoute = createLoginRoute('LoginRoute'); + const expectedAnyRoute = createAnyRoute('LoginRoute'); + expect(orderAppDefinitions.routes).toEqual([expectedLoginRoute, expectedAnyRoute]); + + const expectedTextComponent = createTextComponent(); + const expectedDefaultView = createDefaultView(); + const expectedLoginView = createLoginView(); + expect(orderAppDefinitions.components).toEqual([expectedTextComponent]); + expect(orderAppDefinitions.views).toEqual([expectedDefaultView, expectedLoginView]); + }); +}); \ No newline at end of file diff --git a/samples/order/components/Text.test.ts b/samples/order/components/Text.test.ts new file mode 100644 index 0000000..74ee009 --- /dev/null +++ b/samples/order/components/Text.test.ts @@ -0,0 +1,15 @@ +import { createText } from './Text'; + +describe('createText', () => { + test('creates a valid Text HyperComponentDTO', () => { + const name = 'SampleText'; + const textContent = 'This is some sample text.'; + + const textComponent = createText(name, textContent); + + expect(textComponent).toBeDefined(); + expect(textComponent.name).toBe(name); + expect(textComponent.content).toEqual([textContent]); + expect(textComponent.meta).toBe(undefined); + }); +}); \ No newline at end of file diff --git a/samples/order/components/TextComponent.test.ts b/samples/order/components/TextComponent.test.ts new file mode 100644 index 0000000..e0d40b7 --- /dev/null +++ b/samples/order/components/TextComponent.test.ts @@ -0,0 +1,12 @@ +import { createTextComponent, TEXT_COMPONENT_NAME } from './TextComponent'; + +describe('createTextComponent', () => { + test('creates a valid TextComponent HyperComponentDTO', () => { + const textComponent = createTextComponent(); + + expect(textComponent).toBeDefined(); + expect(textComponent.name).toBe(TEXT_COMPONENT_NAME); + expect(textComponent.content).toEqual([]); + expect(textComponent.meta).toBe(undefined); + }); +}); \ No newline at end of file diff --git a/samples/order/routes/AnyRoute.test.ts b/samples/order/routes/AnyRoute.test.ts new file mode 100644 index 0000000..1d992a0 --- /dev/null +++ b/samples/order/routes/AnyRoute.test.ts @@ -0,0 +1,23 @@ +import { createAnyRoute, ANY_ROUTE_NAME } from './AnyRoute'; + +describe('createAnyRoute', () => { + test('creates a valid AnyRoute HyperRouteDTO with redirect', () => { + const redirect = '/some-redirect-path'; + + const anyRoute = createAnyRoute(redirect); + + expect(anyRoute).toBeDefined(); + expect(anyRoute.name).toBe(ANY_ROUTE_NAME); + expect(anyRoute.path).toBe('*'); + expect(anyRoute.redirect).toBe(redirect); + }); + + test('creates a valid AnyRoute HyperRouteDTO without redirect', () => { + const anyRoute = createAnyRoute(''); + + expect(anyRoute).toBeDefined(); + expect(anyRoute.name).toBe(ANY_ROUTE_NAME); + expect(anyRoute.path).toBe('*'); + expect(anyRoute.redirect).toBe(""); + }); +}); \ No newline at end of file diff --git a/samples/order/routes/LoginRoute.test.ts b/samples/order/routes/LoginRoute.test.ts new file mode 100644 index 0000000..23aaa7f --- /dev/null +++ b/samples/order/routes/LoginRoute.test.ts @@ -0,0 +1,16 @@ +import { createLoginRoute, LoginRoute } from './LoginRoute'; +import { createHyperRouteDTO, HyperRouteDTO } from '../../../dto/HyperRouteDTO'; +import { LOGIN_VIEW_NAME } from '../views/LoginView'; + +describe('createLoginRoute', () => { + test('creates a valid LoginRoute HyperRouteDTO', () => { + const routeName = 'LoginRoute'; + + const loginRoute = createLoginRoute(routeName); + + expect(loginRoute).toBeDefined(); + expect(loginRoute.name).toBe(routeName); + expect(loginRoute.path).toBe('/'); + expect(loginRoute.view).toBe(LOGIN_VIEW_NAME); + }); +}); \ No newline at end of file diff --git a/samples/order/views/DefaultView.test.ts b/samples/order/views/DefaultView.test.ts new file mode 100644 index 0000000..74f05c4 --- /dev/null +++ b/samples/order/views/DefaultView.test.ts @@ -0,0 +1,15 @@ +import { createDefaultView } from './DefaultView'; +import { createHyperStyleDTO } from '../../../dto/HyperStyleDTO'; +import { DARK_BACKGROUND_COLOR, DARK_TEXT_COLOR } from '../constants/colors'; + +describe('createDefaultView', () => { + test('creates a valid DefaultView HyperViewDTO', () => { + const defaultView = createDefaultView(); + + expect(defaultView).toBeDefined(); + expect(defaultView.name).toBe('DefaultView'); + + const expectedStyle = createHyperStyleDTO(DARK_TEXT_COLOR, DARK_BACKGROUND_COLOR); + expect(defaultView.style).toEqual(expectedStyle); + }); +}); \ No newline at end of file diff --git a/samples/order/views/LoginView.test.ts b/samples/order/views/LoginView.test.ts index fe25534..10460b7 100644 --- a/samples/order/views/LoginView.test.ts +++ b/samples/order/views/LoginView.test.ts @@ -1,25 +1,20 @@ -import {createLoginView} from './LoginView'; +import { createLoginView} from './LoginView'; +import { createText } from '../components/Text'; +import { DEFAULT_VIEW_NAME } from './DefaultView'; describe('createLoginView', () => { - it('should create a LoginView with the correct properties', () => { - const loginView = createLoginView() + test('creates a valid LoginView HyperViewDTO', () => { + 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(); + expect(loginView).toBeDefined(); + expect(loginView.name).toBe('LoginView'); + const expectedContent = [ + createText('project', 'Example'), + createText('appName', 'OrderApp'), + ]; + expect(loginView.content).toEqual(expectedContent); + expect(loginView.extend).toBe(DEFAULT_VIEW_NAME); }); }); \ No newline at end of file diff --git a/utils/components/mergeHyperComponent.test.ts b/utils/components/mergeHyperComponent.test.ts new file mode 100644 index 0000000..4ff4071 --- /dev/null +++ b/utils/components/mergeHyperComponent.test.ts @@ -0,0 +1,28 @@ +import { mergeHyperComponentContent } from "./mergeHyperComponentContent"; + +describe('mergeHyperComponentContent', () => { + test('merges arrays of strings', () => { + const result = mergeHyperComponentContent(['a', 'b'], ['c', 'd']); + expect(result).toEqual(['a', 'b', 'c', 'd']); + }); + + test('merges arrays of HyperComponentDTO', () => { + const componentA = { type: 'exampleA', /* other properties */ } as any; + const componentB = { type: 'exampleB', /* other properties */ } as any; + + const result = mergeHyperComponentContent([componentA], [componentB]); + expect(result).toEqual([componentA, componentB]); + }); + + test('merges arrays of strings and HyperComponentDTO', () => { + const component = { type: 'example', /* other properties */ } as any; + + const result = mergeHyperComponentContent(['a', 'b'], [component]); + expect(result).toEqual(['a', 'b', component]); + }); + + test('handles undefined inputs', () => { + const result = mergeHyperComponentContent(undefined, undefined); + expect(result).toEqual([]); + }); +}); diff --git a/utils/components/populateHyperComponentDTO.test.ts b/utils/components/populateHyperComponentDTO.test.ts new file mode 100644 index 0000000..e8710ff --- /dev/null +++ b/utils/components/populateHyperComponentDTO.test.ts @@ -0,0 +1,60 @@ +import { populateHyperComponentDTO } from "./populateHyperComponentDTO"; +import { HyperComponentDTO, } from "../../dto/HyperComponentDTO"; + +describe('populateHyperComponentDTO', () => { + test('returns the same component if extend is undefined', () => { + const component: HyperComponentDTO = { + name: 'TestComponent', + content: ['a', 'b'], + meta: { key: 'value' }, + }; + + const components: HyperComponentDTO[] = []; + + const result = populateHyperComponentDTO(component, components); + expect(result).toEqual(component); + }); + + test('returns a new component with extended content', () => { + const extendComponent: HyperComponentDTO = { + name: 'ExtendComponent', + content: ['c', 'd'], + meta: { otherKey: 'otherValue' }, + }; + + const component: HyperComponentDTO = { + name: 'TestComponent', + extend: 'ExtendComponent', + content: ['a', 'b'], + meta: { key: 'value' }, + }; + + const components: HyperComponentDTO[] = [extendComponent]; + + const result = populateHyperComponentDTO(component, components); + + const expected: HyperComponentDTO = { + name: 'ExtendComponent', + extend: undefined, + content: ['c', 'd', 'a', 'b'], + meta: { key: 'value', otherKey: 'otherValue' }, + }; + + expect(result).toEqual(expected); + }); + + test('throws error if extend component not found', () => { + const component: HyperComponentDTO = { + name: 'TestComponent', + extend: 'NonExistentComponent', + content: ['a', 'b'], + meta: { key: 'value' }, + }; + + const components: HyperComponentDTO[] = []; + + expect(() => populateHyperComponentDTO(component, components)).toThrowError( + TypeError('Could not find component by name NonExistentComponent to extend for TestComponent') + ); + }); +}); \ No newline at end of file diff --git a/utils/views/findAndPopulateHyperViewDTO.test.ts b/utils/views/findAndPopulateHyperViewDTO.test.ts index 29714e3..0ef3044 100644 --- a/utils/views/findAndPopulateHyperViewDTO.test.ts +++ b/utils/views/findAndPopulateHyperViewDTO.test.ts @@ -41,3 +41,4 @@ describe('findAndPopulateHyperViewDTO', () => { ); }); }); + From 1b072f40fdfdae312e30cdc4cc1357bc8c58f2b8 Mon Sep 17 00:00:00 2001 From: Miska Date: Tue, 21 Nov 2023 15:57:06 +0200 Subject: [PATCH 08/10] deleted one extra line --- jest.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index d594502..b963126 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,4 +7,4 @@ module.exports = { globals: { window: {} } -}; +}; \ No newline at end of file From 2a224400e5c35d3e336ab8c0289ce30ce028fcb2 Mon Sep 17 00:00:00 2001 From: Miska Date: Tue, 21 Nov 2023 16:27:28 +0200 Subject: [PATCH 09/10] deleted one file --- samples/order/views/LoginView.test.ts | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 samples/order/views/LoginView.test.ts diff --git a/samples/order/views/LoginView.test.ts b/samples/order/views/LoginView.test.ts deleted file mode 100644 index 10460b7..0000000 --- a/samples/order/views/LoginView.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { createLoginView} from './LoginView'; -import { createText } from '../components/Text'; -import { DEFAULT_VIEW_NAME } from './DefaultView'; - -describe('createLoginView', () => { - test('creates a valid LoginView HyperViewDTO', () => { - const loginView = createLoginView(); - - expect(loginView).toBeDefined(); - expect(loginView.name).toBe('LoginView'); - - const expectedContent = [ - createText('project', 'Example'), - createText('appName', 'OrderApp'), - ]; - expect(loginView.content).toEqual(expectedContent); - - expect(loginView.extend).toBe(DEFAULT_VIEW_NAME); - }); -}); \ No newline at end of file From a97486d71728acfe4b0ed2d382ec4576580fe4ed Mon Sep 17 00:00:00 2001 From: Miska Date: Wed, 22 Nov 2023 15:11:24 +0200 Subject: [PATCH 10/10] added LoginView.test.ts --- samples/order/views/LoginView.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 samples/order/views/LoginView.test.ts diff --git a/samples/order/views/LoginView.test.ts b/samples/order/views/LoginView.test.ts new file mode 100644 index 0000000..10460b7 --- /dev/null +++ b/samples/order/views/LoginView.test.ts @@ -0,0 +1,20 @@ +import { createLoginView} from './LoginView'; +import { createText } from '../components/Text'; +import { DEFAULT_VIEW_NAME } from './DefaultView'; + +describe('createLoginView', () => { + test('creates a valid LoginView HyperViewDTO', () => { + const loginView = createLoginView(); + + expect(loginView).toBeDefined(); + expect(loginView.name).toBe('LoginView'); + + const expectedContent = [ + createText('project', 'Example'), + createText('appName', 'OrderApp'), + ]; + expect(loginView.content).toEqual(expectedContent); + + expect(loginView.extend).toBe(DEFAULT_VIEW_NAME); + }); +}); \ No newline at end of file