@thednp/shorty 2.0.2 → 2.0.4

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/README.md +5 -5
  2. package/dist/shorty.cjs +1 -1
  3. package/dist/shorty.cjs.map +1 -1
  4. package/dist/shorty.d.ts +12 -11
  5. package/dist/shorty.js +1 -1
  6. package/dist/shorty.js.map +1 -1
  7. package/dist/shorty.mjs +14 -4
  8. package/dist/shorty.mjs.map +1 -1
  9. package/package.json +17 -15
  10. package/src/boolean/isApple.ts +1 -1
  11. package/src/boolean/isFirefox.ts +3 -1
  12. package/src/boolean/isMobile.ts +1 -1
  13. package/src/event/one.ts +1 -1
  14. package/src/get/getRectRelativeToOffsetParent.ts +1 -1
  15. package/src/index.ts +11 -0
  16. package/src/misc/createCustomEvent.ts +5 -5
  17. package/src/misc/createElementNS.ts +1 -1
  18. package/src/misc/emulateAnimationEnd.ts +3 -2
  19. package/src/misc/emulateTransitionEnd.ts +2 -2
  20. package/src/selectors/closest.ts +5 -2
  21. package/test/att.test.ts +43 -0
  22. package/test/boolean.test.ts +30 -0
  23. package/test/class.test.ts +26 -0
  24. package/test/event.test.ts +39 -0
  25. package/{cypress/test.html → test/fixtures/getExampleDom.ts} +17 -32
  26. package/test/fixtures/style.css +18 -0
  27. package/test/get.test.ts +150 -0
  28. package/{cypress/e2e/is.cy.ts → test/is.test.ts} +77 -74
  29. package/test/misc.test.ts +352 -0
  30. package/test/selectors.test.ts +90 -0
  31. package/tsconfig.json +6 -1
  32. package/vitest.config-ui.ts +21 -0
  33. package/vitest.config.ts +20 -0
  34. package/cypress/e2e/att.cy.ts +0 -46
  35. package/cypress/e2e/boolean.cy.ts +0 -44
  36. package/cypress/e2e/class.cy.ts +0 -28
  37. package/cypress/e2e/event.cy.ts +0 -51
  38. package/cypress/e2e/get.cy.ts +0 -168
  39. package/cypress/e2e/misc.cy.ts +0 -354
  40. package/cypress/e2e/selectors.cy.ts +0 -85
  41. package/cypress/plugins/esbuild-istanbul.ts +0 -50
  42. package/cypress/plugins/tsCompile.ts +0 -34
  43. package/cypress/support/commands.ts +0 -37
  44. package/cypress/support/e2e.ts +0 -21
  45. package/cypress/support/index.js +0 -22
  46. package/cypress.config.ts +0 -30
  47. /package/{cypress → test}/fixtures/custom-elem.js +0 -0
