From 0473b7bfde3fb22ccf9f1e0d8bdd20f6131c64d4 Mon Sep 17 00:00:00 2001 From: sebo <sebastian.bergandy@external.mgm-cp.com> Date: Mon, 17 Feb 2025 14:49:55 +0100 Subject: [PATCH] OZG-5977 add missing tests --- ...ti-file-upload-list-item.component.spec.ts | 79 +++++++++++++++++-- 1 file changed, 73 insertions(+), 6 deletions(-) diff --git a/alfa-client/libs/design-component/src/lib/form/multi-file-upload-list-container/multi-file-upload-list-item/multi-file-upload-list-item.component.spec.ts b/alfa-client/libs/design-component/src/lib/form/multi-file-upload-list-container/multi-file-upload-list-item/multi-file-upload-list-item.component.spec.ts index 68154b8030..3be9b34667 100644 --- a/alfa-client/libs/design-component/src/lib/form/multi-file-upload-list-container/multi-file-upload-list-item/multi-file-upload-list-item.component.spec.ts +++ b/alfa-client/libs/design-component/src/lib/form/multi-file-upload-list-container/multi-file-upload-list-item/multi-file-upload-list-item.component.spec.ts @@ -1,8 +1,16 @@ +import { BinaryFile2ContainerComponent, BinaryFileModule } from '@alfa-client/binary-file'; import { BinaryFileResource } from '@alfa-client/binary-file-shared'; import { createEmptyStateResource, createErrorStateResource, createStateResource } from '@alfa-client/tech-shared'; -import { existsAsHtmlElement, notExistsAsHtmlElement } from '@alfa-client/test-utils'; +import { + existsAsHtmlElement, + getElementComponentFromFixtureByCss, + notExistsAsHtmlElement, + triggerEvent, +} from '@alfa-client/test-utils'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { expect } from '@jest/globals'; +import { AttachmentComponent } from '@ods/system'; +import { MockComponent } from 'ng-mocks'; import { createBinaryFileResource, createLoadingBinaryFileStateResource, @@ -21,8 +29,8 @@ describe('MultiFileUploadListItemComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [MultiFileUploadListItemComponent], - // declarations: [MockComponent(BinaryFile2ContainerComponent)], + imports: [MultiFileUploadListItemComponent, BinaryFileModule], + declarations: [MockComponent(BinaryFile2ContainerComponent)], }).compileComponents(); fixture = TestBed.createComponent(MultiFileUploadListItemComponent); @@ -52,8 +60,7 @@ describe('MultiFileUploadListItemComponent', () => { }); }); - // TODO: testing standalone components with mocked components - xdescribe('template', () => { + describe('template', () => { const file: File = createFile(); beforeEach(() => { @@ -77,13 +84,73 @@ describe('MultiFileUploadListItemComponent', () => { existsAsHtmlElement(fixture, attachmentTestId); }); - it('should not exists on loaded', () => { + it('should NOT exists on loaded', () => { component.uploadStateResource = createStateResource(createBinaryFileResource()); fixture.detectChanges(); notExistsAsHtmlElement(fixture, attachmentTestId); }); + + it('should have inputs', () => { + component.file = createFile(); + component.uploadStateResource = createEmptyStateResource(true); + + fixture.detectChanges(); + + const attachmentComponent: AttachmentComponent = getElementComponentFromFixtureByCss(fixture, attachmentTestId); + + expect(attachmentComponent.loadingCaption).toEqual(component.file.name); + expect(attachmentComponent.errorMessages).toBeUndefined(); + expect(attachmentComponent.isLoading).toEqual(true); + }); + }); + + describe('uploaded file', () => { + it('should exists', () => { + component.uploadStateResource = createStateResource(createBinaryFileResource()); + + fixture.detectChanges(); + + existsAsHtmlElement(fixture, binaryFileContainerTestId); + }); + + it('should NOT exists', () => { + component.uploadStateResource = createEmptyStateResource(true); + + fixture.detectChanges(); + + notExistsAsHtmlElement(fixture, binaryFileContainerTestId); + }); + + it('should have inputs', () => { + component.uploadStateResource = createStateResource(createBinaryFileResource()); + + fixture.detectChanges(); + + const binaryFileComponent: BinaryFile2ContainerComponent = getElementComponentFromFixtureByCss( + fixture, + binaryFileContainerTestId, + ); + + expect(binaryFileComponent.file).toEqual(component.uploadStateResource.resource); + expect(binaryFileComponent.deletable).toEqual(true); + }); + + describe('output', () => { + describe('startDelete', () => { + it('should call handler', () => { + const binaryFileResource: BinaryFileResource = createBinaryFileResource(); + component.uploadStateResource = createStateResource(binaryFileResource); + component.onDelete = jest.fn(); + fixture.detectChanges(); + + triggerEvent({ fixture, elementSelector: binaryFileContainerTestId, name: 'startDelete', data: binaryFileResource }); + + expect(component.onDelete).toHaveBeenCalledWith(binaryFileResource); + }); + }); + }); }); }); }); -- GitLab