Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Created tests for all files except dto folders content #2

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions dto/HyperViewDTO.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2023. Sendanor <[email protected]>. 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();
});
});

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);
});
});
14 changes: 7 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +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: {}
}
};
preset: 'ts-jest',
testEnvironment: 'node',
// testTimeout: 30000,
globals: {
window: {}
}
};
42 changes: 42 additions & 0 deletions samples/loading/LoadingAppDefinition.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
15 changes: 15 additions & 0 deletions samples/loading/components/Text.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
12 changes: 12 additions & 0 deletions samples/loading/components/TextComponent.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
23 changes: 23 additions & 0 deletions samples/loading/routes/AnyRoute.test.ts
Original file line number Diff line number Diff line change
@@ -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("");
});
});
15 changes: 15 additions & 0 deletions samples/loading/routes/LoadingRoute.test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
15 changes: 15 additions & 0 deletions samples/loading/views/DefaultView.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
21 changes: 21 additions & 0 deletions samples/loading/views/LoadingView.test.ts
Original file line number Diff line number Diff line change
@@ -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');
}
});
});
29 changes: 29 additions & 0 deletions samples/order/OrderAppDefinition.test.ts
Original file line number Diff line number Diff line change
@@ -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]);
});
});
15 changes: 15 additions & 0 deletions samples/order/components/Text.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
12 changes: 12 additions & 0 deletions samples/order/components/TextComponent.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
23 changes: 23 additions & 0 deletions samples/order/routes/AnyRoute.test.ts
Original file line number Diff line number Diff line change
@@ -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("");
});
});
16 changes: 16 additions & 0 deletions samples/order/routes/LoginRoute.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
15 changes: 15 additions & 0 deletions samples/order/views/DefaultView.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
20 changes: 20 additions & 0 deletions samples/order/views/LoginView.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading