/
create.js
133 lines (120 loc) · 3.17 KB
/
create.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import Ember from 'ember';
import Ceibo from 'ceibo';
import { text } from './queries/text';
import { isVisible } from './predicates/is-visible';
import { isHidden } from './predicates/is-hidden';
import { contains } from './predicates/contains';
import { clickOnText } from './actions/click-on-text';
import { clickable } from './actions/clickable';
import { render, setContext, removeContext } from './context';
const merge = Ember.assign || Ember.merge;
var thenDescriptor = {
isDescriptor: true,
value() {
/* global wait */
return wait().then(...arguments);
}
};
var defaultProperties = {
isVisible: isVisible,
isHidden: isHidden,
clickOn: clickOnText,
click: clickable,
contains: contains,
text: text,
then: thenDescriptor
};
function plugDefaultProperties(definition) {
Object.keys(defaultProperties).forEach(key => {
if (typeof(definition[key]) !== 'undefined') {
return;
}
if (typeof(defaultProperties[key]) === 'function') {
definition[key] = defaultProperties[key]();
} else {
definition[key] = defaultProperties[key];
}
});
}
// See https://github.com/san650/ceibo#examples for more info on how Ceibo
// builders work.
function buildObject(node, blueprintKey, blueprint, defaultBuilder) {
blueprint = { ...blueprint };
plugDefaultProperties(blueprint);
return defaultBuilder(node, blueprintKey, blueprint, defaultBuilder);
}
/**
* Creates a new PageObject.
*
* By default, the resulting PageObject will respond to:
*
* - **Actions**: click, clickOn
* - **Predicates**: contains, isHidden, isVisible
* - **Queries**: text
*
* `definition` can include a key `context`, which is an
* optional integration test `this` context.
*
* If a context is passed, it is used by actions, queries, etc.,
* as the `this` in `this.$()`.
*
* If no context is passed, the global Ember acceptence test
* helpers are used.
*
* @example
*
* // <div class="title">My title</div>
*
* import PageObject, { text } from 'ember-cli-page-object';
*
* const page = PageObject.create({
* title: text('.title')
* });
*
* assert.equal(page.title, 'My title');
*
* @example
*
* // <div id="my-page">
* // My super text
* // <button>Press Me</button>
* // </div>
*
* const page = PageObject.create({
* scope: '#my-page'
* });
*
* assert.equal(page.text, 'My super text');
* assert.ok(page.contains('super'));
* assert.ok(page.isVisible);
* assert.notOk(page.isHidden);
*
* // clicks div#my-page
* page.click();
*
* // clicks button
* page.clickOn('Press Me');
*
* @public
*
* @param {Object} definition - PageObject definition
* @param {Object} [definition.context] - A test's `this` context
* @param {Object} options - [private] Ceibo options. Do not use!
* @return {PageObject}
*/
export function create(definition, options = {}) {
definition = { ...definition };
var context = definition.context;
delete definition.context;
var builder = {
object: buildObject
};
var page = Ceibo.create(definition, merge({ builder }, options));
if (page) {
page.render = render;
page.setContext = setContext;
page.removeContext = removeContext;
page.setContext(context);
}
return page;
}