-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
172 additions
and
259 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,33 @@ | ||
import { | ||
beforeEach, | ||
beforeEachProviders, | ||
describe, | ||
expect, | ||
injectAsync, | ||
it, | ||
} from '@angular/core/testing'; | ||
import { | ||
ComponentFixture, | ||
TestComponentBuilder, | ||
} from '@angular/compiler/testing'; | ||
import { provide } from '@angular/core'; | ||
import { Config } from 'ionic-angular'; | ||
import { ClickerButton } from './clickerButton'; | ||
import { Clickers } from '../../services/clickers'; | ||
import { TestUtils } from '../../../test/testUtils'; | ||
import { Utils } from '../../services/utils'; | ||
import { beforeEach, beforeEachProviders, describe, expect, it } from '@angular/core/testing'; | ||
import { asyncCallbackFactory, injectAsyncWrapper, providers, TestUtils } from '../../../test/diExports'; | ||
import { ClickerButton } from './clickerButton'; | ||
|
||
let clickerButton: ClickerButton = null; | ||
let clickerButtonFixture: ComponentFixture<ClickerButton> = null; | ||
|
||
class MockClickers { | ||
public doClick(): boolean { | ||
return true; | ||
} | ||
} | ||
|
||
class MockClicker { | ||
public name: string = 'TEST CLICKER'; | ||
public getCount(): number { return 10; }; | ||
} | ||
|
||
class MockClass { | ||
public get(): any { | ||
return {}; | ||
} | ||
} | ||
this.fixture = null; | ||
this.instance = null; | ||
|
||
describe('ClickerButton', () => { | ||
|
||
beforeEachProviders(() => [ | ||
provide(Clickers, {useClass: MockClickers}), | ||
provide(Config, {useClass: MockClass}), | ||
]); | ||
let beforeEachFn: Function = ((testSpec) => { | ||
testSpec.instance['clicker'] = { name: 'TEST CLICKER' }; | ||
testSpec.instance['clicker'].getCount = function(): number { return 10; }; | ||
}); | ||
|
||
beforeEach(injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { | ||
return tcb | ||
.createAsync(ClickerButton) | ||
.then((componentFixture: ComponentFixture<ClickerButton>) => { | ||
clickerButtonFixture = componentFixture; | ||
clickerButton = componentFixture.componentInstance; | ||
clickerButton['clicker'] = { name: 'TEST CLICKER' }; | ||
clickerButton['clicker'].getCount = function(): number { return 10; }; | ||
window['fixture'] = clickerButtonFixture; | ||
window['testUtils'] = TestUtils; | ||
}) | ||
.catch(Utils.promiseCatchHandler); | ||
})); | ||
beforeEachProviders(() => providers); | ||
beforeEach(injectAsyncWrapper(asyncCallbackFactory(ClickerButton, this, false, beforeEachFn))); | ||
|
||
it('initialises', () => { | ||
expect(clickerButton).not.toBeNull(); | ||
expect(this.instance).not.toBeNull(); | ||
}); | ||
|
||
it('displays the clicker name and count', () => { | ||
clickerButtonFixture.detectChanges(); | ||
expect(clickerButtonFixture.nativeElement.querySelectorAll('.button-inner')[0].innerHTML).toEqual('TEST CLICKER (10)'); | ||
this.fixture.detectChanges(); | ||
expect(this.fixture.nativeElement.querySelectorAll('.button-inner')[0].innerHTML).toEqual('TEST CLICKER (10)'); | ||
}); | ||
|
||
it('does a click', () => { | ||
clickerButtonFixture.detectChanges(); | ||
spyOn(clickerButton['clickerService'], 'doClick'); | ||
TestUtils.eventFire(clickerButtonFixture.nativeElement.querySelectorAll('button')[0], 'click'); | ||
expect(clickerButton['clickerService'].doClick).toHaveBeenCalled(); | ||
this.fixture.detectChanges(); | ||
spyOn(this.instance['clickerService'], 'doClick'); | ||
TestUtils.eventFire(this.fixture.nativeElement.querySelectorAll('button')[0], 'click'); | ||
expect(this.instance['clickerService'].doClick).toHaveBeenCalled(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,95 +1,45 @@ | ||
import { | ||
beforeEach, | ||
beforeEachProviders, | ||
describe, | ||
expect, | ||
injectAsync, | ||
it, | ||
} from '@angular/core/testing'; | ||
import { | ||
ComponentFixture, | ||
TestComponentBuilder, | ||
} from '@angular/compiler/testing'; | ||
import { provide } from '@angular/core'; | ||
import { | ||
Config, | ||
Form, | ||
App, | ||
Platform, | ||
} from 'ionic-angular'; | ||
import { ClickerForm } from './clickerForm'; | ||
import { Clickers } from '../../services/clickers'; | ||
import { TestUtils } from '../../../test/testUtils'; | ||
import { Utils } from '../../services/utils'; | ||
import { beforeEach, beforeEachProviders, describe, expect, it } from '@angular/core/testing'; | ||
import { asyncCallbackFactory, injectAsyncWrapper, providers, TestUtils } from '../../../test/diExports'; | ||
import { Utils } from '../../services/utils'; | ||
import { ClickerForm } from './clickerForm'; | ||
|
||
let clickerForm: ClickerForm = null; | ||
let clickerFormFixture: ComponentFixture<ClickerForm> = null; | ||
|
||
class MockClickers { | ||
public newClicker(): boolean { | ||
return true; | ||
} | ||
} | ||
|
||
class MockClass { | ||
public get(): any { | ||
return ''; | ||
} | ||
|
||
public getBoolean(): boolean { | ||
return true; | ||
} | ||
|
||
public getNumber(): number { | ||
return 42; | ||
} | ||
} | ||
this.fixture = null; | ||
this.instance = null; | ||
|
||
describe('ClickerForm', () => { | ||
|
||
beforeEachProviders(() => [ | ||
Form, | ||
provide(Clickers, {useClass: MockClickers}), | ||
provide(App, {useClass: MockClass}), | ||
provide(Platform, {useClass: MockClass}), | ||
provide(Config, {useClass: MockClass}), | ||
]); | ||
let beforeEachFn: Function = ((testSpec) => { | ||
spyOn(testSpec.instance, 'newClicker').and.callThrough(); | ||
spyOn(testSpec.instance['clickerService'], 'newClicker').and.callThrough(); | ||
}); | ||
|
||
beforeEach(injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { | ||
return tcb | ||
.createAsync(ClickerForm) | ||
.then((componentFixture: ComponentFixture<ClickerForm>) => { | ||
clickerFormFixture = componentFixture; | ||
clickerForm = componentFixture.componentInstance; | ||
spyOn(clickerForm, 'newClicker').and.callThrough(); | ||
spyOn(clickerForm['clickerService'], 'newClicker').and.callThrough(); | ||
}) | ||
.catch(Utils.promiseCatchHandler); | ||
})); | ||
beforeEachProviders(() => providers); | ||
beforeEach(injectAsyncWrapper(asyncCallbackFactory(ClickerForm, this, false, beforeEachFn))); | ||
|
||
it('initialises', () => { | ||
expect(clickerForm).not.toBeNull(); | ||
expect(this.fixture).not.toBeNull(); | ||
expect(this.instance).not.toBeNull(); | ||
}); | ||
|
||
it('passes new clicker through to service', () => { | ||
let clickerName: string = 'dave'; | ||
let input: any = clickerFormFixture.nativeElement.querySelectorAll('.text-input')[0]; | ||
let button: any = clickerFormFixture.nativeElement.querySelectorAll('button')[1]; | ||
let input: any = this.fixture.nativeElement.querySelectorAll('.text-input')[0]; | ||
let button: any = this.fixture.nativeElement.querySelectorAll('button')[1]; | ||
spyOn(Utils, 'resetControl').and.callThrough(); | ||
input.value = clickerName; | ||
clickerFormFixture.detectChanges(); | ||
clickerForm['clickerNameInput']['updateValue'](clickerName, true); | ||
this.fixture.detectChanges(); | ||
this.instance['clickerNameInput']['updateValue'](clickerName, true); | ||
TestUtils.eventFire(input, 'input'); | ||
TestUtils.eventFire(button, 'click'); | ||
expect(clickerForm.newClicker).toHaveBeenCalledWith(Object({ clickerNameInput: clickerName })); | ||
expect(clickerForm['clickerService'].newClicker).toHaveBeenCalledWith(clickerName); | ||
expect(Utils.resetControl).toHaveBeenCalledWith(clickerForm['clickerNameInput']); | ||
expect(this.instance.newClicker).toHaveBeenCalledWith(Object({ clickerNameInput: clickerName })); | ||
expect(this.instance['clickerService'].newClicker).toHaveBeenCalledWith(clickerName); | ||
expect(Utils.resetControl).toHaveBeenCalledWith(this.instance['clickerNameInput']); | ||
}); | ||
|
||
it('doesn\'t try to add a clicker with no name', () => { | ||
let button: any = clickerFormFixture.nativeElement.querySelectorAll('button')[1]; | ||
let button: any = this.fixture.nativeElement.querySelectorAll('button')[1]; | ||
TestUtils.eventFire(button, 'click'); | ||
expect(clickerForm.newClicker).toHaveBeenCalled(); | ||
expect(clickerForm['clickerService'].newClicker).not.toHaveBeenCalled(); | ||
expect(this.instance.newClicker).toHaveBeenCalled(); | ||
expect(this.instance['clickerService'].newClicker).not.toHaveBeenCalled(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,68 +1,17 @@ | ||
import { | ||
beforeEach, | ||
beforeEachProviders, | ||
describe, | ||
expect, | ||
injectAsync, | ||
it, | ||
} from '@angular/core/testing'; | ||
import { | ||
ComponentFixture, | ||
TestComponentBuilder, | ||
} from '@angular/compiler/testing'; | ||
import { provide } from '@angular/core'; | ||
import { ClickerList } from './clickerList'; | ||
import { Utils } from '../../services/utils'; | ||
import { | ||
Config, | ||
Form, | ||
App, | ||
NavController, | ||
NavParams, | ||
Platform, | ||
} from 'ionic-angular'; | ||
import { beforeEach, beforeEachProviders, describe, expect, it } from '@angular/core/testing'; | ||
import { asyncCallbackFactory, injectAsyncWrapper, providers } from '../../../test/diExports'; | ||
import { ClickerList } from './clickerList'; | ||
|
||
class MockClass { | ||
public get(): any { | ||
return ''; | ||
} | ||
|
||
public getBoolean(): boolean { | ||
return true; | ||
} | ||
|
||
public getNumber(): number { | ||
return 42; | ||
} | ||
} | ||
|
||
let clickerList: ClickerList = null; | ||
let clickerListFixture: ComponentFixture<ClickerList> = null; | ||
this.fixture = null; | ||
this.instance = null; | ||
|
||
describe('ClickerList', () => { | ||
|
||
beforeEachProviders(() => [ | ||
Form, | ||
provide(NavController, {useClass: MockClass}), | ||
provide(NavParams, {useClass: MockClass}), | ||
provide(Config, {useClass: MockClass}), | ||
provide(App, {useClass: MockClass}), | ||
provide(Platform, {useClass: MockClass}), | ||
]); | ||
|
||
beforeEach(injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { | ||
return tcb | ||
.createAsync(ClickerList) | ||
.then((componentFixture: ComponentFixture<ClickerList>) => { | ||
clickerListFixture = componentFixture; | ||
clickerList = componentFixture.componentInstance; | ||
clickerListFixture.detectChanges(); | ||
}) | ||
.catch(Utils.promiseCatchHandler); | ||
})); | ||
beforeEachProviders(() => providers); | ||
beforeEach(injectAsyncWrapper(asyncCallbackFactory(ClickerList, this, true))); | ||
|
||
it('initialises', () => { | ||
expect(clickerList).not.toBeNull(); | ||
expect(clickerListFixture).not.toBeNull(); | ||
expect(this.instance).not.toBeNull(); | ||
expect(this.fixture).not.toBeNull(); | ||
}); | ||
}); |
Oops, something went wrong.