-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtools.test.js
More file actions
71 lines (64 loc) · 3.28 KB
/
tools.test.js
File metadata and controls
71 lines (64 loc) · 3.28 KB
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
import { createQuickAccess, dashesToCamelCase, camelCaseToDashes } from '../src/tools.js';
describe('dashesToCamelCase', () => {
it('converts properly to camel case', () => {
expect(dashesToCamelCase('test')).toBe('test');
expect(dashesToCamelCase('-test')).toBe('Test');
expect(dashesToCamelCase('test-test')).toBe('testTest');
expect(dashesToCamelCase('test-Test')).toBe('testTest');
expect(dashesToCamelCase('-test-Test')).toBe('TestTest');
expect(dashesToCamelCase('this-is-a-test-with-multiple-dashes')).toBe('thisIsATestWithMultipleDashes');
expect(dashesToCamelCase('dash-on-the-end-')).toBe('dashOnTheEnd');
});
});
describe('camelCaseToDashes', () => {
it('converts properly to lowercased dashes', () => {
expect(camelCaseToDashes('test')).toBe('test');
expect(camelCaseToDashes('Test')).toBe('-test');
expect(camelCaseToDashes('testTest')).toBe('test-test');
expect(camelCaseToDashes('TestTest')).toBe('-test-test');
expect(camelCaseToDashes('thisIsATestThatShouldHaveMultipleDashes')).toBe('this-is-a-test-that-should-have-multiple-dashes');
expect(camelCaseToDashes('ThisIsATestThatShouldHaveMultipleDashes')).toBe('-this-is-a-test-that-should-have-multiple-dashes');
});
});
describe('createQuickAccess', () => {
it('creates members for a nested id', () => {
const element = document.createElement('div');
element.innerHTML = '<div><span><div id="test"></div></span></div>';
expect(createQuickAccess(element, 'id')).toEqual({ test: element.querySelector('#test') });
});
it('creates members for multiple ids', () => {
const element = document.createElement('div');
element.innerHTML = '<div id="first"><span id="second"><div id="third"></div></span></div>';
expect(createQuickAccess(element, 'id')).toEqual({
first: element.querySelector('#first'),
second: element.querySelector('#second'),
third: element.querySelector('#third'),
});
});
it('members should be camel case for dashed ids', () => {
const element = document.createElement('div');
element.innerHTML = '<div id="first-with-dash"><span id="second-with-dash"><div id="third-with-dash"></div></span></div>';
expect(createQuickAccess(element, 'id')).toEqual({
firstWithDash: element.querySelector('#first-with-dash'),
secondWithDash: element.querySelector('#second-with-dash'),
thirdWithDash: element.querySelector('#third-with-dash'),
});
});
it('should also work when using name as the tag', () => {
const element = document.createElement('div');
element.innerHTML = '<div name="first-with-dash"><span name="second-with-dash"><div name="third-with-dash"></div></span></div>';
expect(createQuickAccess(element, 'name')).toEqual({
firstWithDash: element.querySelector('[name="first-with-dash"]'),
secondWithDash: element.querySelector('[name="second-with-dash"]'),
thirdWithDash: element.querySelector('[name="third-with-dash"]'),
});
});
it('only one tag type should be retrieved', () => {
const element = document.createElement('div');
element.innerHTML = '<div name="first-with-dash"><span id="second-with-dash"><div name="third-with-dash"></div></span></div>';
expect(createQuickAccess(element, 'name')).toEqual({
firstWithDash: element.querySelector('[name="first-with-dash"]'),
thirdWithDash: element.querySelector('[name="third-with-dash"]'),
});
});
});