Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
- Add "key" arg to "getter("
- Add "chainable" option to the "alias("
- Add missing "scope" option to FindOneOptions
- Fix "triggerable(" options
- Fix "text(" options
- Add "selactable(" types
- Assume "objectAt(" always returns a found page object instance
  • Loading branch information
ro0gr committed Jan 24, 2020
1 parent 3df78b8 commit d068b4c
Show file tree
Hide file tree
Showing 20 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let screenPage = create({
let page = create({
visit: visitable('/calculator'),
keys: keyboard,
screen: screenPage
screen: screenPage
});

moduleForAcceptance('Acceptance | composition');
Expand All @@ -54,7 +54,7 @@ test('allows compose', async function(assert) {
await page.screen.fillValue('45')
//click 6
await page.keys.numbers.objectAt(5).click();

assert.equal(page.screen.value, '456');
});

Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ moduleForProperty('alias', function(test) {
const page = create({
form: {
buttonText: text('button'),
isButtonReady: getter(function() {
isButtonReady: getter(function(this: any) {
return this.buttonText === 'Ready to Submit!';
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ moduleForProperty('getter', function(test) {
const page = create({
inputValue: value('input'),
isSubmitButtonDisabled: property('disabled', 'button'),
isFormEmpty: getter(function() {
isFormEmpty: getter(function(this: any): boolean {
return !this.inputValue && this.isSubmitButtonDisabled;
})
});
Expand All @@ -46,7 +46,7 @@ moduleForProperty('getter', function(test) {
assert.expect(2);

const page = create({
foo: getter(function(key) {
foo: getter(function(key: string) {
assert.equal(key, 'foo');
return true;
})
Expand All @@ -59,7 +59,7 @@ moduleForProperty('getter', function(test) {
assert.expect(1);

const page = create({
foo: getter('not a function')
foo: getter('not a function' as any)
});

assert.throws(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ moduleForProperty('triggerable', function(test) {

await this.adapter.createTemplate(this, page, '<input />');

this.adapter.$('input').on('keypress', (e) => assert.equal(e.keyCode, 13));
this.adapter.$('input').on('keypress', (e: KeyboardEvent) => assert.equal(e.keyCode, 13));

await this.adapter.await(page.foo());
});
Expand All @@ -42,7 +42,7 @@ moduleForProperty('triggerable', function(test) {

await this.adapter.createTemplate(this, page, '<input />');

this.adapter.$('input').on('keypress', (e) => assert.equal(e.keyCode, 13));
this.adapter.$('input').on('keypress', (e: KeyboardEvent) => assert.equal(e.keyCode, 13));

await this.adapter.await(page.foo({ keyCode: 13 }));
});
Expand All @@ -58,7 +58,7 @@ moduleForProperty('triggerable', function(test) {

await this.adapter.createTemplate(this, page, '<input />');

this.adapter.$('input').on('keypress', (e) => assert.equal(e.keyCode, 13));
this.adapter.$('input').on('keypress', (e: KeyboardEvent) => assert.equal(e.keyCode, 13));

await this.adapter.await(page.foo({ keyCode: 13 }));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ moduleForProperty('value', function(test) {
<input value="ipsum">
`);

assert.deepEqual(page.foo, ['lorem', 'ipsum']);
assert.deepEqual(page.foo as any, ['lorem', 'ipsum']);
});

test('finds element by index', async function(assert) {
Expand Down
15 changes: 8 additions & 7 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ declare module 'ember-cli-page-object' {
function isVisible(scope?: string, options?: FindOptions): GetterDescriptor<boolean>;
function isHidden(scope?: string, options?: FindOptions): GetterDescriptor<boolean>;
function isPresent(scope?: string, options?: FindOptions): GetterDescriptor<boolean>;
function text(scope?: string, options?: FindOptions): GetterDescriptor<string>;
function text(scope?: string, options?: FindOptions & { normalize?: boolean }): GetterDescriptor<string>;
function value(scope?: string, options?: FindOptions): GetterDescriptor<string>;
function property(name: string): GetterDescriptor<any>;
function property(scope: string, name: string, options?: FindOptions): GetterDescriptor<any>;
Expand All @@ -33,7 +33,8 @@ declare module 'ember-cli-page-object' {
function clickable(scope?: string, userOptions?: FindOptions): MethodDescriptor<<T>(this: T) => T>;
function clickOnText(scope?: string, userOptions?: FindOptions): MethodDescriptor<<T>(this: T, text: string) => T>;
function fillable(scope?: string, userOptions?: FindOptions): MethodDescriptor<<T>(this: T, clueOrContent: string, content?: string) => T>;
function triggerable(event: string, scope?: string, eventOptions?: TriggerOptions, options?: FindOptions): MethodDescriptor<<T>(this: T) => T>;
function selectable(scope?: string, userOptions?: FindOptions): MethodDescriptor<<T>(this: T, clueOrContent: string, content?: string) => T>;
function triggerable(event: string, scope?: string, eventOptions?: TriggerOptions, options?: FindOptions): MethodDescriptor<<T>(this: T, options?: {}) => T>;
function focusable(scope?: string, options?: FindOptions): MethodDescriptor<<T>(this: T) => T>;
function blurrable(scope?: string, options?: FindOptions): MethodDescriptor<<T>(this: T) => T>;
function visitable(path: string): MethodDescriptor<<T>(this: T, dynamicSegmentsAndQueryParams?: {}) => T>;
Expand All @@ -51,7 +52,7 @@ declare module 'ember-cli-page-object' {
forEach(callback: (c: Component<T>, i: number) => void): void;
map<S>(callback: (c: Component<T>) => S): S[];
mapBy(propName: keyof T | keyof DSL<T>): any[];
objectAt(i: number): Component<T>|undefined;
objectAt(i: number): Component<T>;
toArray(): Array<Component<T>>;
}
}
Expand All @@ -70,8 +71,8 @@ declare module 'ember-cli-page-object/extend' {
declare module 'ember-cli-page-object/macros' {
import { GetterDescriptor } from 'ember-cli-page-object/-private';

function getter<T>(body: () => T): GetterDescriptor<T>;
function alias(path: string): any;
function getter<T>(body: (key: string) => T): GetterDescriptor<T>;
function alias(path: string, options?: { chainable: boolean }): any;
}

declare module 'ember-cli-page-object/-private' {
Expand Down Expand Up @@ -149,8 +150,8 @@ declare module 'ember-cli-page-object/-private' {
at?: number;
}

interface TriggerOptions extends DomElementQueryOptions {
eventProperties: object;
interface TriggerOptions extends FindOptions {
eventProperties?: object;
}

interface DomElementQueryOptions extends SelectorQueryOptions {
Expand Down

0 comments on commit d068b4c

Please sign in to comment.