|
| 1 | +import { CustomElement } from '../../../../../../src/devcomp/domain/models/element/CustomElement.js'; |
| 2 | +import { DomainError } from '../../../../../../src/shared/domain/errors.js'; |
| 3 | +import { catchErrSync, expect } from '../../../../../test-helper.js'; |
| 4 | + |
| 5 | +describe('Unit | Devcomp | Domain | Models | Element | CustomElement', function () { |
| 6 | + describe('#constructor', function () { |
| 7 | + it('should create a valid CustomElement object', function () { |
| 8 | + // given |
| 9 | + const attributes = { |
| 10 | + id: '5ce0ddf1-8620-43b5-9e43-cd9b2ffaca17', |
| 11 | + tagName: 'qcu-image', |
| 12 | + props: { |
| 13 | + name: "Liste d'applications", |
| 14 | + maxChoicesPerLine: 3, |
| 15 | + imageChoicesSize: 'icon', |
| 16 | + choices: [ |
| 17 | + { |
| 18 | + name: 'Google', |
| 19 | + image: { |
| 20 | + width: 534, |
| 21 | + height: 544, |
| 22 | + loading: 'lazy', |
| 23 | + decoding: 'async', |
| 24 | + src: 'https://epreuves.pix.fr/_astro/Google.B1bcY5Go_1BynY8.svg', |
| 25 | + }, |
| 26 | + }, |
| 27 | + { |
| 28 | + name: 'LibreOffice Writer', |
| 29 | + image: { |
| 30 | + width: 205, |
| 31 | + height: 246, |
| 32 | + loading: 'lazy', |
| 33 | + decoding: 'async', |
| 34 | + src: 'https://epreuves.pix.fr/_astro/writer.3bR8N2DK_Z1iWuJ9.webp', |
| 35 | + }, |
| 36 | + }, |
| 37 | + { |
| 38 | + name: 'Explorateur', |
| 39 | + image: { |
| 40 | + width: 128, |
| 41 | + height: 128, |
| 42 | + loading: 'lazy', |
| 43 | + decoding: 'async', |
| 44 | + src: 'https://epreuves.pix.fr/_astro/windows-file-explorer.CnF8MYwI_23driA.webp', |
| 45 | + }, |
| 46 | + }, |
| 47 | + { |
| 48 | + name: 'Geogebra', |
| 49 | + image: { |
| 50 | + width: 640, |
| 51 | + height: 640, |
| 52 | + loading: 'lazy', |
| 53 | + decoding: 'async', |
| 54 | + src: 'https://epreuves.pix.fr/_astro/geogebra.CZH9VYqc_19v4nj.webp', |
| 55 | + }, |
| 56 | + }, |
| 57 | + ], |
| 58 | + }, |
| 59 | + }; |
| 60 | + |
| 61 | + // when |
| 62 | + const result = new CustomElement(attributes); |
| 63 | + |
| 64 | + // then |
| 65 | + expect(result.id).to.equal(attributes.id); |
| 66 | + expect(result.tagName).to.equal(attributes.tagName); |
| 67 | + expect(result.props).to.deep.equal(attributes.props); |
| 68 | + expect(result.type).to.equal('custom'); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + describe('A CustomElement without a tagName', function () { |
| 73 | + it('should throw an error', function () { |
| 74 | + const attributes = { |
| 75 | + id: '5ce0ddf1-8620-43b5-9e43-cd9b2ffaca17', |
| 76 | + }; |
| 77 | + // when |
| 78 | + const error = catchErrSync(() => new CustomElement(attributes))(); |
| 79 | + |
| 80 | + // then |
| 81 | + expect(error).to.be.instanceOf(DomainError); |
| 82 | + expect(error.message).to.equal('The tagName is required for an CustomElement element'); |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + describe('A CustomElement without props', function () { |
| 87 | + it('should throw an error', function () { |
| 88 | + const attributes = { |
| 89 | + id: '5ce0ddf1-8620-43b5-9e43-cd9b2ffaca17', |
| 90 | + tagName: 'qcu-image', |
| 91 | + }; |
| 92 | + // when |
| 93 | + const error = catchErrSync(() => new CustomElement(attributes))(); |
| 94 | + |
| 95 | + // then |
| 96 | + expect(error).to.be.instanceOf(DomainError); |
| 97 | + expect(error.message).to.equal('The props are required for an CustomElement element'); |
| 98 | + }); |
| 99 | + }); |
| 100 | +}); |
0 commit comments