@@ -0,0 +1,352 @@
1
+ import { expect, it, describe, vi, afterEach } from 'vitest';
2
+ import { getExampleDOM } from './fixtures/getExampleDom';
3
+ import * as SHORTY from '../src/index';
4
+ import "./fixtures/style.css";
5
+
6
+ describe('Shorty Library Tests - MISC', () => {
7
+ const wrapper = document.createElement('div');
8
+ document.body.append(wrapper);
9
+ afterEach(async () => {
10
+ wrapper.innerHTML = '';
11
+ });
12
+
13
+ it('Test misc folder - emulateTransitionEnd - no transition', () => {
14
+ const container = getExampleDOM();
15
+ wrapper.append(container);
16
+
17
+ const {
18
+ dispatchEvent,
19
+ emulateTransitionEnd,
20
+ createCustomEvent,
21
+ reflow,
22
+ querySelector,
23
+ setElementStyle,
24
+ getElementStyle,
25
+ removeClass,
26
+ addClass,
27
+ one,
28
+ } = SHORTY;
29
+
30
+ const el = querySelector('.alert', container) as HTMLElement;
31
+ const btn = querySelector('.btn-close', el) as HTMLButtonElement;
32
+ const alertHideEvent = createCustomEvent('hide-alert',);
33
+
34
+ setElementStyle(el, {
35
+ transition: 'none',
36
+ transitionProperty: 'none',
37
+ transitionDuration: '0s',
38
+ 'transition-delay': '0s',
39
+ '--transition-prop': 'none',
40
+ });
41
+
42
+ expect(getElementStyle(el, 'transitionProperty')).to.equal('none');
43
+ expect(getElementStyle(el, 'transition-duration')).to.equal('0s');
44
+ expect(getElementStyle(el, 'transitionDelay')).to.equal('0s');
45
+ expect(getElementStyle(el, '--transition-prop')).to.equal('none');
46
+
47
+ one(el, 'hide-alert', function hideHandler(e: typeof alertHideEvent) {
48
+ expect(e.target).to.equal(el);
49
+ expect(e.relatedTarget).to.equal(btn);
50
+ });
51
+
52
+ one(btn, 'click', function handleBtn(e) {
53
+ expect(e.target).to.equal(btn);
54
+ removeClass(el, 'show');
55
+ reflow(el);
56
+ alertHideEvent.relatedTarget = btn;
57
+ dispatchEvent(el, alertHideEvent);
58
+ emulateTransitionEnd(el, function () {
59
+ addClass(el, 'show');
60
+ });
61
+ });
62
+
63
+ btn.click();
64
+ });
65
+
66
+ it('Test misc folder - emulateTransitionEnd - default', () => {
67
+ vi.useFakeTimers();
68
+ const container = getExampleDOM();
69
+ wrapper.append(container);
70
+
71
+ const {
72
+ dispatchEvent,
73
+ emulateTransitionEnd,
74
+ createCustomEvent,
75
+ reflow,
76
+ querySelector,
77
+ removeClass,
78
+ addClass,
79
+ one,
80
+ focus,
81
+ } = SHORTY;
82
+
83
+ const el = querySelector('.alert', container) as HTMLElement;
84
+ const btn = querySelector('.btn-close', el) as HTMLButtonElement;
85
+ const alertHideEvent = createCustomEvent('hide-alert', { relatedTarget: null });
86
+
87
+ one(el, 'hide-alert', function hideHandler(e: typeof alertHideEvent) {
88
+ expect(e.target).to.equal(el);
89
+ expect(e.relatedTarget).to.equal(btn);
90
+ });
91
+
92
+ one(btn, 'click', function handleBtn(e) {
93
+ expect(e.target).to.equal(btn);
94
+ removeClass(el, 'show');
95
+ reflow(el);
96
+ alertHideEvent.relatedTarget = btn;
97
+ dispatchEvent(el, alertHideEvent);
98
+ emulateTransitionEnd(el, function () {
99
+ addClass(el, 'show');
100
+ focus(btn, { preventScroll: false });
101
+ console.log('transitionend triggered');
102
+ });
103
+ vi.advanceTimersByTime(350);
104
+ });
105
+
106
+ btn!.click();
107
+
108
+ });
109
+
110
+ it('Test misc folder - emulateAnimationEnd - default', async () => {
111
+ vi.useFakeTimers();
112
+ const container = getExampleDOM();
113
+ wrapper.append(container);
114
+
115
+ const { emulateAnimationEnd, getElementStyle, querySelector, addClass } = SHORTY;
116
+
117
+ const el = querySelector('.alert') as HTMLElement;
118
+
119
+ addClass(el, 'animate-test');
120
+ emulateAnimationEnd(el, () => {
121
+ console.log('animationend fired - default');
122
+ expect(getElementStyle(el, 'animationName'), 'animationName').to.equal('animate-test');
123
+ expect(getElementStyle(el, 'animationDuration'), 'animationDuration').to.equal('0.3s');
124
+ expect(getElementStyle(el, 'animationDelay'), 'animationDelay').to.equal('0s');
125
+ });
126
+ vi.advanceTimersByTime(350);
127
+
128
+ });
129
+
130
+ it('Test misc folder - emulateAnimationEnd - no duration', () => {
131
+ const container = getExampleDOM();
132
+ wrapper.append(container);
133
+
134
+ const { emulateAnimationEnd, setElementStyle, getElementStyle, querySelector, addClass } =
135
+ SHORTY;
136
+
137
+ const el = querySelector('.alert', container)!;
138
+ setElementStyle(el, { animationDuration: '0.1s' });
139
+
140
+ addClass(el, 'animate-test');
141
+
142
+
143
+ emulateAnimationEnd(el, () => {
144
+ // await vi.waitUntil(() => {
145
+ console.log('animationend fired no duration');
146
+ expect(getElementStyle(el, 'animationName'), 'animationName').to.equal('animate-test');
147
+ expect(getElementStyle(el, 'animationDuration'), 'animationDuration').to.equal('0s');
148
+ expect(getElementStyle(el, 'animationDelay'), 'animationDelay').to.equal('0s');
149
+
150
+ // }, { timeout: 150 })
151
+ });
152
+
153
+ });
154
+
155
+ it('Test misc folder - everything else', () => {
156
+ const container = getExampleDOM();
157
+ wrapper.append(container);
158
+
159
+ const {
160
+ ArrayFrom,
161
+ Float32ArrayFrom,
162
+ Float64ArrayFrom,
163
+ distinct,
164
+ noop,
165
+ ObjectHasOwn,
166
+ ObjectEntries,
167
+ ObjectAssign,
168
+ ObjectKeys,
169
+ ObjectValues,
170
+ // ObjectDefineProperty,
171
+ ObjectFromEntries,
172
+ createElement,
173
+ createElementNS,
174
+ Data,
175
+ getInstance,
176
+ normalizeOptions,
177
+ Timer,
178
+ toLowerCase,
179
+ toUpperCase,
180
+ querySelector,
181
+ getElementsByClassName,
182
+ } = SHORTY;
183
+
184
+
185
+ const el = querySelector('.alert', container)!;
186
+ const table = querySelector('.table', container)!;
187
+
188
+ const defaults = { op1: true, op2: true, op3: 5, title: null };
189
+ const jsOps = { op1: false, op2: false, op3: 8, title: 'something' };
190
+ expect(ObjectHasOwn(jsOps, 'op3')).to.be.true;
191
+ expect(ObjectHasOwn(jsOps, 'momo')).to.be.false;
192
+ // @ts-expect-error
193
+ expect(ObjectHasOwn(null, 'momo')).to.be.false;
194
+ expect(normalizeOptions(el, defaults, {}, 'bs'), 'normalizeOptions(data)').to.deep.equal({
195
+ op1: false,
196
+ op2: true,
197
+ op3: 10,
198
+ title: null,
199
+ });
200
+ // @ts-expect-error
201
+ expect(normalizeOptions(el, defaults, jsOps, 'bs'), 'normalizeOptions(js)').to.deep.equal({
202
+ op1: false,
203
+ op2: false,
204
+ op3: 8,
205
+ title: 'something',
206
+ });
207
+ expect(noop()).to.be.undefined;
208
+
209
+ // @ts-expect-error
210
+ Timer.set('el', noop, 150);
211
+ Timer.set(el, () => console.log(el.tagName + ' has timer of 150'), 150, 'alert');
212
+ // @ts-expect-error
213
+ expect(Timer.get('el', 'alert')).to.be.null;
214
+ expect(Timer.get(el, 'alert')).to.not.be.undefined;
215
+ // @ts-expect-error
216
+ Timer.clear('el', 'alert');
217
+ Timer.clear(el, 'alert');
218
+ expect(Timer.get(el, 'alert')).to.be.null;
219
+
220
+ Timer.set(el, () => console.log(el.tagName + ' has timer of 250'), 250);
221
+ expect(Timer.get(el)).to.not.be.null;
222
+ Timer.clear(el);
223
+ expect(Timer.get(el)).to.be.null;
224
+
225
+ expect([0, 1, 1, 2, 3, 3].filter(distinct), 'filter(DISTINCT)').to.deep.equal([0, 1, 2, 3]);
226
+
227
+ expect(toLowerCase('textSample'), 'toLowerCase(string)').to.equal('textsample');
228
+ expect(toUpperCase('textSample'), 'toUpperCase(string)').to.equal('TEXTSAMPLE');
229
+
230
+ // expect(
231
+ // Object.defineProperty({ c: 3}, 'a', { value: {b: 1}, writable: true }),
232
+ // 'ObjectDefineProperty(object1, prop, value)',
233
+ // ).to.deep.equal({ c: 3, a: {b: 1} });
234
+ expect(
235
+ ObjectAssign({ c: 3 }, { a: 1, b: 2 }),
236
+ 'ObjectAssign(object1, object2)',
237
+ ).to.deep.equal({ a: 1, b: 2, c: 3 });
238
+ expect(ObjectEntries({ a: 1, b: 2 }), 'ObjectEntries(object)').to.deep.equal([
239
+ ['a', 1],
240
+ ['b', 2],
241
+ ]);
242
+ expect(ObjectKeys({ a: 1, b: 2 }), 'ObjectKeys(object)').to.deep.equal(['a', 'b']);
243
+ expect(ObjectValues({ a: 1, b: 2 }), 'ObjectValues(object)').to.deep.equal([1, 2]);
244
+
245
+ expect(Float32ArrayFrom([0, 1, 2, 3]), 'Float32ArrayFrom(array)').to.be.instanceOf(
246
+ Float32Array,
247
+ );
248
+ expect(Float64ArrayFrom([0, 1, 2, 3]), 'Float64ArrayFrom(array)').to.be.instanceOf(
249
+ Float64Array,
250
+ );
251
+ expect(Float64ArrayFrom([0, 1, 2, 3]).length, 'Float64ArrayFrom(array)').to.eq(4);
252
+
253
+ expect(
254
+ ArrayFrom(new Float32Array([0, 1, 2, 3])),
255
+ 'ArrayFrom(Float32Array)',
256
+ ).to.be.instanceOf(Array);
257
+ expect(ArrayFrom(new Float64Array([0, 1, 2, 3])), 'Array(Float64Array)').to.be.instanceOf(
258
+ Array,
259
+ );
260
+ expect(
261
+ ArrayFrom(getElementsByClassName('table', container)),
262
+ 'ArrayFrom(HTMLCollection)',
263
+ ).to.deep.equal([table]);
264
+
265
+ expect(createElement(), 'createElement()').to.be.undefined;
266
+ expect(createElement('input'), 'createElement(string)').to.be.instanceOf(HTMLInputElement);
267
+ const parag = createElement({
268
+ tagName: 'p',
269
+ className: 'lead',
270
+ innerText: 'This is a newly created paragraph.',
271
+ });
272
+ expect(parag).to.be.instanceOf(HTMLParagraphElement)
273
+ expect(parag?.className).to.contain('lead')
274
+ expect(parag?.innerHTML).to.contain('This is a newly created paragraph.');
275
+ expect(
276
+ createElement({
277
+ tagName: 'p',
278
+ textContent: 'This is a newly created paragraph.',
279
+ }),
280
+ 'createElement(object)',
281
+ ).to.be.instanceOf(HTMLParagraphElement)
282
+ // .and.contain('This is a newly created paragraph.');
283
+
284
+ expect(
285
+ createElement({
286
+ className: 'lead',
287
+ innerText: 'This is a newly created paragraph.',
288
+ }),
289
+ 'createElement(incompleteObject)',
290
+ ).to.be.undefined;
291
+
292
+ expect(createElementNS(''), 'createElementNS()').to.be.undefined;
293
+ expect(
294
+ createElementNS('http://www.w3.org/2000/svg', 'svg'),
295
+ 'createElementNS(ns, string)',
296
+ ).to.be.instanceOf(SVGElement);
297
+ expect(
298
+ createElementNS<HTMLButtonElement>('http://www.w3.org/1999/xhtml', {
299
+ tagName: 'button',
300
+ className: 'btn',
301
+ innerText: 'New Item',
302
+ textContent: 'New Item',
303
+ }),
304
+ 'createElementNS(ns, object)',
305
+ )
306
+ .to.be.instanceOf(HTMLButtonElement)
307
+ // .and.contain('btn')
308
+ // .and.contain('New Item');
309
+
310
+ expect(
311
+ createElementNS<SVGPathElement & { d: string }>('http://www.w3.org/2000/svg', {
312
+ tagName: 'path',
313
+ d: 'M98,158l157,156L411,158l27,27L255,368L71,185L98,158z',
314
+ }),
315
+ 'createElementNS(ns, object)',
316
+ ).to.be.instanceOf(SVGPathElement)
317
+ .and.have.property('d').equal('M98,158l157,156L411,158l27,27L255,368L71,185L98,158z');
318
+
319
+ expect(
320
+ createElementNS<SVGPathElement & { d: string }>('http://www.w3.org/2000/svg', {
321
+ tagName: '',
322
+ className: 'icon',
323
+ d: 'M98,158l157,156L411,158l27,27L255,368L71,185L98,158z',
324
+ }),
325
+ 'createElementNS(ns, incompleteObject)',
326
+ ).to.be.undefined;
327
+
328
+ // @ts-expect-error
329
+ Data.set(el);
330
+ // @ts-expect-error
331
+ expect(Data.get(el), 'not enough params - Data.get(node)').to.be.null;
332
+
333
+ // @ts-expect-error
334
+ Data.set('str', 'strKey', 'data');
335
+ // @ts-expect-error
336
+ expect(Data.get('str', 'strKey'), 'not HTMLElement - Data.get(string, string, string)').to
337
+ .be.null;
338
+
339
+ Data.set(el, 'Alert', { element: el });
340
+ expect(Data.get(el, 'Alert'), 'Data.get(node, key)').to.deep.equal({ element: el });
341
+ expect(getInstance(el, 'Alert'), 'getInstance(node, key)').to.deep.equal({ element: el });
342
+ expect(Data.getAllFor('Alert')?.size, 'Data.getAllFor(string).size').to.equal(1);
343
+
344
+ Data.remove(el, 'Alert');
345
+ expect(Data.get(el, 'Alert'), 'removed - Data.get(node, string)').to.be.null;
346
+ expect(getInstance(el, 'Alert'), 'removed - getInstance(node, string)').to.be.null;
347
+ expect(Data.getAllFor('Alert'), 'removed - Data.getAllFor(string)').to.be.null;
348
+ Data.remove(el, 'Alert');
349
+
350
+ expect(ObjectFromEntries([['a', 1], ['b', 2]])).to.deep.equal({ a: 1, b: 2 })
351
+ });
352
+ });
@@ -0,0 +1,90 @@
1
+ import { expect, it, describe, vi, afterEach } from 'vitest';
2
+ import { getExampleDOM } from './fixtures/getExampleDom';
3
+ import * as SHORTY from '../src/index';
4
+ import CustomElem from './fixtures/custom-elem';
5
+ import "./fixtures/style.css";
6
+
7
+ describe('Shorty Library Tests', () => {
8
+ const wrapper = document.createElement('div');
9
+ document.body.append(wrapper);
10
+ afterEach(async () => {
11
+ wrapper.innerHTML = '';
12
+ });
13
+
14
+ it('Test selectors folder', () => {
15
+ const container = getExampleDOM();
16
+ wrapper.append(container);
17
+
18
+ const {
19
+ closest,
20
+ getCustomElements,
21
+ getElementById,
22
+ getElementsByClassName,
23
+ getElementsByTagName,
24
+ matches,
25
+ querySelector,
26
+ querySelectorAll,
27
+ } = SHORTY;
28
+
29
+ const el = querySelector('.alert', container);
30
+ if (!el) return;
31
+ const win = window;
32
+
33
+ const CE = new CustomElem();
34
+ win.document.body.append(CE);
35
+
36
+ expect(querySelectorAll('div'), 'querySelectorAll(div)').to.have.length(3);
37
+ expect(querySelectorAll('div', win.document), 'querySelectorAll(div, parent)').to.have.length(3);
38
+
39
+ // @ts-expect-error
40
+ expect(querySelector(), 'querySelector()').to.be.null;
41
+ expect(querySelector(el), 'querySelector(node)').to.equal(el);
42
+ expect(querySelector('.alert'), 'querySelector(selector)').to.not.be.null;
43
+ expect(querySelector('.alert', win.document), 'querySelector(selector, parent)').to.eq(el);
44
+ // @ts-expect-error
45
+ expect(closest(), 'closest()').to.be.null;
46
+ // @ts-expect-error
47
+ expect(closest(el)).to.be.null;
48
+ expect(closest(el, 'wombat'), 'closest(el, invalidTagSelector)').to.be.null;
49
+ expect(closest(el, 'body'), 'closest(body)').to.eq(win.document.body);
50
+
51
+ expect(getCustomElements(), 'getCustomElements()').to.have.lengthOf(1);
52
+ expect(getCustomElements(win.document), 'getCustomElements(expected)').to.deep.equal([CE]);
53
+
54
+ // @ts-expect-error
55
+ expect(getElementById(), 'getElementById()').to.be.null;
56
+ expect(getElementById('alertDemo'), 'getElementById(id)').to.not.be.null;
57
+ expect(
58
+ getElementById('alertDemo', win.document),
59
+ 'getElementById(id, parent)',
60
+ ).to.be.instanceOf(win.HTMLDivElement);
61
+
62
+ // @ts-expect-error
63
+ expect(getElementsByClassName(), 'getElementsByClassName()').to.be.instanceOf(
64
+ HTMLCollection,
65
+ );
66
+ expect(
67
+ getElementsByClassName('alert'),
68
+ 'getElementsByClassName(selector)',
69
+ ).to.be.instanceOf(HTMLCollection);
70
+ expect(
71
+ getElementsByClassName('alert', win.document),
72
+ 'getElementsByClassName(selector, parent)',
73
+ ).to.be.instanceOf(win.HTMLCollection);
74
+
75
+ // @ts-expect-error
76
+ expect(getElementsByTagName(), 'getElementsByTagName()').to.be.instanceOf(HTMLCollection);
77
+ expect(getElementsByTagName('div'), 'getElementsByTagName(selector)').to.be.instanceOf(
78
+ HTMLCollection,
79
+ );
80
+ expect(
81
+ getElementsByTagName('div', win.document),
82
+ 'getElementsByTagName(selector, parent)',
83
+ ).to.be.instanceOf(win.HTMLCollection);
84
+
85
+ expect(
86
+ [...getElementsByClassName('alert', win.document)].filter(x => matches(x, 'div')),
87
+ 'matches(node, selector)',
88
+ ).to.deep.equal([el]);
89
+ });
90
+ });
package/tsconfig.json CHANGED
@@ -23,7 +23,12 @@
23
23
  "allowSyntheticDefaultImports": true,
