@thednp/shorty 2.0.0-alpha8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/.eslintrc.cjs +224 -0
  2. package/.lgtm.yml +8 -0
  3. package/.prettierrc.json +15 -0
  4. package/README.md +5 -5
  5. package/cypress/e2e/att.cy.ts +46 -0
  6. package/cypress/e2e/boolean.cy.ts +44 -0
  7. package/cypress/e2e/class.cy.ts +28 -0
  8. package/cypress/e2e/event.cy.ts +51 -0
  9. package/cypress/e2e/get.cy.ts +168 -0
  10. package/cypress/e2e/is.cy.ts +233 -0
  11. package/cypress/e2e/misc.cy.ts +354 -0
  12. package/cypress/e2e/selectors.cy.ts +85 -0
  13. package/cypress/fixtures/custom-elem.js +18 -0
  14. package/cypress/plugins/esbuild-istanbul.ts +50 -0
  15. package/cypress/plugins/tsCompile.ts +34 -0
  16. package/cypress/support/commands.ts +37 -0
  17. package/cypress/support/e2e.ts +21 -0
  18. package/cypress/support/index.js +22 -0
  19. package/cypress/test.html +63 -0
  20. package/cypress.config.ts +30 -0
  21. package/dist/shorty.cjs +1 -1
  22. package/dist/shorty.cjs.map +1 -1
  23. package/dist/shorty.d.ts +228 -6
  24. package/dist/shorty.js +1 -1
  25. package/dist/shorty.js.map +1 -1
  26. package/dist/shorty.mjs +473 -350
  27. package/dist/shorty.mjs.map +1 -1
  28. package/dts.config.ts +21 -0
  29. package/package.json +73 -73
  30. package/src/event/off.ts +4 -4
  31. package/src/event/on.ts +4 -4
  32. package/src/event/one.ts +6 -5
  33. package/src/index.ts +21 -0
  34. package/src/interface/event.d.ts +247 -0
  35. package/src/misc/ObjectFromEntries.ts +11 -0
  36. package/src/misc/createElement.ts +4 -10
  37. package/src/misc/createElementNS.ts +8 -13
  38. package/src/misc/data.ts +1 -0
  39. package/src/strings/dragEvent.ts +5 -0
  40. package/src/strings/dragendEvent.ts +5 -0
  41. package/src/strings/dragenterEvent.ts +5 -0
  42. package/src/strings/dragleaveEvent.ts +5 -0
  43. package/src/strings/dragoverEvent.ts +5 -0
  44. package/src/strings/dragstartEvent.ts +5 -0
  45. package/src/strings/keyNumpadEnter.ts +7 -0
  46. package/tsconfig.json +30 -0
  47. package/vite.config.ts +30 -0
