UNPKG

6.14 kBTypeScriptView Raw
1// TypeScript Version: 3.3
2declare module 'ember-cli-page-object' {
3 import {
4 Component,
5 Definition,
6 FindOptions,
7 TriggerOptions,
8 GetterDescriptor,
9 MethodDescriptor,
10 DSL
11 } from 'ember-cli-page-object/-private';
12
13 function create<T extends Partial<Definition>>(definition?: T): Component<T>;
14 function collection<T extends Partial<Definition>>(scope: string, definition?: T): Collection<T>;
15
16 // Attributes
17 function attribute(attributeName: string, scope?: string, options?: FindOptions): GetterDescriptor<string>;
18 function isVisible(scope?: string, options?: FindOptions): GetterDescriptor<boolean>;
19 function isHidden(scope?: string, options?: FindOptions): GetterDescriptor<boolean>;
20 function isPresent(scope?: string, options?: FindOptions): GetterDescriptor<boolean>;
21 function text(scope?: string, options?: FindOptions & { normalize?: boolean }): GetterDescriptor<string>;
22 function value(scope?: string, options?: FindOptions): GetterDescriptor<string>;
23 function property(name: string): GetterDescriptor<any>;
24 function property(scope: string, name: string, options?: FindOptions): GetterDescriptor<any>;
25 function hasClass(className: string): GetterDescriptor<boolean>;
26 function hasClass(scope: string, className: string, options?: FindOptions): GetterDescriptor<boolean>;
27 function notHasClass(className: string): GetterDescriptor<boolean>;
28 function notHasClass(scope: string, className: string, options?: FindOptions): GetterDescriptor<boolean>;
29 function contains(scope?: string, options?: FindOptions): (text: string) => GetterDescriptor<boolean>;
30 function count(scope?: string, options?: FindOptions): () => GetterDescriptor<boolean>;
31
32 // Actions
33 function clickable(scope?: string, userOptions?: FindOptions): MethodDescriptor<<T>(this: T) => T>;
34 function clickOnText(scope?: string, userOptions?: FindOptions): MethodDescriptor<<T>(this: T, text: string) => T>;
35 function fillable(scope?: string, userOptions?: FindOptions): MethodDescriptor<<T>(this: T, clueOrContent: string, content?: string) => T>;
36 function selectable(scope?: string, userOptions?: FindOptions): MethodDescriptor<<T>(this: T, clueOrContent: string, content?: string) => T>;
37 function triggerable(event: string, scope?: string, eventOptions?: TriggerOptions, options?: FindOptions): MethodDescriptor<<T>(this: T, options?: {}) => T>;
38 function focusable(scope?: string, options?: FindOptions): MethodDescriptor<<T>(this: T) => T>;
39 function blurrable(scope?: string, options?: FindOptions): MethodDescriptor<<T>(this: T) => T>;
40 function visitable(path: string): MethodDescriptor<<T>(this: T, dynamicSegmentsAndQueryParams?: {}) => T>;
41
42 interface Collection<T> {
43 (scope: string, definition?: T): Array<Component<T>>;
44
45 [i: number]: Component<T>;
46 [Symbol.iterator](): Iterator<Component<T>>;
47
48 filter(callback: (c: Component<T>) => boolean): Array<Component<T>>;
49 filterBy(propName: keyof T | keyof DSL<T>, value?: any): Array<Component<T>>;
50 findOne(callback: (c: Component<T>) => boolean): Component<T>;
51 findOneBy(propName: keyof T | keyof DSL<T>, value: any): Component<T>;
52 forEach(callback: (c: Component<T>, i: number) => void): void;
53 map<S>(callback: (c: Component<T>) => S): S[];
54 mapBy(propName: keyof T | keyof DSL<T>): any[];
55 objectAt(i: number): Component<T>;
56 toArray(): Array<Component<T>>;
57 }
58}
59
60declare module 'ember-cli-page-object/extend' {
61 import 'jquery';
62 import { Component, FindOptions, FindOneOptions } from 'ember-cli-page-object/-private';
63
64 function findElement(pageObject: Component, scope?: string, options?: FindOptions): JQuery;
65 function findElementWithAssert(pageObject: Component, scope?: string, options?: FindOptions): JQuery;
66
67 function findOne(pageObject: Component, scope?: string, options?: FindOneOptions): Element;
68 function findMany(pageObject: Component, scope?: string, options?: FindOptions): Element[];
69}
70
71declare module 'ember-cli-page-object/macros' {
72 import { GetterDescriptor } from 'ember-cli-page-object/-private';
73
74 function getter<T>(body: (key: string) => T): GetterDescriptor<T>;
75 function alias(path: string, options?: { chainable: boolean }): any;
76}
77
78declare module 'ember-cli-page-object/-private' {
79 import 'jquery';
80 import {
81 clickable,
82 clickOnText,
83 fillable,
84 focusable,
85 blurrable
86 } from 'ember-cli-page-object';
87
88 interface GetterDescriptor<T> {
89 isGetter: true;
90
91 get: T;
92 }
93
94 interface MethodDescriptor<T extends <S>(this: S, ...args: any[]) => S> {
95 isMethod: true;
96
97 (...args: Parameters<T>): ReturnType<T>;
98
99 get(): T;
100 }
101
102 type Component<T = Definition> = UnpackedDefinition<T> & DSL<T> & {
103 [s: string]: unknown;
104 };
105
106 type UnpackedDefinition<T> = {
107 [k in keyof T]:
108 T[k] extends GetterDescriptor<infer C> ? C
109 : T[k] extends MethodDescriptor<infer C> ? C
110 : T[k] extends Function | Component ? T[k]
111 : T[k] extends object ? Component<T[k]>
112 : T[k]
113 };
114
115 interface DSL<T> {
116 isHidden?: boolean;
117 isPresent?: boolean;
118 isVisible?: boolean;
119 text?: string;
120 value?: string;
121 contains(textToSearch: string): boolean;
122
123 blur(): Component<T>;
124 click(): Component<T>;
125 clickOn(text: string): Component<T>;
126 fillIn(clueOrContent: string, content?: string): Component<T>;
127 focus(): Component<T>;
128
129 then(
130 onfulfilled?: (value: any) => any,
131 onrejected?: (reason: any) => any
132 ): Component<T>;
133 }
134
135 interface Definition extends SelectorQueryOptions {
136 scope?: string;
137
138 [l: string]: unknown;
139 }
140
141 interface FindOptions extends FindOneOptions {
142 multiple?: boolean;
143 }
144
145 interface FindOneOptions extends DomElementQueryOptions {
146 contains?: string;
147 scope?: string;
148 last?: boolean;
149 visible?: boolean;
150 at?: number;
151 }
152
153 interface TriggerOptions extends FindOptions {
154 eventProperties?: object;
155 }
156
157 interface DomElementQueryOptions extends SelectorQueryOptions {
158 pageObjectKey?: string;
159 }
160
161 interface SelectorQueryOptions {
162 resetScope?: boolean;
163 testContainer?: string|HTMLElement|JQuery;
164 }
165}