|
| 1 | +import { AccessibilitySettingsComponent } from './accessibility-settings.component'; |
| 2 | +import { ComponentFixture, waitForAsync, TestBed } from '@angular/core/testing'; |
| 3 | +import { TranslateModule } from '@ngx-translate/core'; |
| 4 | +import { NO_ERRORS_SCHEMA } from '@angular/core'; |
| 5 | +import { AuthServiceStub } from '../../shared/testing/auth-service.stub'; |
| 6 | +import { getAccessibilitySettingsServiceStub } from '../../accessibility/accessibility-settings.service.stub'; |
| 7 | +import { AccessibilitySettingsService, AccessibilitySetting } from '../../accessibility/accessibility-settings.service'; |
| 8 | +import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub'; |
| 9 | +import { AuthService } from '../../core/auth/auth.service'; |
| 10 | +import { NotificationsService } from '../../shared/notifications/notifications.service'; |
| 11 | +import { of } from 'rxjs'; |
| 12 | + |
| 13 | + |
| 14 | +describe('AccessibilitySettingsComponent', () => { |
| 15 | + let component: AccessibilitySettingsComponent; |
| 16 | + let fixture: ComponentFixture<AccessibilitySettingsComponent>; |
| 17 | + |
| 18 | + let authService: AuthServiceStub; |
| 19 | + let settingsService: AccessibilitySettingsService; |
| 20 | + let notificationsService: NotificationsServiceStub; |
| 21 | + |
| 22 | + beforeEach(waitForAsync(() => { |
| 23 | + authService = new AuthServiceStub(); |
| 24 | + settingsService = getAccessibilitySettingsServiceStub(); |
| 25 | + notificationsService = new NotificationsServiceStub(); |
| 26 | + |
| 27 | + TestBed.configureTestingModule({ |
| 28 | + imports: [TranslateModule.forRoot()], |
| 29 | + declarations: [AccessibilitySettingsComponent], |
| 30 | + providers: [ |
| 31 | + { provide: AuthService, useValue: authService }, |
| 32 | + { provide: AccessibilitySettingsService, useValue: settingsService }, |
| 33 | + { provide: NotificationsService, useValue: notificationsService }, |
| 34 | + ], |
| 35 | + schemas: [NO_ERRORS_SCHEMA], |
| 36 | + }).compileComponents(); |
| 37 | + })); |
| 38 | + |
| 39 | + beforeEach(() => { |
| 40 | + fixture = TestBed.createComponent(AccessibilitySettingsComponent); |
| 41 | + component = fixture.componentInstance; |
| 42 | + fixture.detectChanges(); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should create', () => { |
| 46 | + expect(component).toBeTruthy(); |
| 47 | + }); |
| 48 | + |
| 49 | + describe('On Init', () => { |
| 50 | + it('should retrieve all accessibility settings options', () => { |
| 51 | + expect(settingsService.getAllAccessibilitySettingKeys).toHaveBeenCalled(); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should retrieve the current settings', () => { |
| 55 | + expect(settingsService.getAll).toHaveBeenCalled(); |
| 56 | + }); |
| 57 | + }); |
| 58 | + |
| 59 | + describe('getInputType', () => { |
| 60 | + it('should retrieve the input type for the setting from the service', () => { |
| 61 | + component.getInputType(AccessibilitySetting.LiveRegionTimeOut); |
| 62 | + expect(settingsService.getInputType).toHaveBeenCalledWith(AccessibilitySetting.LiveRegionTimeOut); |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + describe('saveSettings', () => { |
| 67 | + it('should save the settings in the service', () => { |
| 68 | + settingsService.setSettings = jasmine.createSpy('setSettings').and.returnValue(of('cookie')); |
| 69 | + component.saveSettings(); |
| 70 | + expect(settingsService.setSettings).toHaveBeenCalled(); |
| 71 | + }); |
| 72 | + |
| 73 | + it('should give the user a notification mentioning where the settings were saved', () => { |
| 74 | + settingsService.setSettings = jasmine.createSpy('setSettings').and.returnValue(of('cookie')); |
| 75 | + component.saveSettings(); |
| 76 | + expect(notificationsService.success).toHaveBeenCalled(); |
| 77 | + }); |
| 78 | + }); |
| 79 | +}); |
0 commit comments