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

Merge branch 'OZG-2886_Toogle_Benachrichtigung_bei_Antragseingang' of...

Merge branch 'OZG-2886_Toogle_Benachrichtigung_bei_Antragseingang' of git.ozg-sh.de:mgm/goofy into OZG-2886_Toogle_Benachrichtigung_bei_Antragseingang
parents 19ea4185 ed317f35
No related branches found
No related tags found
No related merge requests found
......@@ -5,9 +5,8 @@ import { combineLatest, Observable } from 'rxjs';
import { map, startWith, tap } from 'rxjs/operators';
import { UserSettingsFacade } from './+state/user-settings.facade';
import { UserSettings, UserSettingsResource } from './user-settings.model';
@Injectable({
providedIn: 'root',
})
@Injectable({ providedIn: 'root' })
export class UserSettingsService {
constructor(
......@@ -15,11 +14,8 @@ export class UserSettingsService {
private userProfileService: UserProfileService,
) { }
getUserSettings(): Observable<StateResource<UserSettingsResource>> {
const userProfile$ = this.userProfileService.getCurrentUser();
const userSetting$ = this.userSettingsFacade.getUserSettings();
return combineLatest([userProfile$, userSetting$]).pipe(
public getUserSettings(): Observable<StateResource<UserSettingsResource>> {
return combineLatest([this.userProfileService.getCurrentUser(), this.userSettingsFacade.getUserSettings()]).pipe(
tap(([userProfile, userSettings]) => doIfLoadingRequired(userSettings, () => {
if (userProfile.resource) {
this.userSettingsFacade.loadUserSettings(userProfile.resource);
......@@ -30,7 +26,7 @@ export class UserSettingsService {
);
}
setUserSettings(userSettings: UserSettings): void {
public setUserSettings(userSettings: UserSettings): void {
this.userSettingsFacade.setUserSettings(userSettings);
}
}
<goofy-client-icon-button-with-spinner
icon="settings"
toolTip="Einstellungen"
[matMenuTriggerFor]="settingsMenu"
>
<goofy-client-icon-button-with-spinner icon="settings" toolTip="Einstellungen"
[matMenuTriggerFor]="settingsMenu">
</goofy-client-icon-button-with-spinner>
<mat-menu #settingsMenu="matMenu">
......
......@@ -4,20 +4,21 @@ import { AppService } from '@goofy-client/app-shared';
import { mock } from '@goofy-client/test-utils';
import { IconButtonWithSpinnerComponent } from '@goofy-client/ui';
import { UserSettingsService } from '@goofy-client/user-settings-shared';
import { NotificationsSendFor } from 'libs/user-settings-shared/src/lib/user-settings.model';
import { MockComponent } from 'ng-mocks';
import { BehaviorSubject } from 'rxjs';
import { UserSettingsContainerComponent } from './user-settings-container.component';
import { UserSettingsDarkmodeComponent } from './user-settings-darkmode/user-settings-darkmode.component';
import { UserSettingsEmailBenachrichtigungComponent } from './user-settings-email-benachrichtigung/user-settings-email-benachrichtigung.component';
const darkModeSubj: BehaviorSubject<boolean> = new BehaviorSubject(false);
const appService = { ...mock(AppService), getDarkMode: () => darkModeSubj };
const userSettingsService = mock(UserSettingsService);
describe('UserSettingsContainerComponent', () => {
let component: UserSettingsContainerComponent;
let fixture: ComponentFixture<UserSettingsContainerComponent>;
const darkModeSubj: BehaviorSubject<boolean> = new BehaviorSubject(false);
const appService = { ...mock(AppService), getDarkMode: () => darkModeSubj };
const userSettingsService = { ...mock(UserSettingsService), setUserSettings: jest.fn() };
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatMenuModule],
......@@ -37,8 +38,10 @@ describe('UserSettingsContainerComponent', () => {
useValue: userSettingsService
}
],
}).compileComponents();
});
});
beforeEach(() => {
fixture = TestBed.createComponent(UserSettingsContainerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
......@@ -47,4 +50,28 @@ describe('UserSettingsContainerComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
describe('change color mode', () => {
it('should call app service', () => {
component.changeColorMode(true);
expect(appService.setDarkMode).toHaveBeenCalledWith(true);
})
})
describe('change notifications send for', () => {
it('should call service with ALL', () => {
component.changeNotificationsSendFor(true);
expect(userSettingsService.setUserSettings).toHaveBeenCalledWith({ notificationsSendFor: NotificationsSendFor.ALL });
})
it('should call service with NONE', () => {
component.changeNotificationsSendFor(false);
expect(userSettingsService.setUserSettings).toHaveBeenCalledWith({ notificationsSendFor: NotificationsSendFor.NONE });
})
})
});
......@@ -3,7 +3,7 @@ import { Component, Inject, OnInit, Renderer2 } from '@angular/core';
import { AppService, localStorageDark } from '@goofy-client/app-shared';
import { StateResource } from '@goofy-client/tech-shared';
import { UserSettingsService } from '@goofy-client/user-settings-shared';
import { NotificationsSendFor, UserSettingsResource } from 'libs/user-settings-shared/src/lib/user-settings.model';
import { NotificationsSendFor, UserSettings, UserSettingsResource } from 'libs/user-settings-shared/src/lib/user-settings.model';
import { Observable, of } from 'rxjs';
@Component({
......@@ -50,8 +50,12 @@ export class UserSettingsContainerComponent implements OnInit {
this.appService.setDarkMode(darkMode);
}
changeNotificationsSendFor(value: boolean): void {
const notificationsSendFor: string = value ? NotificationsSendFor.ALL : NotificationsSendFor.NONE;
this.userSettingsService.setUserSettings({ notificationsSendFor });
changeNotificationsSendFor(toggleValue: boolean): void {
this.userSettingsService.setUserSettings(this.createUserSettings(toggleValue));
}
private createUserSettings(toggleValue: boolean): UserSettings {
const notificationsSendFor: NotificationsSendFor = toggleValue ? NotificationsSendFor.ALL : NotificationsSendFor.NONE;
return { notificationsSendFor };
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment