-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduces a new `MdThemeable` base class that can be extended by different components to automatically support the `color` input. * This reduces a lot of repeated code in the different components and it also simplifies maintaining. Closes #2394.
- Loading branch information
1 parent
3ad6ff0
commit 705519d
Showing
11 changed files
with
192 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import {async, ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {Component, ElementRef, Renderer} from '@angular/core'; | ||
import {MdThemeable} from './themeable'; | ||
import {By} from '@angular/platform-browser'; | ||
|
||
describe('MdThemeable', () => { | ||
|
||
let fixture: ComponentFixture<TestComponent>; | ||
let testComponent: TestComponent; | ||
let themeableElement: HTMLElement; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [TestComponent, ThemeableComponent], | ||
}); | ||
|
||
TestBed.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TestComponent); | ||
fixture.detectChanges(); | ||
|
||
testComponent = fixture.componentInstance; | ||
themeableElement = fixture.debugElement.query(By.css('themeable-test')).nativeElement; | ||
}); | ||
|
||
it('should support a default component color', () => { | ||
expect(themeableElement.classList).toContain('mat-warn'); | ||
}); | ||
|
||
it('should update classes on color change', () => { | ||
expect(themeableElement.classList).toContain('mat-warn'); | ||
|
||
testComponent.color = 'primary'; | ||
fixture.detectChanges(); | ||
|
||
expect(themeableElement.classList).toContain('mat-primary'); | ||
expect(themeableElement.classList).not.toContain('mat-warn'); | ||
|
||
testComponent.color = 'accent'; | ||
fixture.detectChanges(); | ||
|
||
expect(themeableElement.classList).toContain('mat-accent'); | ||
expect(themeableElement.classList).not.toContain('mat-warn'); | ||
expect(themeableElement.classList).not.toContain('mat-primary'); | ||
|
||
testComponent.color = null; | ||
fixture.detectChanges(); | ||
|
||
expect(themeableElement.classList).not.toContain('mat-accent'); | ||
expect(themeableElement.classList).not.toContain('mat-warn'); | ||
expect(themeableElement.classList).not.toContain('mat-primary'); | ||
}); | ||
|
||
it('should throw an error when using an invalid color', () => { | ||
testComponent.color = 'Invalid'; | ||
|
||
expect(() => fixture.detectChanges()).toThrow(); | ||
}); | ||
|
||
}); | ||
|
||
@Component({ | ||
selector: 'themeable-test', | ||
template: '<span>Themeable</span>' | ||
}) | ||
class ThemeableComponent extends MdThemeable { | ||
constructor(renderer: Renderer, elementRef: ElementRef) { | ||
super(renderer, elementRef); | ||
} | ||
} | ||
|
||
@Component({ | ||
template: '<themeable-test [color]="color"></themeable-test>' | ||
}) | ||
class TestComponent { | ||
color: string = 'warn'; | ||
} |
Oops, something went wrong.