-
Notifications
You must be signed in to change notification settings - Fork 6
/
page-object.js
45 lines (30 loc) · 1.4 KB
/
page-object.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { assert } from '@ember/debug';
import { create } from 'ember-cli-page-object';
import { useNativeEvents } from 'ember-cli-page-object/extend';
import { extractPageObjects, extractGetters, deepMergeDescriptors } from './utils/descriptors';
// pre-emptively turn on native events since we'll need them
useNativeEvents();
function extendDefinition(definition, extension) {
assert('must provide a string or an object to extend', extension !== null && (typeof extension === 'string' || typeof extension === 'object'));
assert('must provide a definition with atleast one key when extending a PageObject', extension && Object.keys(extension).length > 0);
let finalizedDefinition = typeof extension === 'string' ? { scope: extension } : extension;
finalizedDefinition = extractPageObjects(finalizedDefinition);
finalizedDefinition = extractGetters(finalizedDefinition);
finalizedDefinition = deepMergeDescriptors(
finalizedDefinition, definition
);
return finalizedDefinition;
}
export default class PageObject {
constructor(extension) {
let definition = this.constructor._definition;
definition = extension ? extendDefinition(definition, extension) : definition;
return create(definition);
}
static extend(extension) {
let Page = class extends this {};
Page._definition = extendDefinition(this._definition, extension);
return Page;
}
}
PageObject._definition = {};