|
| 1 | +import { |
| 2 | + it, |
| 3 | + describe, |
| 4 | + expect, |
| 5 | + beforeEach, |
| 6 | + inject, |
| 7 | + TestComponentBuilder |
| 8 | +} from 'angular2/testing'; |
| 9 | +import {Component} from 'angular2/core'; |
| 10 | +import {By} from 'angular2/platform/browser'; |
| 11 | +import {MdProgressFab} from './progress-fab'; |
| 12 | +import {MdProgressCircle} from '../progress-circle/progress-circle'; |
| 13 | + |
| 14 | +export function main() { |
| 15 | + describe('MdProgressFab', () => { |
| 16 | + let builder: TestComponentBuilder; |
| 17 | + |
| 18 | + beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { |
| 19 | + builder = tcb; |
| 20 | + })); |
| 21 | + |
| 22 | + it('should correctly apply the color attribute on the progress circle', (done: () => void) => { |
| 23 | + return builder |
| 24 | + .createAsync(TestApp) |
| 25 | + .then((fixture) => { |
| 26 | + let testComponent = fixture.debugElement.componentInstance; |
| 27 | + let progressDebugElement = fixture.debugElement.query(By.css('md-progress-circle')); |
| 28 | + |
| 29 | + testComponent.progressColor = 'primary'; |
| 30 | + fixture.detectChanges(); |
| 31 | + |
| 32 | + expect(progressDebugElement.nativeElement.getAttribute('color')).toBe('primary'); |
| 33 | + |
| 34 | + testComponent.progressColor = 'accent'; |
| 35 | + fixture.detectChanges(); |
| 36 | + |
| 37 | + expect(progressDebugElement.nativeElement.getAttribute('color')).toBe('accent'); |
| 38 | + |
| 39 | + done(); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should correctly apply the mode on the progress circle', (done: () => void) => { |
| 44 | + return builder |
| 45 | + .createAsync(TestApp) |
| 46 | + .then((fixture) => { |
| 47 | + let testComponent = fixture.debugElement.componentInstance; |
| 48 | + let progressComponent: MdProgressCircle = fixture.debugElement |
| 49 | + .query(By.css('md-progress-circle')).componentInstance; |
| 50 | + |
| 51 | + testComponent.progressMode = 'determinate'; |
| 52 | + fixture.detectChanges(); |
| 53 | + |
| 54 | + expect(progressComponent.mode).toBe('determinate'); |
| 55 | + |
| 56 | + testComponent.progressColor = 'indeterminate'; |
| 57 | + fixture.detectChanges(); |
| 58 | + |
| 59 | + expect(progressComponent.mode).toBe('determinate'); |
| 60 | + |
| 61 | + done(); |
| 62 | + }); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should correctly apply the value on the progress circle', (done: () => void) => { |
| 66 | + return builder |
| 67 | + .createAsync(TestApp) |
| 68 | + .then((fixture) => { |
| 69 | + let testComponent = fixture.debugElement.componentInstance; |
| 70 | + let progressComponent: MdProgressCircle = fixture.debugElement |
| 71 | + .query(By.css('md-progress-circle')).componentInstance; |
| 72 | + |
| 73 | + testComponent.progressValue = 50; |
| 74 | + fixture.detectChanges(); |
| 75 | + |
| 76 | + expect(progressComponent._value).toBe(50); |
| 77 | + |
| 78 | + testComponent.progressValue = 70; |
| 79 | + fixture.detectChanges(); |
| 80 | + |
| 81 | + expect(progressComponent._value).toBe(70); |
| 82 | + |
| 83 | + done(); |
| 84 | + }); |
| 85 | + }); |
| 86 | + |
| 87 | + it('should correctly apply the color on the button', (done: () => void) => { |
| 88 | + return builder |
| 89 | + .createAsync(TestApp) |
| 90 | + .then((fixture) => { |
| 91 | + let testComponent = fixture.debugElement.componentInstance; |
| 92 | + let buttonDebugElement = fixture.debugElement.query(By.css('button')); |
| 93 | + |
| 94 | + testComponent.buttonColor = 'primary'; |
| 95 | + fixture.detectChanges(); |
| 96 | + |
| 97 | + expect(buttonDebugElement.nativeElement.classList.contains('md-primary')).toBe(true); |
| 98 | + |
| 99 | + testComponent.buttonColor = 'accent'; |
| 100 | + fixture.detectChanges(); |
| 101 | + expect(buttonDebugElement.nativeElement.classList.contains('md-accent')).toBe(true); |
| 102 | + |
| 103 | + done(); |
| 104 | + }); |
| 105 | + }); |
| 106 | + |
| 107 | + }); |
| 108 | +} |
| 109 | + |
| 110 | +@Component({ |
| 111 | + selector: 'test-app', |
| 112 | + template: ` |
| 113 | + <button md-progress-fab [color]="buttonColor" [progressColor]="progressColor" |
| 114 | + [mode]="progressMode" [value]="progressValue"> |
| 115 | + </button>`, |
| 116 | + directives: [MdProgressFab] |
| 117 | +}) |
| 118 | +class TestApp { |
| 119 | + buttonColor: string = 'primary'; |
| 120 | + progressColor: string = 'accent'; |
| 121 | + progressMode: string = 'indeterminate'; |
| 122 | + progressValue: number = 0; |
| 123 | +} |
0 commit comments