-
Notifications
You must be signed in to change notification settings - Fork 46
/
rxCollapse.page.js
169 lines (154 loc) · 4.4 KB
/
rxCollapse.page.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
var _ = require('lodash');
var Page = require('astrolabe').Page;
/**
* @namespace
*/
var rxCollapse = {
/**
* @instance
* @function
* @description Whether the root element is currently displayed.
* @returns {Boolean}
*/
isDisplayed: {
value: function () {
return this.rootElement.isDisplayed();
}
},
/**
* @instance
* @function
* @description Whether or not the component is currently expanded.
* @returns {Promise<Boolean>}
*/
isExpanded: {
value: function () {
return this.rootElement.$('.expanded').isPresent();
}
},
/**
* @instance
* @function
* @deprecated
* @description Whether or not the component is currently collapsed.
*
* **DEPRECATED** Check inverse of `isExpanded()` instead.
* @returns {Promise<Boolean>}
*/
isCollapsed: {
value: function () {
return this.isExpanded().then(function (expanded) {
return !expanded;
});
}
},
/**
* @instance
* @function
* @description Whether or not the component has a custom title.
* @returns {Boolean}
*/
hasCustomTitle: {
value: function () {
return this.rootElement.$('.collapse-title-wrap').getAttribute('class').then(function (classes) {
return _.contains(classes.split(' '), 'collapse-title-wrap-custom');
});
}
},
/**
* @instance
* @description Will return the custom title's text if the component uses one. Otherwise, it'll return
* the default title, found in the `.sml-title` (see-more-less-title) class.
* @type {String}
*/
title: {
get: function () {
var page = this;
return this.hasCustomTitle().then(function (hasCustomTitle) {
if (hasCustomTitle) {
return page.rootElement.$('.rx-collapse-title').getText();
} else {
return page.rootElement.$('.sml-title').getText();
}
});
}
},
/**
* @instance
* @description Will expand the component if collapsed, or will collapse it if it's expanded.
* @function
*/
toggle: {
value: function () {
var page = this;
return this.hasCustomTitle().then(function (hasCustomTitle) {
if (hasCustomTitle) {
return page.rootElement.$('.double-chevron').click();
} else {
return page.rootElement.$('.sml-title').click();
}
});
}
},
/**
* @instance
* @function
* @description Will toggle the component only if it's currently collapsed.
*/
expand: {
value: function () {
var page = this;
return this.isExpanded().then(function (expanded) {
if (!expanded) {
page.toggle();
}
});
}
},
/**
* @instance
* @function
* @description Will toggle the component only if it's currently expanded.
*/
collapse: {
value: function () {
var page = this;
return this.isExpanded().then(function (expanded) {
if (expanded) {
page.toggle();
}
});
}
}
};
exports.rxCollapse = {
/**
* @function
* @memberof rxCollapse
* @description Creates a page object from an `[rx-collapse]` DOM element.
* @param {ElementFinder} [rxCollapseElement=$('rx-collapse')] -
* ElementFinder to be transformed into an {@link rxCollapse} object.
* @returns {rxCollapse}
*/
initialize: function (rxCollapseElement) {
if (rxCollapseElement === undefined) {
rxCollapseElement = $('rx-collapse');
}
rxCollapse.rootElement = {
get: function () { return rxCollapseElement; }
};
return Page.create(rxCollapse);
},
/**
* @deprecated
* @memberof rxCollapse
* @description Creates a page object from the first `[rx-bulk-select]` DOM element present on the page.
* @type {rxCollapse}
*/
main: (function () {
rxCollapse.rootElement = {
get: function () { return $('rx-collapse'); }
};
return Page.create(rxCollapse);
})()
};