diff --git a/projects/sbb-esta/angular-public/src/lib/file-selector/file-selector/file-selector.component.spec.ts b/projects/sbb-esta/angular-public/src/lib/file-selector/file-selector/file-selector.component.spec.ts
index 8fa1521123..97608511d6 100644
--- a/projects/sbb-esta/angular-public/src/lib/file-selector/file-selector/file-selector.component.spec.ts
+++ b/projects/sbb-esta/angular-public/src/lib/file-selector/file-selector/file-selector.component.spec.ts
@@ -1,5 +1,6 @@
-import { Component } from '@angular/core';
+import { ChangeDetectorRef, Component } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
+import { FormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { configureTestSuite } from 'ng-bullet';
@@ -84,7 +85,7 @@ const testFileList: File[] = [
@Component({
selector: 'sbb-file-test',
template: `
-
+
`
})
class FileSelectorTestComponent {
@@ -131,7 +132,6 @@ describe('FileSelectorComponent using mock component', () => {
const fileComponent = fixture.debugElement.query(By.directive(FileSelectorComponent));
fileComponent.componentInstance.applyChanges(testFileList);
-
fixture.detectChanges();
const filesItems = fileComponent.queryAll(By.css('.sbb-file-selector-list > li'));
@@ -203,3 +203,53 @@ describe('FileSelectorComponent using mock component', () => {
expect(typeIconWrapper[9].query(By.css('sbb-icon-document-zip'))).toBeTruthy();
});
});
+
+@Component({
+ selector: 'sbb-file-selector-test2',
+ template: `
+
+ `
+})
+class FileSelectorTest2Component {
+ files: File[] = [];
+
+ onFileChange(files: File[]) {
+ if (!files[0]) {
+ return;
+ }
+ this.files = [];
+ }
+}
+
+describe('FileSelectorComponent using mock component and limited behaviour ', () => {
+ let fileSelectorTest2Component: FileSelectorTest2Component;
+ let fixtureFileSelectorTest2: ComponentFixture;
+
+ configureTestSuite(() => {
+ TestBed.configureTestingModule({
+ imports: [FileSelectorModule, FormsModule],
+ declarations: [FileSelectorTest2Component]
+ });
+ });
+
+ beforeEach(() => {
+ fixtureFileSelectorTest2 = TestBed.createComponent(FileSelectorTest2Component);
+ fileSelectorTest2Component = fixtureFileSelectorTest2.componentInstance;
+ fixtureFileSelectorTest2.detectChanges();
+ });
+
+ it('component test is created', async () => {
+ expect(fileSelectorTest2Component).toBeTruthy();
+ });
+
+ it('should call onFileChanged event and have length of li elements equals to 0', () => {
+ const oneElement = testFileList.slice(0, 1);
+ const fileComponent = fixtureFileSelectorTest2.debugElement.query(
+ By.directive(FileSelectorComponent)
+ );
+ const cd: ChangeDetectorRef = fileComponent.componentInstance._changeDetector;
+ spyOn(cd, 'detectChanges');
+ fileComponent.componentInstance.applyChanges(oneElement);
+ expect(cd.detectChanges).toHaveBeenCalled();
+ });
+});
diff --git a/projects/sbb-esta/angular-public/src/lib/file-selector/file-selector/file-selector.component.ts b/projects/sbb-esta/angular-public/src/lib/file-selector/file-selector/file-selector.component.ts
index b3e69fdf2a..aa766995cf 100644
--- a/projects/sbb-esta/angular-public/src/lib/file-selector/file-selector/file-selector.component.ts
+++ b/projects/sbb-esta/angular-public/src/lib/file-selector/file-selector/file-selector.component.ts
@@ -110,6 +110,7 @@ export class FileSelectorComponent implements ControlValueAccessor, FileSelector
writeValue(value: any) {
this.filesList = value;
+ this._changeDetector.detectChanges();
}
registerOnChange(fn: any) {
this.onChange = fn;