Skip to content

Commit

Permalink
Fix client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-glombik committed Nov 2, 2024
1 parent 3fa86a3 commit 2f811a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import dayjs from 'dayjs/esm';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { faQuestionCircle, faTimes } from '@fortawesome/free-solid-svg-icons';
import { ACCEPTED_FILE_EXTENSIONS_FILE_BROWSER, ALLOWED_FILE_EXTENSIONS_HUMAN_READABLE } from 'app/shared/constants/file-extensions.constants';
import { Competency, CompetencyLectureUnitLink } from 'app/entities/competency.model';
import { CompetencyLectureUnitLink } from 'app/entities/competency.model';
import { MAX_FILE_SIZE } from 'app/shared/constants/input.constants';
import { toSignal } from '@angular/core/rxjs-interop';

Expand Down Expand Up @@ -62,7 +62,7 @@ export class AttachmentUnitFormComponent implements OnChanges {
releaseDate: [undefined as dayjs.Dayjs | undefined],
version: [{ value: 1, disabled: true }],
updateNotificationText: [undefined as string | undefined, [Validators.maxLength(1000)]],
competencies: [undefined as Competency[] | undefined],
competencyLinks: [undefined as CompetencyLectureUnitLink[] | undefined],
});
private readonly statusChanges = toSignal(this.form.statusChanges ?? 'INVALID');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { TranslateService } from '@ngx-translate/core';
import { AttachmentUnitFormComponent, AttachmentUnitFormData } from 'app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component';
import { FormDateTimePickerComponent } from 'app/shared/date-time-picker/date-time-picker.component';
import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe';
import dayjs from 'dayjs/esm';
import { MockComponent, MockDirective, MockPipe, MockProviders } from 'ng-mocks';
import { MockComponent, MockDirective, MockPipe } from 'ng-mocks';
import { NgbTooltip } from '@ng-bootstrap/ng-bootstrap';
import { CompetencySelectionComponent } from 'app/shared/competency-selection/competency-selection.component';
import { MAX_FILE_SIZE } from 'app/shared/constants/input.constants';
Expand All @@ -25,7 +24,6 @@ describe('AttachmentUnitFormComponent', () => {
MockComponent(FaIconComponent),
MockComponent(CompetencySelectionComponent),
],
providers: [MockProviders(TranslateService)],
schemas: [],
})
.compileComponents()
Expand Down Expand Up @@ -71,7 +69,7 @@ describe('AttachmentUnitFormComponent', () => {
expect(attachmentUnitFormComponent.descriptionControl?.value).toEqual(formData.formProperties.description);
expect(attachmentUnitFormComponent.versionControl?.value).toEqual(formData.formProperties.version);
expect(attachmentUnitFormComponent.updateNotificationTextControl?.value).toEqual(formData.formProperties.updateNotificationText);
expect(attachmentUnitFormComponent.fileName).toEqual(formData.fileProperties.fileName);
expect(attachmentUnitFormComponent.fileName()).toEqual(formData.fileProperties.fileName);
expect(attachmentUnitFormComponent.file).toEqual(formData.fileProperties.file);
});
it('should submit valid form', () => {
Expand All @@ -90,7 +88,7 @@ describe('AttachmentUnitFormComponent', () => {
const fakeFile = new File([''], 'Test-File.pdf', { type: 'application/pdf' });
attachmentUnitFormComponent.file = fakeFile;
const exampleFileName = 'lorem Ipsum';
attachmentUnitFormComponent.fileName = exampleFileName;
attachmentUnitFormComponent.fileName.set(exampleFileName);

attachmentUnitFormComponentFixture.detectChanges();
expect(attachmentUnitFormComponent.form.valid).toBeTrue();
Expand Down Expand Up @@ -132,7 +130,7 @@ describe('AttachmentUnitFormComponent', () => {
attachmentUnitFormComponent.updateNotificationTextControl!.setValue(exampleUpdateNotificationText);
const fakeFile = new File([''], 'Test-File.pdf', { type: 'application/pdf' });
attachmentUnitFormComponent.file = fakeFile;
attachmentUnitFormComponent.fileName = 'lorem Ipsum';
attachmentUnitFormComponent.fileName.set('lorem Ipsum');

expect(attachmentUnitFormComponent.form.invalid).toBeTrue();
const submitFormSpy = jest.spyOn(attachmentUnitFormComponent, 'submitForm');
Expand Down Expand Up @@ -166,7 +164,7 @@ describe('AttachmentUnitFormComponent', () => {
attachmentUnitFormComponentFixture.detectChanges();

const submitButton = attachmentUnitFormComponentFixture.debugElement.nativeElement.querySelector('#submitButton');
expect(attachmentUnitFormComponent.isFileTooBig).toBeTrue();
expect(attachmentUnitFormComponent.isFileTooBig()).toBeTrue();
expect(submitButton.disabled).toBeTrue();
});
});

0 comments on commit 2f811a5

Please sign in to comment.