|
| 1 | +import { expect } from 'chai' |
| 2 | +import { describe, it } from 'vitest' |
| 3 | + |
| 4 | +import { PrintLayout, PrintLayoutAttribute } from '@/api/print.api.js' |
| 5 | + |
| 6 | +describe('Print API unit tests', () => { |
| 7 | + describe('PrintLayoutAttribute tests', () => { |
| 8 | + it('Correctly tells that a param is invalid', () => { |
| 9 | + const testInstance = new PrintLayoutAttribute('test', 'String') |
| 10 | + expect(testInstance.isValid).to.be.false |
| 11 | + }) |
| 12 | + it('Tells an attribute is valid if it has a default value', () => { |
| 13 | + const testInstance = new PrintLayoutAttribute('test', 'String', 'default') |
| 14 | + expect(testInstance.isValid).to.be.true |
| 15 | + }) |
| 16 | + it('returns an empty array for scales if no clientInfo is defined', () => { |
| 17 | + const testInstance = new PrintLayoutAttribute('test', 'String') |
| 18 | + expect(testInstance.scales).to.be.an('Array').lengthOf(0) |
| 19 | + }) |
| 20 | + it('returns the scales defined in clientInfo', () => { |
| 21 | + const scales = [1, 2, 3, 4] |
| 22 | + const testInstance = new PrintLayoutAttribute('test', 'String', null, null, { |
| 23 | + scales, |
| 24 | + }) |
| 25 | + expect(testInstance.scales).to.eql(scales) |
| 26 | + }) |
| 27 | + }) |
| 28 | + describe('PrintLayout tests', () => { |
| 29 | + it('Filters out invalid attributes inputs', () => { |
| 30 | + const testInstance = new PrintLayout('test', null, '', undefined, 0) |
| 31 | + expect(testInstance.attributes).to.be.an('Array').lengthOf(0) |
| 32 | + }) |
| 33 | + it('Correctly tells if all attributes are valid', () => { |
| 34 | + const attributeOne = new PrintLayoutAttribute('one', 'Number') |
| 35 | + const attributeTwo = new PrintLayoutAttribute('two', 'String', 'default value') |
| 36 | + const testInstance = new PrintLayout('test', attributeOne, attributeTwo) |
| 37 | + // attribute one requires a value |
| 38 | + expect(testInstance.isReadyToPrint).to.be.false |
| 39 | + |
| 40 | + attributeOne.value = 123 |
| 41 | + expect(testInstance.isReadyToPrint).to.be.true |
| 42 | + }) |
| 43 | + it('gets the scales from the "map" attribute correctly', () => { |
| 44 | + const attributeNotMapWithScales = new PrintLayoutAttribute( |
| 45 | + 'not map', |
| 46 | + 'String', |
| 47 | + null, |
| 48 | + null, |
| 49 | + { scales: [1, 2, 3] } |
| 50 | + ) |
| 51 | + // testing param that aren't "map" but have a scale |
| 52 | + const scalesButNotInMapAttr = new PrintLayout('wrong', attributeNotMapWithScales) |
| 53 | + expect(scalesButNotInMapAttr.scales).to.be.an('Array').lengthOf(0) |
| 54 | + |
| 55 | + const scales = [5, 6, 7] |
| 56 | + const scalesInMapAttr = new PrintLayout( |
| 57 | + 'correct', |
| 58 | + // also adding the wrong attribute here, it should be ignored when gathering scales |
| 59 | + attributeNotMapWithScales, |
| 60 | + new PrintLayoutAttribute('map', null, null, null, { scales }) |
| 61 | + ) |
| 62 | + expect(scalesInMapAttr.scales).to.eql(scales) |
| 63 | + }) |
| 64 | + }) |
| 65 | +}) |
0 commit comments