forked from ember-bootstrap/ember-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap-test.js
159 lines (124 loc) · 3.75 KB
/
bootstrap-test.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
import config from 'dummy/config/environment';
import test from 'ember-sinon-qunit/test-support/test';
import { skip } from 'qunit';
import { Promise } from 'rsvp';
const currentBootstrapVersion = parseInt(config.bootstrapVersion);
function testForBootstrap(bsVersion, name, fn) {
if (bsVersion !== currentBootstrapVersion) {
// Skip test for different Bootstrap version
return;
}
return test(`${name} [BS${bsVersion}]`, fn);
}
export function testBS3() {
return testForBootstrap(3, ...arguments);
}
export function testBS4() {
return testForBootstrap(4, ...arguments);
}
export function versionDependent(v3, v4) {
if (currentBootstrapVersion === 3) {
return v3;
}
return v4;
}
export function visibilityClass() {
return versionDependent('in', 'show');
}
export function openClass() {
return versionDependent('open', 'show');
}
export function defaultButtonClass() {
return versionDependent('btn-default', 'btn-secondary');
}
export function formFeedbackClass() {
return versionDependent('help-block', 'invalid-feedback');
}
export function formFeedbackElement() {
return versionDependent('.form-group', '.form-control');
}
export function validationSuccessClass() {
return versionDependent('has-success', 'is-valid');
}
export function validationErrorClass() {
return versionDependent('has-error', 'is-invalid');
}
export function validationWarningClass() {
return versionDependent('has-warning', 'is-warning');
}
export function placementClassFor(type, placement) {
return versionDependent(placement, `${type}-${placement}`);
}
export function positionClassFor(position) {
return versionDependent(`navbar-${position}`, position);
}
export function positionStickyClass() {
return versionDependent('navbar-static-top', 'sticky-top');
}
export function formHelpTextClass() {
return versionDependent('help-block', 'form-text');
}
export function accordionClassFor(type) {
type = type ? `-${type}` : '';
return versionDependent(`panel${type}`, type ? `bg${type}` : 'card');
}
export function accordionTitleSelector() {
return versionDependent('.panel-title', 'h5');
}
export function accordionItemHeadClass() {
return versionDependent('panel-heading', 'card-header');
}
export function accordionItemClickableSelector() {
return versionDependent('.panel-title a', 'h5 button');
}
export function dropdownVisibilityElementSelector() {
return versionDependent('.dropdown', '.dropdown-menu');
}
export function accordionItemBodyClass() {
return versionDependent('panel-body', 'card-body');
}
export function tooltipPositionClass(pos) {
return versionDependent(pos, `bs-tooltip-${pos}`);
}
export function popoverPositionClass(pos) {
return versionDependent(pos, `bs-popover-${pos}`);
}
export function tooltipArrowClass() {
return versionDependent('tooltip-arrow', 'arrow');
}
export function isVisible(el) {
return !isHidden(el);
}
export function isHidden(el) {
// A bit of an odd test, but taken from https://stackoverflow.com/questions/19669786/check-if-element-is-visible-in-dom
// referencing https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent
return !el || el.offsetParent === null;
}
export { test };
export function testRequiringFocus(name, fn) {
if (document.hasFocus()) {
return test(name, fn);
} else {
skip(name);
}
}
export function testBS3RequiringFocus(name, fn) {
if (document.hasFocus()) {
return testBS3(name, fn);
} else {
skip(name);
}
}
export function testBS4RequiringFocus(name, fn) {
if (document.hasFocus()) {
return testBS4(name, fn);
} else {
skip(name);
}
}
export function testRequiringTransitions(name, fn) {
return test(name, fn);
}
export function delay(delay) {
return new Promise((resolve) => setTimeout(resolve, delay));
}