24
24
  "noEmit": true,
25
25
  "checkJs": true,
26
- "skipLibCheck": true // allows dts-bundle-generator to import from package.json
26
+ "skipLibCheck": true, // allows dts-bundle-generator to import from package.json
27
+ "paths": {
28
+ "~/*": [
29
+ "./src/*"
30
+ ],
31
+ }
27
32
  },
28
33
  "include": ["src/*", "src/**/*"],
29
34
  "exclude": ["node_modules", "experiments", "coverage", "dist"],
@@ -0,0 +1,21 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ css: true,
6
+ globals: true,
7
+ coverage: {
8
+ provider: "istanbul",
9
+ reporter: ["html", "text", "lcov"],
10
+ enabled: true,
11
+ include: ["src/**/*.{ts,tsx}"],
12
+ },
13
+ browser: {
14
+ // provider: 'webdriverio', // or 'preview'
15
+ enabled: true,
16
+ headless: false,
17
+ name: 'chrome', // browser name is required
18
+ // enableUI: true
19
+ },
20
+ },
21
+ });
@@ -0,0 +1,20 @@
1
+ import { defineConfig } from "vitest/config";
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ css: true,
6
+ globals: true,
7
+ coverage: {
8
+ provider: "istanbul",
9
+ reporter: ["html", "text", "lcov"],
10
+ enabled: true,
11
+ include: ["src/**/*.{ts,tsx}"],
12
+ },
13
+ browser: {
14
+ provider: 'playwright', // or 'webdriverio'
15
+ enabled: true,
16
+ headless: true,
17
+ name: 'chromium', // browser name is required
18
+ },
19
+ },
20
+ });
@@ -1,46 +0,0 @@
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
- before(() => {
9
- cy.visit('cypress/test.html');
10
- });
11
-
12
- it('Test attr folder', () => {
13
- const {
14
- getAttribute,
15
- setAttribute,
16
- hasAttribute,
17
- removeAttribute,
18
- getAttributeNS,
19
- setAttributeNS,
20
- hasAttributeNS,
21
- removeAttributeNS,
22
- querySelector,
23
- } = SHORTY;
24
-
25
- cy
26
- .get('.alert')
27
- .should($element => {
28
- const el = $element[0];
29
- expect(getAttribute(el, 'class'), 'getAttribute').to.have.length.above(0);
30
- setAttribute(el, 'data-att', 'momo');
31
- expect(hasAttribute(el, 'data-att'), 'hasAttribute').to.be.true;
32
- removeAttribute(el, 'data-att');
33
- expect(hasAttribute(el, 'data-att'), 'hasAttribute').to.be.false;
34
- });
35
- cy.get('svg').should($svg => {
36
- console.log(querySelector('svg'));
37
- const svg = $svg[0] as HTMLElement;
38
- const ns = 'http://www.w3.org/2000/svg';
39
- expect(hasAttributeNS(ns, svg, 'transform'), 'hasAttributeNS').to.be.false;
40
- setAttributeNS(ns, svg, 'transform', 'scale(0.99)');
41
- expect(getAttributeNS(ns, svg, 'transform'), 'getAttributeNS').to.eq('scale(0.99)');
42
- removeAttributeNS(ns, svg, 'transform');
43
- expect(getAttributeNS(ns, svg, 'transform'), 'getAttributeNS').to.be.null;
44
- });
45
- });
46
- });
@@ -1,44 +0,0 @@
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
- before(() => {
9
- cy.visit('cypress/test.html');
10
- });
11
-
12
- it('Test boolean folder', () => {
13
- const {
14
- // these are impossible to test 100% of the branches
15
- isApple,
16
- isMobile,
17
- isFirefox,
18
- support3DTransform,
19
- supportAnimation,
20
- supportPassive,
21
- supportTouch,
22
- supportTransform,
23
- supportTransition,
24
- // querySelectorAll, getWindow
25
- } = SHORTY;
26
- cy
27
- .window()
28
- .then(() => {
29
- expect(isApple, 'isApple').to.be.false;
30
- expect(isMobile, 'isMobile').to.be.false;
31
- if (Cypress.isBrowser('firefox')) {
32
- expect(isFirefox, 'isFirefox').to.be.true;
33
- } else {
34
- expect(isFirefox, 'isFirefox').to.be.false;
35
- }
36
- expect(support3DTransform, 'support3DTransform').to.be.true;
37
- expect(supportAnimation, 'supportAnimation').to.be.true;
38
- expect(supportPassive, 'supportPassive').to.be.true;
39
- expect(supportTouch, 'supportTouch').to.be.false;
40
- expect(supportTransform, 'supportTransform').to.be.true;
41
- expect(supportTransition, 'supportTransition').to.be.true;
42
- });
43
- });
44
- });
@@ -1,28 +0,0 @@
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
- before(() => {
9
- cy.visit('cypress/test.html');
10
- });
11
-
12
- it('Test class folder', () => {
13
- const { addClass, hasClass, removeClass } = SHORTY;
14
- cy
15
- .get('.alert')
16
- .then($alert => {
17
- const alert = $alert[0];
18
-
19
- addClass(alert, 'to-be-removed');
20
- expect(hasClass(alert, 'to-be-removed')).to.be.true;
21
- removeClass(alert, 'show');
22
- expect(hasClass(alert, 'show')).to.be.false;
23
- })
24
- .wait(200)
25
- .get('.alert')
26
- .should('be.hidden');
27
- });
28
- });
@@ -1,51 +0,0 @@
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
- before(() => {
9
- cy.visit('cypress/test.html');
10
- });
11
-
12
- it('Test event folder', () => {
13
- const {
14
- // on, off are called by one
15
- one,
16
- getElementsByClassName,
17
- } = SHORTY;
18
-
19
- cy
20
- .get('.alert')
21
- .should(($alert) => {
22
-
23
- if ($alert[0]){
24
- const [el] = $alert;
25
- const [btn] = getElementsByClassName('btn-close', el);
26
- const doc = btn.ownerDocument;
27
- console.log(doc, btn)
28
-
29
- one(el, 'click', function handle(e) {
30
- const message = doc.createElement('p');
31
- message.innerText += 'click fired for ' + (e.currentTarget as HTMLElement).tagName;
32
- el.append(message);
33
- // console.log(e.target, e.currentTarget);
34
- });
35
-
36
- one(btn, 'click', function handle(e) {
37
- const message = doc.createElement('p');
38
- message.innerText = 'click fired for ' + (e.target as HTMLElement).tagName;
39
- el.append(message);
40
- });
41
- }
42
- })
43
- .get('.btn-close')
44
- .click({ force: true })
45
- .should(btn => {
46
- expect(btn[0], 'event target').be.equal((btn[0].ownerDocument as Document).activeElement);
47
- })
48
- .get('.alert')
49
- .should('contain', 'click fired for BUTTON');
50
- });
51
- });