@@ -0,0 +1,233 @@
1
+ /// <reference types="cypress" />
2
+ // @ts-nocheck
3
+
4
+ // import SHORTY from '../../src/index';
5
+ import * as SHORTY from '../../src/index';
6
+
7
+ import CustomElem from '../fixtures/custom-elem';
8
+
9
+ describe('Shorty Library Tests', () => {
10
+ before(() => {
11
+ cy.visit('cypress/test.html');
12
+ });
13
+
14
+ it('Test is folder', () => {
15
+ const {
16
+ isArray,
17
+ isCustomElement,
18
+ isDocument,
19
+ isElement,
20
+ isElementInScrollRange,
21
+ isElementInViewport,
22
+ isElementsArray,
23
+ isCanvas,
24
+ isFunction,
25
+ isHTMLCollection,
26
+ isHTMLElement,
27
+ isHTMLImageElement,
28
+ isJSON,
29
+ isMedia,
30
+ isMap,
31
+ isWeakMap,
32
+ isObject,
33
+ isNode,
34
+ isNodeList,
35
+ isRTL,
36
+ isScaledElement,
37
+ isShadowRoot,
38
+ isString,
39
+ isNumber,
40
+ isSVGElement,
41
+ isTableElement,
42
+ isWindow,
43
+ getWindow,
44
+ querySelector,
45
+ // getElementsByTagName,
46
+ } = SHORTY;
47
+
48
+ cy.get('div').then($element => {
49
+ // const win = getWindow($element[0]);
50
+ const CE = new CustomElem();
51
+ CE.className = 'btn btn-outline-primary';
52
+ CE.style.transform = 'scale(1.01)';
53
+ getWindow($element[0]).document.body.append(CE);
54
+ })
55
+ .wait(100)
56
+ .get('.alert').then($element => {
57
+ const element = $element[0];
58
+ const win = getWindow(element);
59
+ const CE = querySelector('custom-elem', win.document);
60
+ // CE.className = 'btn btn-outline-primary';
61
+ // CE.style.transform = 'scale(1.01)';
62
+ // win.document.body.append(CE);
63
+ const img = querySelector('img', element);
64
+ const svg = querySelector('svg', element);
65
+ const path = querySelector('path', element);
66
+ const table = querySelector('table', win.document);
67
+
68
+ expect(isArray(new Float32Array(0, 'a')), 'isArray(Float32Array)').to.be.false;
69
+ expect(isArray(), 'isArray()').to.be.false;
70
+ expect(isArray(element), 'isArray(node)').to.be.false;
71
+ expect(isArray([0, 'a']), 'isArray([0, 1]])').to.be.true;
72
+ expect(isArray(new Array(0, 'a')), 'isArray(new Array(0, 1)])').to.be.true;
73
+
74
+ expect(isDocument(), 'isDocument()').to.be.false;
75
+ expect(isDocument(win), 'isDocument(document)').to.be.false;
76
+ expect(isDocument(document), 'isDocument(document)').to.be.true;
77
+ expect(isDocument(win.document), 'isDocument(document)').to.be.true;
78
+
79
+ expect(isElement(), 'isElement()').to.be.false;
80
+ expect(isElement(win.document), 'isElement(document)').to.be.false;
81
+ expect(isElement(win), 'isElement(window)').to.be.false;
82
+ expect(isElement(element), 'isElement(node)').to.be.true;
83
+ expect(isElement(win.document.body), 'isElement(body)').to.be.true;
84
+
85
+ expect(isElementsArray(), 'isElementsArray()').to.be.false;
86
+ expect(isElementsArray(win), 'isElementsArray(window)').to.be.false;
87
+ expect(isElementsArray([0, 1]), 'isElementsArray(window)').to.be.false;
88
+ expect(isElementsArray([...element.children]), 'isElementsArray(expected)').to.be.true;
89
+
90
+ expect(isFunction(), 'isFunction()').to.be.false;
91
+ expect(isFunction(element), 'isFunction(node)').to.be.false;
92
+ expect(isFunction(element.addEventListener), 'isFunction(function)').to.be.true;
93
+
94
+ expect(isObject(), 'isObject()').to.be.false;
95
+ expect(isObject(element), 'isObject(node)').to.be.true;
96
+ expect(isObject({ a: 2 }), 'isObject(object)').to.be.true;
97
+ expect(isObject(element.addEventListener), 'isObject(function)').to.be.false;
98
+
99
+ expect(isHTMLCollection(), 'isHTMLCollection()').to.be.false;
100
+ expect(isHTMLCollection([...element.children]), 'isHTMLCollection(array)').to.be.false;
101
+ expect(isHTMLCollection(element.children), 'isHTMLCollection(expected)').to.be.true;
102
+
103
+ expect(isHTMLElement(), 'isHTMLElement()').to.be.false;
104
+ expect(isHTMLElement(element), 'isHTMLElement(element)').to.be.true;
105
+ expect(isHTMLElement(win), 'isHTMLElement(window)').to.be.false;
106
+ expect(isHTMLElement(win.document.body), 'isHTMLElement(body)').to.be.true;
107
+ expect(isHTMLElement(win.document.head), 'isHTMLElement(head)').to.be.true;
108
+ expect(isHTMLElement(CE), 'isHTMLElement(CustomElement)').to.be.true;
109
+ expect(isHTMLElement(CE.shadowRoot), 'isHTMLElement(CustomElement)').to.be.false;
110
+ expect(isHTMLElement([...element.children]), 'isHTMLElement(array)').to.be.false;
111
+ expect(isHTMLElement(win.document), 'isHTMLElement(document)').to.be.false;
112
+
113
+ expect(isHTMLImageElement(), 'isHTMLImageElement()').to.be.false;
114
+ expect(isHTMLImageElement(win.document), 'isHTMLImageElement(document)').to.be.false;
115
+ expect(isHTMLImageElement(win), 'isHTMLImageElement(window)').to.be.false;
116
+ expect(isHTMLImageElement(img), 'isHTMLImageElement(image)').to.be.true;
117
+ expect(isHTMLImageElement(svg), 'isHTMLImageElement(svg)').to.be.false;
118
+ expect(isHTMLImageElement(path), 'isHTMLImageElement(path)').to.be.false;
119
+
120
+ expect(isMedia(), 'isMedia()').to.be.false;
121
+ expect(isMedia(win.document), 'isMedia(document)').to.be.false;
122
+ expect(isMedia(win), 'isMedia(window)').to.be.false;
123
+ expect(isMedia(CE), 'isMedia(CustomElement)').to.be.false;
124
+ expect(isMedia(img), 'isMedia(image)').to.be.true;
125
+ expect(isMedia(svg), 'isMedia(svg)').to.be.true;
126
+ expect(isMedia(path), 'isMedia(path)').to.be.true;
127
+
128
+ expect(isCanvas(), 'isCanvas()').to.be.false;
129
+ expect(isCanvas(win.document), 'isCanvas(document)').to.be.false;
130
+ expect(isCanvas(win), 'isCanvas(window)').to.be.false;
131
+ expect(isCanvas(CE), 'isCanvas(CustomElement)').to.be.false;
132
+ expect(isCanvas(img), 'isCanvas(image)').to.be.false;
133
+ expect(isCanvas(svg), 'isCanvas(svg)').to.be.false;
134
+ expect(isCanvas(win.document.createElement('canvas')), 'isCanvas(canvas)').to.be.true;
135
+
136
+ expect(isJSON(), 'isJSON()').to.be.false;
137
+ expect(isJSON(win.document), 'isJSON(document)').to.be.false;
138
+ expect(isJSON(win), 'isJSON(window)').to.be.false;
139
+ expect(isJSON('some string'), 'isJSON(JSON)').to.be.false;
140
+ expect(isJSON('{"a":1,"b":2}'), 'isJSON(JSON)').to.be.true;
141
+ expect(isJSON('["a",2]'), 'isJSON(JSON)').to.be.true;
142
+
143
+ expect(isMap(), 'isMap()').to.be.false;
144
+ expect(isMap(win.document), 'isMap(document)').to.be.false;
145
+ expect(isMap(win), 'isMap(window)').to.be.false;
146
+ expect(isMap(new Map()), 'isMap(Map)').to.be.true;
147
+
148
+ expect(isWeakMap(), 'isWeakMap()').to.be.false;
149
+ expect(isWeakMap(win.document), 'isWeakMap(document)').to.be.false;
150
+ expect(isWeakMap(win), 'isWeakMap(window)').to.be.false;
151
+ expect(isWeakMap(new WeakMap()), 'isWeakMap(WeakMap)').to.be.true;
152
+
153
+ expect(isElementInScrollRange(), 'isElementInScrollRange()').to.be.false;
154
+ expect(isElementInScrollRange(win), 'isElementInScrollRange(window)').to.be.false;
155
+ expect(isElementInScrollRange(CE), 'isElementInScrollRange(CustomElement)').to.be.true;
156
+ expect(isElementInScrollRange(element), 'isElementInScrollRange(node)').to.be.true;
157
+
158
+ expect(isElementInViewport(), 'isElementInScrollRange()').to.be.false;
159
+ expect(isElementInViewport(win), 'isElementInScrollRange(window)').to.be.false;
160
+ expect(isElementInViewport(CE), 'isElementInScrollRange(CustomElement)').to.be.true;
161
+ expect(isElementInViewport(element), 'isElementInScrollRange(node)').to.be.true;
162
+
163
+ expect(isNode(), 'isNode()').to.be.false;
164
+ expect(isNode(img), 'isNode(image)').to.be.true;
165
+ expect(isNode(svg), 'isNode(svg)').to.be.true;
166
+ expect(isNode(path), 'isNode(path)').to.be.true;
167
+ expect(isNode(win.document), 'isNode(document)').to.be.true;
168
+ expect(isNode(win), 'isNode(window)').to.be.false;
169
+ expect(isNode(CE), 'isNode(CustomElement)').to.be.true;
170
+
171
+ expect(isNodeList(), 'isNodeList()').to.be.false;
172
+ expect(isNodeList(element), 'isNodeList(node)').to.be.false;
173
+ expect(isNodeList(element.children), 'isNodeList(HTMLCollection)').to.be.false;
174
+ expect(isNodeList(element.querySelectorAll('*')), 'isNodeList(expected)').to.be.true;
175
+
176
+ expect(isRTL(), 'isRTL()').to.be.false;
177
+ expect(isRTL(element), 'isRTL(node)').to.be.false;
178
+ expect(isRTL(win.document), 'isRTL(document)').to.be.false;
179
+
180
+ expect(isScaledElement(), 'isScaledElement()').to.be.false;
181
+ expect(isScaledElement(element), 'isScaledElement(node)').to.be.false;
182
+ expect(isScaledElement(win), 'isScaledElement(window)').to.be.false;
183
+ expect(isScaledElement(win.document), 'isScaledElement(document)').to.be.false;
184
+ expect(isScaledElement(CE), 'isScaledElement(expected)').to.be.true;
185
+
186
+ expect(isSVGElement(), 'isSVGElement()').to.be.false;
187
+ expect(isSVGElement(element), 'isSVGElement(node)').to.be.false;
188
+ expect(isSVGElement(win), 'isSVGElement(window)').to.be.false;
189
+ expect(isSVGElement(win.document), 'isSVGElement(document)').to.be.false;
190
+ expect(isSVGElement(CE), 'isSVGElement(CustomElement)').to.be.false;
191
+ expect(isSVGElement(svg), 'isSVGElement(svg)').to.be.true;
192
+ expect(isSVGElement(path), 'isSVGElement(path)').to.be.true;
193
+
194
+ expect(isString(), 'isString()').to.be.false;
195
+ expect(isString(element), 'isString(node)').to.be.false;
196
+ expect(isString(element.nodeName), 'isString(nodeName)').to.be.true;
197
+ expect(isString(element.nodeType), 'isString(number)').to.be.false;
198
+
199
+ expect(isNumber(), 'isNumber()').to.be.false;
200
+ expect(isNumber(element), 'isNumber(node)').to.be.false;
201
+ expect(isNumber(element.nodeName), 'isNumber(nodeName)').to.be.false;
202
+ expect(isNumber(element.nodeType), 'isNumber(nodeType)').to.be.true;
203
+ expect(isNumber(0.55), 'isNumber(number)').to.be.true;
204
+ expect(isNumber(-Infinity), 'isNumber(Infinity)').to.be.true;
205
+
206
+ expect(isTableElement(), 'isTableElement()').to.be.false;
207
+ expect(isTableElement(element), 'isTableElement(node)').to.be.false;
208
+ expect(isTableElement(win), 'isTableElement(window)').to.be.false;
209
+ expect(isTableElement(win.document), 'isTableElement(document)').to.be.false;
210
+ expect(isTableElement(CE), 'isTableElement(CustomElement)').to.be.false;
211
+ expect(isTableElement(table), 'isTableElement(table)').to.be.true;
212
+ expect(isTableElement(querySelector('td', table)), 'isTableElement(TD)').to.be.true;
213
+ expect(isTableElement(querySelector('th', table)), 'isTableElement(TH)').to.be.true;
214
+
215
+ expect(isWindow(), 'isWindow()').to.be.false;
216
+ expect(isWindow(win.document), 'isWindow(document)').to.be.false;
217
+ expect(isWindow(document), 'isWindow(document)').to.be.false;
218
+ expect(isWindow(win), 'isDocument(window)').to.be.true;
219
+ expect(isWindow(win.top), 'isDocument(window)').to.be.true;
220
+ expect(isWindow(window), 'isDocument(window)').to.be.true;
221
+ expect(isWindow(window.top), 'isDocument(window)').to.be.true;
222
+
223
+ expect(isCustomElement(), 'isCustomElement()').to.be.false;
224
+ expect(isCustomElement(element), 'isCustomElement(node)').to.be.false;
225
+ expect(isCustomElement(CE), 'isCustomElement(CustomElement)').to.be.true;
226
+
227
+ expect(isShadowRoot(), 'isShadowRoot()').to.be.false;
228
+ expect(isShadowRoot(element), 'isShadowRoot(element)').to.be.false;
229
+ expect(isShadowRoot(document), 'isShadowRoot(document)').to.be.false;
230
+ expect(isShadowRoot(CE.shadowRoot), 'isShadowRoot(CustomElement.shadowRoot)').to.be.true;
231
+ });
232
+ });
233
+ });
@@ -0,0 +1,354 @@
1
+ /// <reference types="cypress" />
2
+ // @ts-nocheck
3
+
4
+ // import SHORTY from '../../src/index';
5
+ import * as SHORTY from '../../src/index';
6
+
7
+ describe('Shorty Library Tests', () => {
8
+ beforeEach(() => {
9
+ cy.visit('cypress/test.html');
10
+ });
11
+
12
+ it('Test misc folder - emulateTransitionEnd - no transition', () => {
13
+ const {
14
+ dispatchEvent,
15
+ emulateTransitionEnd,
16
+ createCustomEvent,
17
+ reflow,
18
+ querySelector,
19
+ setElementStyle,
20
+ getElementStyle,
21
+ removeClass,
22
+ addClass,
23
+ one,
24
+ } = SHORTY;
25
+
26
+ cy
27
+ .window()
28
+ .then(win => {
29
+ const el = querySelector('.alert', win.document) as HTMLElement;
30
+ const btn = querySelector('.btn-close', el);
31
+ const alertHideEvent = createCustomEvent('hide-alert', { relatedTarget: null });
32
+
33
+ setElementStyle(el, {
34
+ transition: 'none',
35
+ transitionProperty: 'none',
36
+ transitionDuration: '0s',
37
+ 'transition-delay': '0s',
38
+ '--transition-prop': 'none',
39
+ });
40
+
41
+ expect(getElementStyle(el, 'transitionProperty')).to.equal('none');
42
+ expect(getElementStyle(el, 'transition-duration')).to.equal('0s');
43
+ expect(getElementStyle(el, 'transitionDelay')).to.equal('0s');
44
+ expect(getElementStyle(el, '--transition-prop')).to.equal('none');
45
+
46
+ cy.log('emulateTransitionEnd').then(() => {
47
+ one(el, 'hide-alert', function hideHandler(e) {
48
+ cy.log('hide-alert triggered');
49
+ expect(e.target).to.equal(el);
50
+ expect(e.relatedTarget).to.equal(btn);
51
+ });
52
+
53
+ one(btn, 'click', function handleBtn(e) {
54
+ cy.log('clicked btn');
55
+ expect(e.target).to.equal(btn);
56
+ removeClass(el, 'show');
57
+ reflow(el);
58
+ alertHideEvent.relatedTarget = btn;
59
+ dispatchEvent(el, alertHideEvent);
60
+ emulateTransitionEnd(el, function () {
61
+ addClass(el, 'show');
62
+ cy.log('transitionend triggered');
63
+ });
64
+ });
65
+
66
+ btn.click();
67
+ cy.wait(100);
68
+ });
69
+ });
70
+ });
71
+
72
+ it('Test misc folder - emulateTransitionEnd - default', () => {
73
+ const {
74
+ dispatchEvent,
75
+ emulateTransitionEnd,
76
+ createCustomEvent,
77
+ reflow,
78
+ querySelector,
79
+ removeClass,
80
+ addClass,
81
+ one,
82
+ focus,
83
+ } = SHORTY;
84
+
85
+ cy
86
+ // .wait('@pageload')
87
+ .window()
88
+ .then(win => {
89
+ const el = querySelector('.alert', win.document);
90
+ const btn = querySelector('.btn-close', el);
91
+ const alertHideEvent = createCustomEvent('hide-alert', { relatedTarget: null });
92
+
93
+ cy.log('begin **emulateTransitionEnd**').then(() => {
94
+ one(el, 'hide-alert', function hideHandler(e) {
95
+ cy.log('hide-alert triggered');
96
+ expect(e.target).to.equal(el);
97
+ expect(e.relatedTarget).to.equal(btn);
98
+ });
99
+
100
+ one(btn, 'click', function handleBtn(e) {
101
+ cy.log('clicked btn');
102
+ expect(e.target).to.equal(btn);
103
+ removeClass(el, 'show');
104
+ reflow(el);
105
+ alertHideEvent.relatedTarget = btn;
106
+ dispatchEvent(el, alertHideEvent);
107
+ emulateTransitionEnd(el, function () {
108
+ addClass(el, 'show');
109
+ focus(btn);
110
+ console.log('transitionend triggered');
111
+ });
112
+ });
113
+
114
+ btn.click();
115
+ cy.wait(300);
116
+ });
117
+ });
118
+ });
119
+
120
+ it('Test misc folder - emulateAnimationEnd - default', () => {
121
+ const { emulateAnimationEnd, getElementStyle, querySelector, addClass } = SHORTY;
122
+ cy
123
+ // .wait('@pageload')
124
+ .window()
125
+ .then(win => {
126
+ const el = querySelector('.alert', win.document);
127
+
128
+ cy.log('begin **emulateAnimationEnd**').then(() => {
129
+ addClass(el, 'animate-test');
130
+ emulateAnimationEnd(el, () => {
131
+ console.log('animationend fired');
132
+ expect(getElementStyle(el, 'animationName'), 'animationName').to.equal('animate-test');
133
+ expect(getElementStyle(el, 'animationDuration'), 'animationDuration').to.equal('0.3s');
134
+ expect(getElementStyle(el, 'animationDelay'), 'animationDelay').to.equal('0s');
135
+ });
136
+
137
+ cy.wait(350);
138
+ });
139
+ });
140
+ });
141
+
142
+ it('Test misc folder - emulateAnimationEnd - no duration', () => {
143
+ const { emulateAnimationEnd, setElementStyle, getElementStyle, querySelector, addClass } =
144
+ SHORTY;
145
+ cy
146
+ // .wait('@pageload')
147
+ .window()
148
+ .then(win => {
149
+ const el = querySelector('.alert', win.document);
150
+ setElementStyle(el, { animationDuration: '0s' });
151
+
152
+ cy.log('begin **emulateAnimationEnd**').then(() => {
153
+ addClass(el, 'animate-test');
154
+ emulateAnimationEnd(el, () => {
155
+ console.log('animationend fired');
156
+ expect(getElementStyle(el, 'animationName'), 'animationName').to.equal('animate-test');
157
+ expect(getElementStyle(el, 'animationDuration'), 'animationDuration').to.equal('0s');
158
+ expect(getElementStyle(el, 'animationDelay'), 'animationDelay').to.equal('0s');
159
+ });
160
+
161
+ cy.wait(100);
162
+ });
163
+ });
164
+ });
165
+
166
+ it('Test misc folder - everything else', () => {
167
+ const {
168
+ ArrayFrom,
169
+ Float32ArrayFrom,
170
+ Float64ArrayFrom,
171
+ distinct,
172
+ noop,
173
+ ObjectHasOwn,
174
+ ObjectEntries,
175
+ ObjectAssign,
176
+ ObjectKeys,
177
+ ObjectValues,
178
+ ObjectDefineProperty,
179
+ createElement,
180
+ createElementNS,
181
+ Data,
182
+ getInstance,
183
+ normalizeOptions,
184
+ Timer,
185
+ toLowerCase,
186
+ toUpperCase,
187
+ querySelector,
188
+ getElementsByClassName,
189
+ } = SHORTY;
190
+ cy
191
+ // .wait('@pageload')
192
+ .window()
193
+ .then(win => {
194
+ const el = querySelector('.alert', win.document);
195
+ const table = querySelector('.table', win.document);
196
+
197
+ const defaults = { op1: true, op2: true, op3: 5, title: null };
198
+ const jsOps = { op1: false, op2: false, op3: 8, title: 'something' };
199
+ expect(ObjectHasOwn(jsOps,'op3')).to.be.true;
200
+ expect(ObjectHasOwn(jsOps,'momo')).to.be.false;
201
+ expect(ObjectHasOwn(null,'momo')).to.be.false;
202
+ expect(normalizeOptions(el, defaults, {}, 'bs'), 'normalizeOptions(data)').to.deep.equal({
203
+ op1: false,
204
+ op2: true,
205
+ op3: 10,
206
+ title: null,
207
+ });
208
+ expect(normalizeOptions(el, defaults, jsOps, 'bs'), 'normalizeOptions(js)').to.deep.equal({
209
+ op1: false,
210
+ op2: false,
211
+ op3: 8,
212
+ title: 'something',
213
+ });
214
+ expect(noop()).to.be.undefined;
215
+
216
+ Timer.set('el', noop, 150);
217
+ Timer.set(el, () => console.log(el.tagName + ' has timer of 150'), 150, 'alert');
218
+ expect(Timer.get('el', 'alert')).to.be.null;
219
+ expect(Timer.get(el, 'alert')).to.not.be.undefined;
220
+ Timer.clear('el', 'alert');
221
+ Timer.clear(el, 'alert');
222
+ expect(Timer.get(el, 'alert')).to.be.null;
223
+
224
+ Timer.set(el, () => console.log(el.tagName + ' has timer of 250'), 250);
225
+ expect(Timer.get(el)).to.not.be.null;
226
+ Timer.clear(el);
227
+ expect(Timer.get(el)).to.be.null;
228
+
229
+ expect([0, 1, 1, 2, 3, 3].filter(distinct), 'filter(DISTINCT)').to.deep.equal([0, 1, 2, 3]);
230
+
231
+ expect(toLowerCase('textSample'), 'toLowerCase(string)').to.equal('textsample');
232
+ expect(toUpperCase('textSample'), 'toUpperCase(string)').to.equal('TEXTSAMPLE');
233
+
234
+ // expect(
235
+ // Object.defineProperty({ c: 3}, 'a', { value: {b: 1}, writable: true }),
236
+ // 'ObjectDefineProperty(object1, prop, value)',
237
+ // ).to.deep.equal({ c: 3, a: {b: 1} });
238
+ expect(
239
+ ObjectAssign({ c: 3 }, { a: 1, b: 2 }),
240
+ 'ObjectAssign(object1, object2)',
241
+ ).to.deep.equal({ a: 1, b: 2, c: 3 });
242
+ expect(ObjectEntries({ a: 1, b: 2 }), 'ObjectEntries(object)').to.deep.equal([
243
+ ['a', 1],
244
+ ['b', 2],
245
+ ]);
246
+ expect(ObjectKeys({ a: 1, b: 2 }), 'ObjectKeys(object)').to.deep.equal(['a', 'b']);
247
+ expect(ObjectValues({ a: 1, b: 2 }), 'ObjectValues(object)').to.deep.equal([1, 2]);
248
+
249
+ expect(Float32ArrayFrom([0, 1, 2, 3]), 'Float32ArrayFrom(array)').to.be.instanceOf(
250
+ Float32Array,
251
+ );
252
+ expect(Float64ArrayFrom([0, 1, 2, 3]), 'Float64ArrayFrom(array)').to.be.instanceOf(
253
+ Float64Array,
254
+ );
255
+ expect(Float64ArrayFrom([0, 1, 2, 3]).length, 'Float64ArrayFrom(array)').to.eq(4);
256
+
257
+ expect(
258
+ ArrayFrom(new Float32Array([0, 1, 2, 3])),
259
+ 'ArrayFrom(Float32Array)',
260
+ ).to.be.instanceOf(Array);
261
+ expect(ArrayFrom(new Float64Array([0, 1, 2, 3])), 'Array(Float64Array)').to.be.instanceOf(
262
+ Array,
263
+ );
264
+ expect(
265
+ ArrayFrom(getElementsByClassName('table', win.document)),
266
+ 'ArrayFrom(HTMLCollection)',
267
+ ).to.deep.equal([table]);
268
+
269
+ expect(createElement(), 'createElement()').to.be.undefined;
270
+ expect(createElement('input'), 'createElement(string)').to.be.instanceOf(HTMLInputElement);
271
+ expect(
272
+ createElement({
273
+ tagName: 'p',
274
+ className: 'lead',
275
+ innerText: 'This is a newly created paragraph.',
276
+ }),
277
+ 'createElement(object)',
278
+ )
279
+ .to.be.instanceOf(HTMLParagraphElement)
280
+ .and.have.class('lead')
281
+ .and.contain('This is a newly created paragraph.');
282
+ expect(
283
+ createElement({
284
+ tagName: 'p',
285
+ textContent: 'This is a newly created paragraph.',
286
+ }),
287
+ 'createElement(object)',
288
+ ).to.be.instanceOf(HTMLParagraphElement)
289
+ .and.contain('This is a newly created paragraph.');
290
+
291
+ expect(
292
+ createElement({
293
+ className: 'lead',
294
+ innerText: 'This is a newly created paragraph.',
295
+ }),
296
+ 'createElement(incompleteObject)',
297
+ ).to.be.undefined;
298
+
299
+ expect(createElementNS(), 'createElementNS()').to.be.undefined;
300
+ expect(
301
+ createElementNS('http://www.w3.org/2000/svg', 'svg'),
302
+ 'createElementNS(ns, string)',
303
+ ).to.be.instanceOf(SVGElement);
304
+ expect(
305
+ createElementNS('http://www.w3.org/1999/xhtml', {
306
+ tagName: 'button',
307
+ className: 'btn',
308
+ innerText: 'New Item',
309
+ textContent: 'New Item',
310
+ }),
311
+ 'createElementNS(ns, object)',
312
+ )
313
+ .to.be.instanceOf(HTMLButtonElement)
314
+ .and.have.class('btn')
315
+ .and.contain('New Item');
316
+
317
+ expect(
318
+ createElementNS('http://www.w3.org/2000/svg', {
319
+ tagName: 'path',
320
+ d: 'M98,158l157,156L411,158l27,27L255,368L71,185L98,158z',
321
+ }),
322
+ 'createElementNS(ns, object)',
323
+ ).to.be.instanceOf(SVGPathElement)
324
+ .and.have.property('d').equal('M98,158l157,156L411,158l27,27L255,368L71,185L98,158z');
325
+
326
+ expect(
327
+ createElementNS('http://www.w3.org/2000/svg', {
328
+ tagName: '',
329
+ className: 'icon',
330
+ d: 'M98,158l157,156L411,158l27,27L255,368L71,185L98,158z',
331
+ }),
332
+ 'createElementNS(ns, incompleteObject)',
333
+ ).to.be.undefined;
334
+
335
+ Data.set(el);
336
+ expect(Data.get(el), 'not enough params - Data.get(node)').to.be.null;
337
+
338
+ Data.set('str', 'strKey', 'data');
339
+ expect(Data.get('str', 'strKey'), 'not HTMLElement - Data.get(string, string, string)').to
340
+ .be.null;
341
+
342
+ Data.set(el, 'Alert', { element: el });
343
+ expect(Data.get(el, 'Alert'), 'Data.get(node, key)').to.deep.equal({ element: el });
344
+ expect(getInstance(el, 'Alert'), 'getInstance(node, key)').to.deep.equal({ element: el });
345
+ expect(Data.getAllFor('Alert').size, 'Data.getAllFor(string).size').to.equal(1);
346
+
347
+ Data.remove(el, 'Alert');
348
+ expect(Data.get(el, 'Alert'), 'removed - Data.get(node, string)').to.be.null;
349
+ expect(getInstance(el, 'Alert'), 'removed - getInstance(node, string)').to.be.null;
350
+ expect(Data.getAllFor('Alert'), 'removed - Data.getAllFor(string)').to.be.null;
351
+ Data.remove(el, 'Alert');
352
+ });
353
+ });
354
+ });
@@ -0,0 +1,85 @@
1
+ /// <reference types="cypress" />
2
+ // @ts-nocheck
3
+
4
+ // import SHORTY from '../../src/index';
5
+ import * as SHORTY from '../../src/index';
6
+
7
+ import CustomElem from '../fixtures/custom-elem';
8
+
9
+ describe('Shorty Library Tests', () => {
10
+ before(() => {
11
+ cy.visit('cypress/test.html')
12
+ .wait(100);
13
+ });
14
+
15
+ it('Test selectors folder', () => {
16
+ const {
17
+ closest,
18
+ getCustomElements,
19
+ getElementById,
20
+ getElementsByClassName,
21
+ getElementsByTagName,
22
+ matches,
23
+ querySelector,
24
+ querySelectorAll,
25
+ } = SHORTY;
26
+
27
+ cy
28
+ .get('.alert')
29
+ .then($alert => {
30
+ const [el] = $alert;
31
+ const win = el.ownerDocument.defaultView;
32
+
33
+ const CE = new CustomElem();
34
+ win.document.body.append(CE);
35
+
36
+ expect(querySelectorAll('div'), 'querySelectorAll(div)').to.have.length(0);
37
+ expect(querySelectorAll('div', win.document), 'querySelectorAll(div, parent)').to.have.length(1);
38
+
39
+ expect(querySelector(), 'querySelector()').to.be.null;
40
+ expect(querySelector(el), 'querySelector(node)').to.equal(el);
41
+ expect(querySelector('.alert'), 'querySelector(selector)').to.be.null;
42
+ expect(querySelector('.alert', win.document), 'querySelector(selector, parent)').to.eq(el);
43
+
44
+ expect(closest(el), 'closest()').to.be.null;
45
+ expect(closest(el, 'wombat'), 'closest(invalid)').to.be.null;
46
+ expect(closest(el, 'body'), 'closest(body)').to.eq(win.document.body);
47
+
48
+ expect(getCustomElements(), 'getCustomElements()').to.deep.equal([]);
49
+ expect(getCustomElements(win.document), 'getCustomElements(expected)').to.deep.equal([CE]);
50
+
51
+ expect(getElementById(), 'getElementById()').to.be.null;
52
+ expect(getElementById('alertDemo'), 'getElementById(id)').to.be.null;
53
+ expect(
54
+ getElementById('alertDemo', win.document),
55
+ 'getElementById(id, parent)',
56
+ ).to.be.instanceOf(win.HTMLDivElement);
57
+
58
+ expect(getElementsByClassName(), 'getElementsByClassName()').to.be.instanceOf(
59
+ HTMLCollection,
60
+ );
61
+ expect(
62
+ getElementsByClassName('alert'),
63
+ 'getElementsByClassName(selector)',
64
+ ).to.be.instanceOf(HTMLCollection);
65
+ expect(
66
+ getElementsByClassName('alert', win.document),
67
+ 'getElementsByClassName(selector, parent)',
68
+ ).to.be.instanceOf(win.HTMLCollection);
69
+
70
+ expect(getElementsByTagName(), 'getElementsByTagName()').to.be.instanceOf(HTMLCollection);
71
+ expect(getElementsByTagName('div'), 'getElementsByTagName(selector)').to.be.instanceOf(
72
+ HTMLCollection,
73
+ );
74
+ expect(
75
+ getElementsByTagName('div', win.document),
76
+ 'getElementsByTagName(selector, parent)',
77
+ ).to.be.instanceOf(win.HTMLCollection);
78
+
79
+ expect(
80
+ [...getElementsByClassName('alert', win.document)].filter(x => matches(x, 'div')),
81
+ 'matches(node, selector)',
82
+ ).to.deep.equal([el]);
83
+ });
84
+ });
85
+ });
@@ -0,0 +1,18 @@
1
+ const CEP = document.createElement('p');
2
+ CEP.innerText = 'Sample Custom Element';
3
+
4
+ export default class CustomElem extends HTMLElement {
5
+ constructor() {
6
+ super();
7
+
8
+ this.attachShadow({ mode: 'open' });
9
+ }
10
+ connectedCallback() {
11
+ this.shadowRoot.append(CEP);
12
+ }
13
+ disconnectedCallback() {
14
+ this.shadowRoot.innerHTML = '';
15
+ }
16
+ }
17
+
18
+ customElements.define('custom-elem', CustomElem);