Skip to content

Commit

Permalink
Refactors Theme Component and added tests for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyanshdwivedi committed Dec 23, 2018
1 parent c4cf69e commit a7f2b09
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 11 deletions.
48 changes: 37 additions & 11 deletions src/app/theme/theme.component.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
<div class="modal-dialog" role="document">
<div class="modal-content">

<div class="modal-header">
<!-- Start ignoring HTMLLintBear -->
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<!-- Stop ignoring HTMLLintBear -->
<button
type="button"
class="close"
data-dismiss="modal"
aria-label="Close"
><span aria-hidden="true">&times;</span
></button>
<h4 class="modal-title" id="my-modal-label">Customization</h4>
<button type="button" (click)="setTheme('defaultTheme')" class="btn btn-round btn-default theme-link">Default</button>
<button type="button" (click)="setTheme('darkTheme')" class="btn btn-round btn-default theme-link">Dark</button>
<button type="button" (click)="setTheme('basicTheme')" class="btn btn-round btn-default theme-link">Basic</button>
<button type="button" (click)="setTheme('contrastTheme')" class="btn btn-round btn-default theme-link">Contrast</button>
<button type="button" (click)="setTheme('terminalTheme')" class="btn btn-round btn-default theme-link">Terminal</button>
<button type="button" (click)="setTheme('nightTheme')" class="btn btn-round btn-default theme-link">Night</button>
<button
type="button"
(click)="setTheme('defaultTheme')"
class="btn btn-round btn-default theme-link"
>Default</button>
<button
type="button"
(click)="setTheme('darkTheme')"
class="btn btn-round btn-default theme-link"
>Dark</button>
<button
type="button"
(click)="setTheme('basicTheme')"
class="btn btn-round btn-default theme-link"
>Basic</button>
<button
type="button"
(click)="setTheme('contrastTheme')"
class="btn btn-round btn-default theme-link"
>Contrast</button>
<button
type="button"
(click)="setTheme('terminalTheme')"
class="btn btn-round btn-default theme-link"
>Terminal</button>
<button
type="button"
(click)="setTheme('nightTheme')"
class="btn btn-round btn-default theme-link"
>Night</button>
</div>

</div>
</div>
31 changes: 31 additions & 0 deletions src/app/theme/theme.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ThemeComponent } from './theme.component';
import { ThemeService } from '../services/theme.service';
import { By } from '@angular/platform-browser';

describe('ThemeComponent', () => {
let component: ThemeComponent;
Expand All @@ -28,4 +29,34 @@ describe('ThemeComponent', () => {
it('should be created', () => {
expect(component).toBeTruthy();
});

it('should have modal-title', () => {
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h4.modal-title')).toBeTruthy();
});

it('should have button of class close', () => {
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('button.close')).toBeTruthy();
});

it('should have 6 buttons of class theme-link', () => {
const element = fixture.debugElement.queryAll(By.css('button.theme-link'));
expect(element.length).toBe(6);
});

it('should set theme', async(() => {
spyOn(component, 'setTheme').and.callThrough();

const element = fixture.debugElement.queryAll(By.css('button.theme-link'))[1];
const btn = element.nativeElement as HTMLElement;
btn.click();

fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const theme = JSON.parse(localStorage.getItem('theme')).value;
expect(theme).toBe('darkTheme');
});
}));
});

0 comments on commit a7f2b09

Please sign in to comment.