Newer
Older
import { FileUploadListContainerComponent, MultiFileUploadEditorComponent } from '@alfa-client/binary-file';
import { FileUploadType } from '@alfa-client/binary-file-shared';
import { existsAsHtmlElement, getElementComponentFromFixtureByCss } from '@alfa-client/test-utils';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { faker } from '@faker-js/faker/.';
import { expect } from '@jest/globals';
import { Resource } from '@ngxp/rest';
import { MockComponent } from 'ng-mocks';
import { getDataTestIdOf } from '../../../../tech-shared/test/data-test';
import { DummyLinkRel } from '../../../../tech-shared/test/dummy';
import { createDummyResource } from '../../../../tech-shared/test/resource';
import { MultiFileUploadComponent } from './multi-file-upload.component';
describe('OdsMultiFileUploadComponent', () => {
let component: MultiFileUploadComponent;
let fixture: ComponentFixture<MultiFileUploadComponent>;
const fileUploadListTestId: string = getDataTestIdOf('file-list');
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const fileUploadEditorTestId: string = getDataTestIdOf('multi-file-upload-editor');
const fileUploadType: FileUploadType = faker.word.noun();
const uploadLinkRel: string = DummyLinkRel.DUMMY;
const uploadResource: Resource = createDummyResource();
const filesLinkRel: string = DummyLinkRel.DUMMY;
const filesResource: Resource = createDummyResource();
const formFieldsName: string = faker.word.noun();
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MultiFileUploadComponent],
declarations: [MockComponent(MultiFileUploadEditorComponent), MockComponent(FileUploadListContainerComponent)],
}).compileComponents();
fixture = TestBed.createComponent(MultiFileUploadComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
describe('template', () => {
beforeEach(() => {
component.filesFormFieldName = formFieldsName;
component.fileUploadType = fileUploadType;
component.uploadResource = uploadResource;
component.uploadLinkRelation = uploadLinkRel;
component.filesResource = filesResource;
component.filesLinkRelation = filesLinkRel;
});
describe('file upload list', () => {
it('should exists', () => {
existsAsHtmlElement(fixture, fileUploadListTestId);
});
it('should have inputs', () => {
fixture.detectChanges();
const fileUploadListComponent: FileUploadListContainerComponent = getElementComponentFromFixtureByCss(
fixture,
fileUploadListTestId,
);
expect(fileUploadListComponent.parentFormArrayName).toEqual(formFieldsName);
expect(fileUploadListComponent.fileUploadType).toEqual(fileUploadType);
expect(fileUploadListComponent.filesResource).toEqual(filesResource);
expect(fileUploadListComponent.filesLinkRel).toEqual(filesLinkRel);
});
});
describe('file upload editor', () => {
it('should exists', () => {
existsAsHtmlElement(fixture, fileUploadEditorTestId);
});
it('should have inputs', () => {
fixture.detectChanges();
const fileUploadEditorComponent: MultiFileUploadEditorComponent = getElementComponentFromFixtureByCss(
fixture,
fileUploadEditorTestId,
);
expect(fileUploadEditorComponent.fileUploadType).toEqual(fileUploadType);
expect(fileUploadEditorComponent.uploadResource).toEqual(uploadResource);
expect(fileUploadEditorComponent.uploadLinkRelation).toEqual(uploadLinkRel);
});
});
});
});