fix: Fixed test units
This commit is contained in:
@@ -1,14 +1,76 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NotificationsComponent } from './notifications.component';
|
||||
import { AdminCommService } from '../admin-comm.service';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { MatRadioModule } from '@angular/material/radio';
|
||||
import { MatFormFieldControl, MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { Component, forwardRef } from '@angular/core';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { AbstractControlDirective, ControlValueAccessor, FormsModule, NG_VALUE_ACCESSOR, NgControl, ReactiveFormsModule } from '@angular/forms';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
|
||||
@Component({
|
||||
selector: "app-user-search", template: '', providers: [{
|
||||
provide: NG_VALUE_ACCESSOR,
|
||||
useExisting: forwardRef(() => UserSearchStub),
|
||||
multi: true,
|
||||
},
|
||||
{
|
||||
provide: MatFormFieldControl,
|
||||
useExisting: UserSearchStub
|
||||
}]
|
||||
})
|
||||
class UserSearchStub implements ControlValueAccessor, MatFormFieldControl<never> {
|
||||
value: null = null;
|
||||
stateChanges: Observable<void> = of();
|
||||
id: string = "";
|
||||
placeholder: string = "";
|
||||
ngControl: NgControl | AbstractControlDirective | null = null;
|
||||
focused: boolean = false;
|
||||
empty: boolean = true;
|
||||
shouldLabelFloat: boolean = true;
|
||||
required: boolean = false;
|
||||
disabled: boolean = false;
|
||||
errorState: boolean = false;
|
||||
controlType?: string | undefined;
|
||||
autofilled?: boolean | undefined;
|
||||
userAriaDescribedBy?: string | undefined;
|
||||
setDescribedByIds(ids: string[]): void {}
|
||||
onContainerClick(event: MouseEvent): void {}
|
||||
writeValue(obj: any): void {}
|
||||
registerOnChange(fn: any): void {}
|
||||
registerOnTouched(fn: any): void {}
|
||||
setDisabledState?(isDisabled: boolean): void {}
|
||||
}
|
||||
|
||||
describe('NotificationsComponent', () => {
|
||||
let component: NotificationsComponent;
|
||||
let fixture: ComponentFixture<NotificationsComponent>;
|
||||
|
||||
beforeEach(() => {
|
||||
const acMock = {
|
||||
notif: {
|
||||
getGroups: jasmine.createSpy("getGroups").and.returnValue(of())
|
||||
}
|
||||
}
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [NotificationsComponent]
|
||||
declarations: [NotificationsComponent, UserSearchStub],
|
||||
providers: [
|
||||
{provide: AdminCommService, useValue: acMock}
|
||||
],
|
||||
imports: [
|
||||
RouterModule.forRoot([]),
|
||||
MatRadioModule,
|
||||
MatFormFieldModule,
|
||||
MatIconModule,
|
||||
FormsModule,
|
||||
ReactiveFormsModule,
|
||||
MatInputModule,
|
||||
NoopAnimationsModule
|
||||
]
|
||||
});
|
||||
fixture = TestBed.createComponent(NotificationsComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
||||
import { AdminCommService } from '../admin-comm.service';
|
||||
import { Notification } from 'src/app/types/notification';
|
||||
import { Group } from 'src/app/types/group';
|
||||
@@ -14,10 +14,20 @@ import { UserSearchResult } from 'src/app/commonComponents/user-search/user-sear
|
||||
styleUrls: ['./notifications.component.scss']
|
||||
})
|
||||
export class NotificationsComponent implements OnInit, OnDestroy {
|
||||
|
||||
|
||||
groups!: Group[]
|
||||
form = this.fb.group({
|
||||
recp: this.fb.group({
|
||||
uid: this.fb.control<UserSearchResult | null>(null),
|
||||
room: this.fb.control<string|null>(null),
|
||||
group: this.fb.control<string>(''),
|
||||
type: this.fb.control<"room" | "uname" | "group">('uname', {nonNullable: true})
|
||||
}),
|
||||
title: this.fb.control('', {nonNullable: true}),
|
||||
body: this.fb.control('', {nonNullable: true})
|
||||
})
|
||||
|
||||
constructor (private readonly acs: AdminCommService, readonly ls: LocalStorageService, private toolbar: ToolbarService, private router: Router, private route: ActivatedRoute ) {
|
||||
constructor (private readonly acs: AdminCommService, readonly ls: LocalStorageService, private toolbar: ToolbarService, private router: Router, private route: ActivatedRoute, private fb: FormBuilder ) {
|
||||
this.toolbar.comp = this
|
||||
this.toolbar.menu = [
|
||||
{ title: "Wysłane", fn: "outbox", icon: "outbox" }
|
||||
@@ -45,16 +55,6 @@ export class NotificationsComponent implements OnInit, OnDestroy {
|
||||
|
||||
success?: { sent: number; possible: number; };
|
||||
|
||||
form = new FormGroup({
|
||||
recp: new FormGroup({
|
||||
uid: new FormControl<UserSearchResult | null>(null),
|
||||
room: new FormControl<string|null>(null),
|
||||
group: new FormControl<string>(''),
|
||||
type: new FormControl<"room" | "uname" | "group">('uname', {nonNullable: true})
|
||||
}),
|
||||
title: new FormControl('', {nonNullable: true}),
|
||||
body: new FormControl('', {nonNullable: true})
|
||||
})
|
||||
|
||||
submit() {
|
||||
this.acs.notif.send({...this.form.value, recp: {...this.form.get("recp")?.value, uid: this.form.controls['recp'].controls['uid'].value?._id}} as Notification).subscribe((data) => {
|
||||
|
||||
@@ -1,19 +1,32 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { MessageComponent } from './message.component';
|
||||
import { AdminCommService } from 'src/app/admin-view/admin-comm.service';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import * as moment from 'moment';
|
||||
|
||||
describe('MessageComponent', () => {
|
||||
let component: MessageComponent;
|
||||
let fixture: ComponentFixture<MessageComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const acMock = {
|
||||
|
||||
}
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [MessageComponent]
|
||||
declarations: [MessageComponent],
|
||||
providers: [
|
||||
{provide: AdminCommService, useValue: acMock}
|
||||
],
|
||||
imports: [
|
||||
MatCardModule
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(MessageComponent);
|
||||
component = fixture.componentInstance;
|
||||
component.item = {_id: "test", sentDate: moment(), title: "Test"}
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { OutboxComponent } from './outbox.component';
|
||||
import { AdminCommService } from '../../admin-comm.service';
|
||||
import { RouterModule } from '@angular/router';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
describe('OutboxComponent', () => {
|
||||
let component: OutboxComponent;
|
||||
let fixture: ComponentFixture<OutboxComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const acMock = {
|
||||
notif: {
|
||||
outbox: {
|
||||
getSent: jasmine.createSpy("getSent").and.returnValue(of())
|
||||
}
|
||||
}
|
||||
}
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [OutboxComponent]
|
||||
declarations: [OutboxComponent],
|
||||
providers: [
|
||||
{provide: AdminCommService, useValue: acMock}
|
||||
],
|
||||
imports: [
|
||||
RouterModule.forRoot([])
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user