Skip to content
Snippets Groups Projects
Commit 19ea4185 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2626 OZG-2886 add tests for UserSettingsEmailBenachrichtigungComponent

parent 0b5ba148
Branches
Tags
No related merge requests found
<ng-container *ngIf="(userSettings$ | async)?.resource as userSettings">
<mat-slide-toggle
<mat-slide-toggle data-test-id="toggle-notifications-send-for"
color="primary"
matTooltip="Benachrichtigung per E-Mail bei Eingang eines Antrags"
[checked]="getToggleStatus(userSettings)"
......
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { UiModule } from '@goofy-client/ui';
import { MatRippleModule } from '@angular/material/core';
import { MatMenuModule } from '@angular/material/menu';
import { MatSlideToggle } from '@angular/material/slide-toggle';
import { createStateResource } from '@goofy-client/tech-shared';
import { dispatchEventFromFixture, mock } from '@goofy-client/test-utils';
import { getDataTestIdOf } from 'libs/tech-shared/test/data-test';
import { NotificationsSendFor } from 'libs/user-settings-shared/src/lib/user-settings.model';
import { createUserSettings } from 'libs/user-settings-shared/test/user-settings';
import { createUserSettings, createUserSettingsResource } from 'libs/user-settings-shared/test/user-settings';
import { of } from 'rxjs';
import { EventEmitter } from 'stream';
import { UserSettingsEmailBenachrichtigungComponent } from './user-settings-email-benachrichtigung.component';
describe('UserSettingsEmailBenachrichtigungComponent', () => {
let component: UserSettingsEmailBenachrichtigungComponent;
let fixture: ComponentFixture<UserSettingsEmailBenachrichtigungComponent>;
const toggle: string = getDataTestIdOf('toggle-notifications-send-for');
const userSettings = createUserSettings();
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [UiModule],
declarations: [UserSettingsEmailBenachrichtigungComponent],
imports: [MatMenuModule, MatRippleModule],
declarations: [UserSettingsEmailBenachrichtigungComponent, MatSlideToggle],
}).compileComponents();
fixture = TestBed.createComponent(
UserSettingsEmailBenachrichtigungComponent
);
component = fixture.componentInstance;
component.userSettings$ = of(createStateResource(createUserSettingsResource()));
component.valueChanged = { ...<any>mock(EventEmitter), emit: jest.fn() };
fixture.detectChanges();
});
......@@ -25,9 +38,14 @@ describe('UserSettingsEmailBenachrichtigungComponent', () => {
expect(component).toBeTruthy();
});
describe('toogle status', () => {
const userSettings = createUserSettings();
it('should be checked if userSettings.notificationsSendFor is ALL', () => {
it('should show toggle', () => {
const element = fixture.nativeElement.querySelector(toggle);
expect(element).toBeInstanceOf(HTMLElement);
})
describe('toggle status', () => {
it('should be set if userSettings.notificationsSendFor is ALL', () => {
userSettings.notificationsSendFor = NotificationsSendFor.ALL;
const result: boolean = component.getToggleStatus(userSettings);
......@@ -35,12 +53,18 @@ describe('UserSettingsEmailBenachrichtigungComponent', () => {
expect(result).toBeTruthy();
})
it('should not be checked if userSettings.notificationsSendFor is NONE', () => {
it('should not be set if userSettings.notificationsSendFor is NONE', () => {
userSettings.notificationsSendFor = NotificationsSendFor.NONE;
const result: boolean = component.getToggleStatus(userSettings);
expect(result).toBeFalsy();
})
it('should emit value if toggled', () => {
dispatchEventFromFixture(fixture, toggle, 'change');
expect(component.valueChanged.emit).toHaveBeenCalled();
})
})
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment