From 454ab6234a3ec1de11f66b1ccbab529210b823b1 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Tue, 5 Nov 2024 19:53:10 +0100 Subject: [PATCH] Factories tests --- src/wireframes/model/factories.spec.ts | 84 ++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/wireframes/model/factories.spec.ts diff --git a/src/wireframes/model/factories.spec.ts b/src/wireframes/model/factories.spec.ts new file mode 100644 index 0000000..4ecfd0f --- /dev/null +++ b/src/wireframes/model/factories.spec.ts @@ -0,0 +1,84 @@ +/* + * mydraft.cc + * + * @license + * Copyright (c) Sebastian Stehle. All rights reserved. +*/ + +import { ColorConfigurable, NumberConfigurable, SelectionConfigurable, SliderConfigurable, TextConfigurable, ToggleConfigurable } from './configurables'; +import { MinSizeConstraint, SizeConstraint, TextHeightConstraint, TextSizeConstraint } from './constraints'; +import { DefaultConfigurableFactory, DefaultConstraintFactory } from './factories'; + +describe('DefaultConstraintFactory', () => { + const factory = DefaultConstraintFactory.INSTANCE; + + it('should create size constraint', () => { + const constraint = factory.size(); + + expect(constraint).toBeInstanceOf(SizeConstraint); + }); + + it('should create min size constraint', () => { + const constraint = factory.minSize(); + + expect(constraint).toBeInstanceOf(MinSizeConstraint); + }); + + it('should create text height constraint', () => { + const constraint = factory.textHeight(50); + + expect(constraint).toBeInstanceOf(TextHeightConstraint); + }); + + it('should create text size constraint', () => { + const constraint = factory.textSize(50); + + expect(constraint).toBeInstanceOf(TextSizeConstraint); + }); +}); + +describe('DefaultConfigurableFactory', () => { + const factory = DefaultConfigurableFactory.INSTANCE; + + it('should create selection configurable', () => { + const constraint = factory.selection('my-name', 'my-label', ['A', 'B', 'C']); + + expect(constraint).toBeInstanceOf(SelectionConfigurable); + expect(constraint).toEqual({ name: 'my-name', label: 'my-label', options: ['A', 'B', 'C'] }); + }); + + it('should create slider configurable', () => { + const constraint = factory.slider('my-name', 'my-label', 50, 100); + + expect(constraint).toBeInstanceOf(SliderConfigurable); + expect(constraint).toEqual({ name: 'my-name', label: 'my-label', min: 50, max: 100 }); + }); + + it('should create number configurable', () => { + const constraint = factory.number('my-name', 'my-label', 50, 100); + + expect(constraint).toBeInstanceOf(NumberConfigurable); + expect(constraint).toEqual({ name: 'my-name', label: 'my-label', min: 50, max: 100 }); + }); + + it('should create color configurable', () => { + const constraint = factory.color('my-name', 'my-label'); + + expect(constraint).toBeInstanceOf(ColorConfigurable); + expect(constraint).toEqual({ name: 'my-name', label: 'my-label' }); + }); + + it('should create text configurable', () => { + const constraint = factory.text('my-name', 'my-label'); + + expect(constraint).toBeInstanceOf(TextConfigurable); + expect(constraint).toEqual({ name: 'my-name', label: 'my-label' }); + }); + + it('should create toggle configurable', () => { + const constraint = factory.toggle('my-name', 'my-label'); + + expect(constraint).toBeInstanceOf(ToggleConfigurable); + expect(constraint).toEqual({ name: 'my-name', label: 'my-label' }); + }); +}); \ No newline at end of file