From 23d87407823a964f8b2682eeef283248805bcae6 Mon Sep 17 00:00:00 2001 From: ziajka Date: Fri, 6 Apr 2018 07:50:28 +0200 Subject: [PATCH] Test SettingsComponent --- src/app/settings/settings.component.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/app/settings/settings.component.spec.ts b/src/app/settings/settings.component.spec.ts index 70f3c734..c5a151e6 100644 --- a/src/app/settings/settings.component.spec.ts +++ b/src/app/settings/settings.component.spec.ts @@ -10,6 +10,7 @@ import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; describe('SettingsComponent', () => { let component: SettingsComponent; let fixture: ComponentFixture; + let settingsService: SettingsService; beforeEach(async(() => { TestBed.configureTestingModule({ @@ -20,6 +21,8 @@ describe('SettingsComponent', () => { declarations: [ SettingsComponent ] }) .compileComponents(); + + settingsService = TestBed.get(SettingsService); })); beforeEach(() => { @@ -31,4 +34,20 @@ describe('SettingsComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('should get and save new settings', () => { + const settings = { + 'crash_reports': true + }; + const getAll = spyOn(settingsService, 'getAll').and.returnValue(settings); + const setAll = spyOn(settingsService, 'setAll'); + component.ngOnInit(); + expect(getAll).toHaveBeenCalled(); + expect(component.settings).toEqual(settings); + component.settings.crash_reports = false; + component.save(); + expect(setAll).toHaveBeenCalledWith(settings); + }); + + });