Skip to content
Snippets Groups Projects
Select Git revision
  • 0e4b5a49d39c72152e5e55381e06fc3458d0ce4e
  • main default protected
  • OZG-8252-gitlab-pipelines
  • release
  • OZG-7856_schadcode_scanner
  • ci-pipeline
  • OZG-7526-signatur-nicht-uebernommen
  • OZG-6223-zip-download-bug
  • OZG-7367-tooltip-extension
  • OZG-7023-OZG-6956-E2E-externe-Stellen
  • OZG-6238-npm-durch-pnpm-ersetzen
  • release-admin
  • release-info
  • OZG-6700-admin-feature-toggle
  • E2E-Updates
  • OZG-7047-tooltips
  • OZG-6957-e2e-fachstellen-oe-daten
  • OZG-7006-ZuarbeitAnfragen
  • temp_OZG-7027
  • unit-tests-hotfix
  • OZG-6731-POC-keycloakResourceService-with-multiple-stateResources
  • 2.27.0
  • 2.26.0
  • 2.25.0
  • 2.24.2
  • 2.24.1
  • 2.24.0
  • 2.23.0
  • 2.22.0
  • 2.21.0
  • 2.20.0
  • 2.21.0-SNAPSHOT
  • 2.19.0
  • 2.18.0
  • 2.17.1
  • 1.3.0
  • release-admin-1.3.0
  • release-info-1.3.0
  • 2.17.0
  • 2.16.0
  • 2.15.0
41 results

user-settings-email-benachrichtigung.component.spec.ts

Blame
  • user-settings-email-benachrichtigung.component.spec.ts 2.53 KiB
    import { ComponentFixture, TestBed } from '@angular/core/testing';
    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, createUserSettingsResource } from 'libs/user-settings-shared/test/user-settings';
    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: [MatMenuModule, MatRippleModule],
    			declarations: [UserSettingsEmailBenachrichtigungComponent, MatSlideToggle],
    		}).compileComponents();
    
    		fixture = TestBed.createComponent(
    			UserSettingsEmailBenachrichtigungComponent
    		);
    		component = fixture.componentInstance;
    		component.userSettings = createStateResource(createUserSettingsResource());
    		component.valueChanged = { ...<any>mock(EventEmitter), emit: jest.fn() };
    		fixture.detectChanges();
    	});
    
    	it('should create', () => {
    		expect(component).toBeTruthy();
    	});
    
    	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);
    
    			expect(result).toBeTruthy();
    		})
    
    		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();
    		})
    	})
    });