Skip to content
Snippets Groups Projects
Verified Commit 0473b7bf authored by Sebastian Bergandy's avatar Sebastian Bergandy :keyboard:
Browse files

OZG-5977 add missing tests

parent 48fefe20
Branches
Tags
1 merge request!67OZG-5977 add multi option to file upload button
import { BinaryFile2ContainerComponent, BinaryFileModule } from '@alfa-client/binary-file';
import { BinaryFileResource } from '@alfa-client/binary-file-shared'; import { BinaryFileResource } from '@alfa-client/binary-file-shared';
import { createEmptyStateResource, createErrorStateResource, createStateResource } from '@alfa-client/tech-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 { ComponentFixture, TestBed } from '@angular/core/testing';
import { expect } from '@jest/globals'; import { expect } from '@jest/globals';
import { AttachmentComponent } from '@ods/system';
import { MockComponent } from 'ng-mocks';
import { import {
createBinaryFileResource, createBinaryFileResource,
createLoadingBinaryFileStateResource, createLoadingBinaryFileStateResource,
...@@ -21,8 +29,8 @@ describe('MultiFileUploadListItemComponent', () => { ...@@ -21,8 +29,8 @@ describe('MultiFileUploadListItemComponent', () => {
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [MultiFileUploadListItemComponent], imports: [MultiFileUploadListItemComponent, BinaryFileModule],
// declarations: [MockComponent(BinaryFile2ContainerComponent)], declarations: [MockComponent(BinaryFile2ContainerComponent)],
}).compileComponents(); }).compileComponents();
fixture = TestBed.createComponent(MultiFileUploadListItemComponent); fixture = TestBed.createComponent(MultiFileUploadListItemComponent);
...@@ -52,8 +60,7 @@ describe('MultiFileUploadListItemComponent', () => { ...@@ -52,8 +60,7 @@ describe('MultiFileUploadListItemComponent', () => {
}); });
}); });
// TODO: testing standalone components with mocked components describe('template', () => {
xdescribe('template', () => {
const file: File = createFile(); const file: File = createFile();
beforeEach(() => { beforeEach(() => {
...@@ -77,13 +84,73 @@ describe('MultiFileUploadListItemComponent', () => { ...@@ -77,13 +84,73 @@ describe('MultiFileUploadListItemComponent', () => {
existsAsHtmlElement(fixture, attachmentTestId); existsAsHtmlElement(fixture, attachmentTestId);
}); });
it('should not exists on loaded', () => { it('should NOT exists on loaded', () => {
component.uploadStateResource = createStateResource(createBinaryFileResource()); component.uploadStateResource = createStateResource(createBinaryFileResource());
fixture.detectChanges(); fixture.detectChanges();
notExistsAsHtmlElement(fixture, attachmentTestId); 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);
});
});
});
}); });
}); });
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment