feat(): Dartanalyzer running on travis.

This commit is contained in:
Hans Larsen
2016-01-29 14:01:19 -08:00
parent f167934875
commit 3a1d518df0
25 changed files with 905 additions and 290 deletions
+32 -30
View File
@@ -16,42 +16,44 @@ import {By} from 'angular2/platform/browser';
import {MdButton} from './button';
import {AsyncTestFn, FunctionWithParamTokens} from 'angular2/testing';
export function main() {
describe('MdButton', () => {
let builder: TestComponentBuilder;
describe('MdButton', () => {
let builder: TestComponentBuilder;
beforeEach(inject([TestComponentBuilder], (tcb:TestComponentBuilder) => {
builder = tcb;
}));
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { builder = tcb; }));
describe('button[md-button]', () => {
it('should handle a click on the button', (done:() => void) => {
return builder.createAsync(TestApp).then((fixture) => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'));
describe('button[md-button]', () => {
it('should handle a click on the button', (done: () => void) => {
return builder.createAsync(TestApp).then((fixture) => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'));
buttonDebugElement.nativeElement.click();
expect(testComponent.clickCount).toBe(1);
done();
buttonDebugElement.nativeElement.click();
expect(testComponent.clickCount).toBe(1);
done();
});
});
it('should not increment if disabled', (done:() => void) => {
return builder.createAsync(TestApp).then((fixture) => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'));
testComponent.isDisabled = true;
fixture.detectChanges();
buttonDebugElement.nativeElement.click();
expect(testComponent.clickCount).toBe(0);
done();
})
});
});
it('should not increment if disabled', (done: () => void) => {
return builder.createAsync(TestApp).then((fixture) => {
let testComponent = fixture.debugElement.componentInstance;
let buttonDebugElement = fixture.debugElement.query(By.css('button'));
testComponent.isDisabled = true;
fixture.detectChanges();
buttonDebugElement.nativeElement.click();
expect(testComponent.clickCount).toBe(0);
done();
})
});
});
});
}
/** Shortcut function to use instead of `injectAsync` for less boilerplate on each `it`. */
function testAsync(fn: Function): FunctionWithParamTokens {
+204 -189
View File
@@ -21,7 +21,7 @@ import {Predicate} from "angular2/src/facade/collection";
function wait(msec: number) {
return new Promise<void>(resolve => window.setTimeout(() => resolve(), msec));
return new Promise(resolve => window.setTimeout(() => resolve(), msec));
}
@@ -38,75 +38,117 @@ function waitOnEvent(fixture: ComponentFixture,
}
describe('MdSidenav', () => {
let builder: TestComponentBuilder;
export function main() {
describe('MdSidenav', () => {
let builder: TestComponentBuilder;
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { builder = tcb; }));
beforeEach(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
builder = tcb;
}));
describe('methods', () => {
it('should be able to open and close', (done: any) => {
let testComponent: BasicTestApp;
let fixture: ComponentFixture;
describe('methods', () => {
it('should be able to open and close', (done: any) => {
let testComponent: BasicTestApp;
let fixture: ComponentFixture;
return builder.createAsync(BasicTestApp)
.then((f) => {
fixture = f;
testComponent = fixture.debugElement.componentInstance;
return builder.createAsync(BasicTestApp)
.then((f) => {
fixture = f;
testComponent = fixture.debugElement.componentInstance;
const openButtonElement = fixture.debugElement.query(By.css('.open'));
openButtonElement.nativeElement.click();
})
.then(() => wait(1))
.then(() => {
expect(testComponent.openStartCount).toBe(1);
expect(testComponent.openCount).toBe(0);
})
.then(() => waitOnEvent(fixture, By.directive(MdSidenav), 'onOpen'))
.then(() => {
expect(testComponent.openStartCount).toBe(1);
expect(testComponent.openCount).toBe(1);
expect(testComponent.closeStartCount).toBe(0);
expect(testComponent.closeCount).toBe(0);
const openButtonElement = fixture.debugElement.query(By.css('.open'));
openButtonElement.nativeElement.click();
})
.then(() => wait(1))
.then(() => {
expect(testComponent.openStartCount).toBe(1);
expect(testComponent.openCount).toBe(0);
})
.then(() => waitOnEvent(fixture, By.directive(MdSidenav), 'onOpen'))
.then(() => {
expect(testComponent.openStartCount).toBe(1);
expect(testComponent.openCount).toBe(1);
expect(testComponent.closeStartCount).toBe(0);
expect(testComponent.closeCount).toBe(0);
const sidenavElement = fixture.debugElement.query(By.css('md-sidenav'));
const sidenavBackdropElement = fixture.debugElement.query(By.css('.md-sidenav-backdrop'));
expect(window.getComputedStyle(sidenavElement.nativeElement).visibility).toEqual('visible');
expect(window.getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('visible');
const sidenavElement = fixture.debugElement.query(By.css('md-sidenav'));
const sidenavBackdropElement = fixture.debugElement.query(By.css('.md-sidenav-backdrop'));
expect(window.getComputedStyle(sidenavElement.nativeElement).visibility).toEqual('visible');
expect(window.getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('visible');
// Close it.
const closeButtonElement = fixture.debugElement.query(By.css('.close'));
closeButtonElement.nativeElement.click();
})
.then(() => wait(1))
.then(() => {
expect(testComponent.openStartCount).toBe(1);
expect(testComponent.openCount).toBe(1);
expect(testComponent.closeStartCount).toBe(1);
expect(testComponent.closeCount).toBe(0);
})
.then(() => waitOnEvent(fixture, By.directive(MdSidenav), 'onClose'))
.then(() => fixture.detectChanges())
.then(() => {
expect(testComponent.openStartCount).toBe(1);
expect(testComponent.openCount).toBe(1);
expect(testComponent.closeStartCount).toBe(1);
expect(testComponent.closeCount).toBe(1);
// Close it.
const closeButtonElement = fixture.debugElement.query(By.css('.close'));
closeButtonElement.nativeElement.click();
})
.then(() => wait(1))
.then(() => {
expect(testComponent.openStartCount).toBe(1);
expect(testComponent.openCount).toBe(1);
expect(testComponent.closeStartCount).toBe(1);
expect(testComponent.closeCount).toBe(0);
})
.then(() => waitOnEvent(fixture, By.directive(MdSidenav), 'onClose'))
.then(() => fixture.detectChanges())
.then(() => {
expect(testComponent.openStartCount).toBe(1);
expect(testComponent.openCount).toBe(1);
expect(testComponent.closeStartCount).toBe(1);
expect(testComponent.closeCount).toBe(1);
const sidenavElement = fixture.debugElement.query(By.css('md-sidenav'));
const sidenavBackdropElement = fixture.debugElement.query(By.css('.md-sidenav-backdrop'));
expect(window.getComputedStyle(sidenavElement.nativeElement).visibility).toEqual('hidden');
expect(window.getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('hidden');
})
.then(done, done.fail);
}, 8000);
const sidenavElement = fixture.debugElement.query(By.css('md-sidenav'));
const sidenavBackdropElement = fixture.debugElement.query(By.css('.md-sidenav-backdrop'));
expect(window.getComputedStyle(sidenavElement.nativeElement).visibility).toEqual('hidden');
expect(window.getComputedStyle(sidenavBackdropElement.nativeElement).visibility).toEqual('hidden');
})
.then(done, done.fail);
}, 8000);
it('open() and close() return a promise that resolves after the animation ended',
(done: any) => {
it('open() and close() return a promise that resolves after the animation ended',
(done: any) => {
let testComponent: BasicTestApp;
let fixture: ComponentFixture;
let sidenav: MdSidenav;
let promise: Promise<{}>;
let called: boolean = false;
return builder.createAsync(BasicTestApp)
.then((f) => {
fixture = f;
sidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
promise = sidenav.open();
promise.then(() => called = true);
})
.then(() => wait(1))
.then(() => fixture.detectChanges())
.then(() => {
expect(called).toBe(false);
})
.then(() => promise)
.then(() => expect(called).toBe(true))
.then(() => {
// Close it now.
called = false;
promise = sidenav.close();
promise.then(() => called = true);
})
.then(() => wait(1))
.then(() => fixture.detectChanges())
.then(() => {
expect(called).toBe(false);
})
.then(() => promise)
.then(() => expect(called).toBe(true))
.then(done, done.fail);
}, 8000);
it('open() twice returns the same promise', (done: any) => {
let testComponent: BasicTestApp;
let fixture: ComponentFixture;
let sidenav: MdSidenav;
let promise: Promise<void>;
let promise: Promise<{}>;
let called: boolean = false;
return builder.createAsync(BasicTestApp)
@@ -115,151 +157,124 @@ describe('MdSidenav', () => {
sidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
promise = sidenav.open();
promise.then(() => called = true);
expect(sidenav.open()).toBe(promise);
})
.then(() => wait(1))
.then(() => fixture.detectChanges())
.then(() => {
expect(called).toBe(false);
fixture.detectChanges();
return promise;
})
.then(() => promise)
.then(() => expect(called).toBe(true))
.then(() => {
// Close it now.
called = false;
promise = sidenav.close();
promise.then(() => called = true);
expect(sidenav.close()).toBe(promise);
})
.then(() => wait(1))
.then(() => fixture.detectChanges())
.then(() => {
expect(called).toBe(false);
})
.then(() => promise)
.then(() => expect(called).toBe(true))
.then(done, done.fail);
}, 8000);
});
it('open() twice returns the same promise', (done: any) => {
let testComponent: BasicTestApp;
let fixture: ComponentFixture;
let sidenav: MdSidenav;
it('open() then close() cancel animations when called too fast',
(done: any) => {
let testComponent: BasicTestApp;
let fixture: ComponentFixture;
let sidenav: MdSidenav;
let promise: Promise<void>;
let called: boolean = false;
let openPromise: Promise<any>;
let closePromise: Promise<any>;
let openCalled: boolean = false;
let openCancelled: boolean = false;
let closeCalled: boolean = false;
return builder.createAsync(BasicTestApp)
.then((f) => {
fixture = f;
sidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
return builder.createAsync(BasicTestApp)
.then((f) => {
fixture = f;
sidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
promise = sidenav.open();
expect(sidenav.open()).toBe(promise);
})
.then(() => wait(1))
.then(() => {
fixture.detectChanges();
return promise;
})
.then(() => {
promise = sidenav.close();
expect(sidenav.close()).toBe(promise);
})
.then(done, done.fail);
openPromise = sidenav.open().then(() => {
openCalled = true;
},
() => {
openCancelled = true;
});
})
.then(() => wait(1))
.then(() => fixture.detectChanges())
// We need to wait for the browser to start the transition.
.then(() => wait(50))
.then(() => {
closePromise = sidenav.close().then(() => {
closeCalled = true;
}, done.fail);
return wait(1);
})
.then(() => {
fixture.detectChanges();
return closePromise;
})
.then(() => {
expect(openCalled).toBe(false);
expect(openCancelled).toBe(true);
expect(closeCalled).toBe(true);
})
.then(done, done.fail);
}, 8000);
it('close() then open() cancel animations when called too fast',
(done: any) => {
let testComponent: BasicTestApp;
let fixture: ComponentFixture;
let sidenav: MdSidenav;
let openPromise: Promise<any>;
let closePromise: Promise<any>;
let closeCalled: boolean = false;
let closeCancelled: boolean = false;
let openCalled: boolean = false;
return builder.createAsync(BasicTestApp)
.then((f) => {
fixture = f;
sidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
/** First, open it. */
openPromise = sidenav.open();
})
.then(() => wait(1))
.then(() => {
fixture.detectChanges();
return openPromise;
})
.then(() => {
// Then close and check behavior.
closePromise = sidenav.close().then(() => {
closeCalled = true;
},
() => {
closeCancelled = true;
});
})
.then(() => wait(1))
.then(() => fixture.detectChanges())
// We need to wait for the browser to start the transition.
.then(() => wait(50))
.then(() => {
openPromise = sidenav.open().then(() => {
openCalled = true;
}, done.fail);
return wait(1);
})
.then(() => {
fixture.detectChanges();
return openPromise;
})
.then(() => {
expect(closeCalled).toBe(false);
expect(closeCancelled).toBe(true);
expect(openCalled).toBe(true);
})
.then(done, done.fail);
}, 8000);
});
it('open() then close() cancel animations when called too fast',
(done: any) => {
let testComponent: BasicTestApp;
let fixture: ComponentFixture;
let sidenav: MdSidenav;
let openPromise: Promise<void>;
let closePromise: Promise<void>;
let openCalled: boolean = false;
let openCancelled: boolean = false;
let closeCalled: boolean = false;
return builder.createAsync(BasicTestApp)
.then((f) => {
fixture = f;
sidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
openPromise = sidenav.open().then(() => { openCalled = true; },
() => { openCancelled = true; });
})
.then(() => wait(1))
.then(() => fixture.detectChanges())
// We need to wait for the browser to start the transition.
.then(() => wait(50))
.then(() => {
closePromise = sidenav.close().then(() => { closeCalled = true; }, done.fail);
return wait(1);
})
.then(() => {
fixture.detectChanges();
return closePromise;
})
.then(() => {
expect(openCalled).toBe(false);
expect(openCancelled).toBe(true);
expect(closeCalled).toBe(true);
})
.then(done, done.fail);
}, 8000);
it('close() then open() cancel animations when called too fast',
(done: any) => {
let testComponent: BasicTestApp;
let fixture: ComponentFixture;
let sidenav: MdSidenav;
let openPromise: Promise<void>;
let closePromise: Promise<void>;
let closeCalled: boolean = false;
let closeCancelled: boolean = false;
let openCalled: boolean = false;
return builder.createAsync(BasicTestApp)
.then((f) => {
fixture = f;
sidenav = fixture.debugElement.query(By.directive(MdSidenav)).componentInstance;
/** First, open it. */
openPromise = sidenav.open();
})
.then(() => wait(1))
.then(() => {
fixture.detectChanges();
return openPromise;
})
.then(() => {
// Then close and check behavior.
closePromise = sidenav.close().then(() => { closeCalled = true; },
() => { closeCancelled = true; });
})
.then(() => wait(1))
.then(() => fixture.detectChanges())
// We need to wait for the browser to start the transition.
.then(() => wait(50))
.then(() => {
openPromise = sidenav.open().then(() => { openCalled = true; }, done.fail);
return wait(1);
})
.then(() => {
fixture.detectChanges();
return openPromise;
})
.then(() => {
expect(closeCalled).toBe(false);
expect(closeCancelled).toBe(true);
expect(openCalled).toBe(true);
})
.then(done, done.fail);
}, 8000);
});
});
}
/** Test component that contains an MdSidenavLayout and one MdSidenav. */
@Component({
+12 -12
View File
@@ -61,16 +61,16 @@ export class MdSidenav {
@Input('opened') private opened_: boolean;
/** Event emitted when the sidenav is being opened. Use this to synchronize animations. */
@Output('open-start') onOpenStart = new EventEmitter<void>();
@Output('open-start') onOpenStart = new EventEmitter<Object>();
/** Event emitted when the sidenav is fully opened. */
@Output('open') onOpen = new EventEmitter<void>();
@Output('open') onOpen = new EventEmitter<Object>();
/** Event emitted when the sidenav is being closed. Use this to synchronize animations. */
@Output('close-start') onCloseStart = new EventEmitter<void>();
@Output('close-start') onCloseStart = new EventEmitter<Object>();
/** Event emitted when the sidenav is fully closed. */
@Output('close') onClose = new EventEmitter<void>();
@Output('close') onClose = new EventEmitter<Object>();
/**
@@ -91,7 +91,7 @@ export class MdSidenav {
/** Open this sidenav, and return a Promise that will resolve when it's fully opened (or get
* rejected if it didn't). */
open(): Promise<void> {
open(): Promise<{}> {
return this.toggle(true);
}
@@ -99,7 +99,7 @@ export class MdSidenav {
* Close this sidenav, and return a Promise that will resolve when it's fully closed (or get
* rejected if it didn't).
*/
close(): Promise<void> {
close(): Promise<{}> {
return this.toggle(false);
}
@@ -108,11 +108,11 @@ export class MdSidenav {
* close() when it's closed.
* @param isOpen
*/
toggle(isOpen: boolean = !this.opened): Promise<void> {
toggle(isOpen: boolean = !this.opened): Promise<{}> {
// Shortcut it if we're already opened.
if (isOpen === this.opened) {
if (!this.transition_) {
return Promise.resolve();
return Promise.resolve(null);
} else {
return isOpen ? this.openPromise_ : this.closePromise_;
}
@@ -132,7 +132,7 @@ export class MdSidenav {
if (isOpen) {
if (!this.openPromise_) {
this.openPromise_ = new Promise<void>((resolve, reject) => {
this.openPromise_ = new Promise<{}>((resolve, reject) => {
this.openPromiseResolve_ = resolve;
this.openPromiseReject_ = reject;
});
@@ -140,7 +140,7 @@ export class MdSidenav {
return this.openPromise_;
} else {
if (!this.closePromise_) {
this.closePromise_ = new Promise<void>((resolve, reject) => {
this.closePromise_ = new Promise<{}>((resolve, reject) => {
this.closePromiseResolve_ = resolve;
this.closePromiseReject_ = reject;
});
@@ -225,10 +225,10 @@ export class MdSidenav {
}
private transition_: boolean = false;
private openPromise_: Promise<void>;
private openPromise_: Promise<{}>;
private openPromiseResolve_: () => void;
private openPromiseReject_: () => void;
private closePromise_: Promise<void>;
private closePromise_: Promise<{}>;
private closePromiseResolve_: () => void;
private closePromiseReject_: () => void;
}
+1 -1
View File
@@ -16,7 +16,7 @@ import {OneOf} from "../../core/annotations/one-of";
export class Dir {
@Input('dir') @OneOf(['ltr', 'rtl']) private dir_: string = 'ltr';
@Output() dirChange = new EventEmitter<void>();
@Output() dirChange = new EventEmitter<{}>();
@HostBinding('attr.dir')
get dir(): string {
+7
View File
@@ -0,0 +1,7 @@
import "package:angular2/platform/browser.dart" show bootstrap;
import "./demo-app/demo-app.dart" show DemoApp;
import "package:angular2/router" show ROUTER_PROVIDERS;
void main() {
bootstrap(DemoApp, [ROUTER_PROVIDERS]);
}