@natachah/vanilla-frontend 0.3.0 → 0.4.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.
@@ -121,7 +121,7 @@
121
121
  <button class="outline" aria-pressed="true">Active</button>
122
122
  </doc-code>
123
123
  <doc-code id="scss" data-type="scss" role="tabpanel">
124
- @use "@natachah/vanilla-frontend/scss/button" with ($outline: true);
124
+ @use "@natachah/vanilla-frontend/scss/components/button" with ($outline: true);
125
125
  </doc-code>
126
126
  </div>
127
127
 
@@ -148,7 +148,7 @@
148
148
  <button class="primary outline" aria-pressed="true">Active</button>
149
149
  </doc-code>
150
150
  <doc-code id="scss" data-type="scss" role="tabpanel">
151
- @use "@natachah/vanilla-frontend/scss/button" with ($colors: ('primary'),$outline: true);
151
+ @use "@natachah/vanilla-frontend/scss/components/button" with ($colors: ('primary'),$outline: true);
152
152
  </doc-code>
153
153
  </div>
154
154
 
@@ -89,7 +89,7 @@
89
89
  <span class="badge outline">Badge</span>
90
90
  </doc-code>
91
91
  <doc-code id="scss" data-type="scss" role="tabpanel">
92
- @use "@natachah/vanilla-frontend/scss/badge" with ($outline: true);
92
+ @use "@natachah/vanilla-frontend/scss/components/badge" with ($outline: true);
93
93
  </doc-code>
94
94
  </div>
95
95
 
@@ -111,7 +111,7 @@
111
111
  <span class="badge outline primary">Outline</span>
112
112
  </doc-code>
113
113
  <doc-code id="scss" data-type="scss" role="tabpanel">
114
- @use "@natachah/vanilla-frontend/scss/badge" with ($colors: ('primary'), $outline: true);
114
+ @use "@natachah/vanilla-frontend/scss/components/badge" with ($colors: ('primary'), $outline: true);
115
115
  </doc-code>
116
116
  </div>
117
117
 
@@ -151,7 +151,7 @@
151
151
  <div class="card outline">Hello there !</div>
152
152
  </doc-code>
153
153
  <doc-code id="scss" data-type="scss" role="tabpanel">
154
- @use "@natachah/vanilla-frontend/scss/card" with ($outline: true);
154
+ @use "@natachah/vanilla-frontend/scss/components/card" with ($outline: true);
155
155
  </doc-code>
156
156
  </div>
157
157
 
@@ -174,7 +174,7 @@
174
174
  <div class="card outline primary">Hello there !</div>
175
175
  </doc-code>
176
176
  <doc-code id="scss" data-type="scss" role="tabpanel">
177
- @use "@natachah/vanilla-frontend/scss/card" with ($colors: ('primary'),$outline: true);
177
+ @use "@natachah/vanilla-frontend/scss/components/card" with ($colors: ('primary'),$outline: true);
178
178
  </doc-code>
179
179
  </div>
180
180
 
@@ -38,7 +38,7 @@
38
38
  </doc-code>
39
39
  <doc-code id="css" data-type="css" role="tabpanel">
40
40
  html[data-theme=dark] {
41
- background: black
41
+ background: black
42
42
  }
43
43
  </doc-code>
44
44
  <doc-code id="js" data-type="js" role="tabpanel">
@@ -70,7 +70,7 @@
70
70
  </doc-code>
71
71
  <doc-code id="css" data-type="css" role="tabpanel">
72
72
  body {
73
- font-size: var(--font-size)
73
+ font-size: var(--font-size)
74
74
  }
75
75
  </doc-code>
76
76
  <doc-code id="js" data-type="js" role="tabpanel">
@@ -80,6 +80,18 @@
80
80
  </doc-code>
81
81
  </div>
82
82
 
83
+ <p>You can also set a custom style by value with some <code>&lt;input&gt;</code> tag with the <code>data-style-custom="NameOfTheCSSProperty"</code> and <code>value</code> attributes.</p>
84
+ <doc-demo>
85
+ <label for="demoCustomColor" style="color: var(--demo-label-color, black)">Change my label color !</label>
86
+ <input id="demoCustomColor" name="demo-change-color" data-style-custom="--demo-label-color" type="color" />
87
+ <button id="resetConfort">Reset</button>
88
+ </doc-demo>
89
+
90
+ <doc-code data-type="html">
91
+ <label for="demoCustomColor" style="color: var(--demo-label-color, black)">Change my label color !</label>
92
+ <input id="demoCustomColor" name="demo-change-color" data-style-custom="--demo-label-color" type="color" />
93
+ </doc-code>
94
+
83
95
  <h2>Javascript</h2>
84
96
  <p>To enable this component you need to import the javascript file and create a new Comfort object.</p>
85
97
  <p>You can customize the name of the <b>cookie</b> when initiate the component.</p>
@@ -57,7 +57,13 @@ const checkboxAll = document.getElementById('demoCheckboxAll')
57
57
  if (checkboxAll) new CheckAll(checkboxAll)
58
58
 
59
59
  import Comfort from "./../../../js/_comfort"
60
- new Comfort('demo-confort')
60
+ const demoConfort = new Comfort('demo-confort')
61
+
62
+ if (document.getElementById('resetConfort')) {
63
+ document.getElementById('resetConfort').addEventListener('click', () => {
64
+ demoConfort.reset()
65
+ })
66
+ }
61
67
 
62
68
  import Consent from "./../../../js/_consent"
63
69
  if (document.getElementById('demoCookies')) {
@@ -18,7 +18,7 @@ class DocLayout extends HTMLElement {
18
18
  <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pin-angle" viewBox="0 0 16 16">
19
19
  <path d="M9.828.722a.5.5 0 0 1 .354.146l4.95 4.95a.5.5 0 0 1 0 .707c-.48.48-1.072.588-1.503.588-.177 0-.335-.018-.46-.039l-3.134 3.134a6 6 0 0 1 .16 1.013c.046.702-.032 1.687-.72 2.375a.5.5 0 0 1-.707 0l-2.829-2.828-3.182 3.182c-.195.195-1.219.902-1.414.707s.512-1.22.707-1.414l3.182-3.182-2.828-2.829a.5.5 0 0 1 0-.707c.688-.688 1.673-.767 2.375-.72a6 6 0 0 1 1.013.16l3.134-3.133a3 3 0 0 1-.04-.461c0-.43.108-1.022.589-1.503a.5.5 0 0 1 .353-.146m.122 2.112v-.002zm0-.002v.002a.5.5 0 0 1-.122.51L6.293 6.878a.5.5 0 0 1-.511.12H5.78l-.014-.004a5 5 0 0 0-.288-.076 5 5 0 0 0-.765-.116c-.422-.028-.836.008-1.175.15l5.51 5.509c.141-.34.177-.753.149-1.175a5 5 0 0 0-.192-1.054l-.004-.013v-.001a.5.5 0 0 1 .12-.512l3.536-3.535a.5.5 0 0 1 .532-.115l.096.022c.087.017.208.034.344.034q.172.002.343-.04L9.927 2.028q-.042.172-.04.343a1.8 1.8 0 0 0 .062.46z"/>
20
20
  </svg>
21
- 0.3.0v
21
+ 0.4.0v
22
22
  </span>
23
23
  </li>
24
24
  <li>
@@ -6,7 +6,7 @@ import { fileURLToPath } from 'node:url'
6
6
  export default defineConfig({
7
7
  build: {
8
8
  target: 'esnext', //browsers can handle the latest ES features
9
- cssCodeSplit: false,
9
+ cssCodeSplit: true,
10
10
  rollupOptions: {
11
11
  input: Object.fromEntries(
12
12
  glob.sync(['./*.html', './pages/**/*.html']).map(file => [
package/js/_comfort.js CHANGED
@@ -30,6 +30,10 @@ export default class Comfort extends Cookie {
30
30
  style: document.querySelectorAll('body [data-style]'),
31
31
  }
32
32
 
33
+ this._inputs = {
34
+ style: document.querySelectorAll('body [data-style-custom]'),
35
+ }
36
+
33
37
  // Init the cookie
34
38
  this.#init()
35
39
 
@@ -54,6 +58,9 @@ export default class Comfort extends Cookie {
54
58
  // CLICK on style buttons
55
59
  this._buttons.style.forEach((button) => button.addEventListener('click', () => this.setStyle(button.getAttribute('data-style'), button.value)))
56
60
 
61
+ // Change a value input
62
+ this._inputs.style.forEach((input) => input.addEventListener('change', () => this.setStyle(input.getAttribute('data-style-custom'), input.value)))
63
+
57
64
  }
58
65
 
59
66
  /**
@@ -99,6 +106,12 @@ export default class Comfort extends Cookie {
99
106
  button.setAttribute('aria-pressed', style.hasOwnProperty(attribute) && style[attribute] === button.value)
100
107
  })
101
108
 
109
+ // Set the value attribute on the <input>
110
+ this._inputs.style.forEach(input => {
111
+ const attribute = input.getAttribute('data-style-custom')
112
+ input.setAttribute('value', style.hasOwnProperty(attribute) ? style[attribute] : null)
113
+ })
114
+
102
115
  }
103
116
 
104
117
  /**
@@ -168,6 +181,10 @@ export default class Comfort extends Cookie {
168
181
  button.removeAttribute('aria-pressed')
169
182
  })
170
183
 
184
+ this._inputs.style.forEach(input => {
185
+ input.removeAttribute('value')
186
+ })
187
+
171
188
  }
172
189
 
173
190
  }
@@ -133,6 +133,10 @@ describe('#Init()', () => {
133
133
 
134
134
  describe('#ByOption()', () => {
135
135
 
136
+ beforeEach(() => {
137
+ vi.restoreAllMocks()
138
+ })
139
+
136
140
  test('Emmit the autofill:changed event', () => {
137
141
  const eventSpy = vi.spyOn(fakeAutofillSelect, 'emmitEvent')
138
142
  expect(eventSpy).not.toHaveBeenCalled()
@@ -144,6 +148,10 @@ describe('#ByOption()', () => {
144
148
 
145
149
  describe('#ByFile()', () => {
146
150
 
151
+ beforeEach(() => {
152
+ vi.restoreAllMocks()
153
+ })
154
+
147
155
  test('Emmit the autofill:changed event', () => {
148
156
  const fakeImage = new File(["my testing file"], "my-file.jpg", {
149
157
  type: "image/jpeg",
@@ -8,6 +8,7 @@
8
8
  * - Constructor: Return the correct properties
9
9
  * - #Init: Emit the setTheme() method when click on this._buttons.theme
10
10
  * - #Init: Emit the setStyle() method when click on this._buttons.style
11
+ * - #Init: Emit the setStyle() method when change on this._inputs.style
11
12
  * - SetTheme(): Passing the correct parameters
12
13
  * - SetTheme(): Save the property in the cookie
13
14
  * - SetTheme(): Emmit the set() method
@@ -41,7 +42,8 @@ beforeAll(() => {
41
42
  document.body.innerHTML =
42
43
  '<button id="fakeDarkButton" data-theme="theme" value="dark"></button>' +
43
44
  '<button id="fakeLightButton" data-theme="theme" value="light"></button>' +
44
- '<button id="fakeFontButton" data-style="font-size" value="1rem"></button>'
45
+ '<button id="fakeFontButton" data-style="font-size" value="1rem"></button>' +
46
+ '<input id="fakeColorInput" data-style-custom="color" value=""/>'
45
47
 
46
48
  fakeComfort = new Comfort()
47
49
 
@@ -59,12 +61,17 @@ describe('Structure of the class', () => {
59
61
  expect(fakeComfort._buttons).toBeTypeOf('object')
60
62
  expect(fakeComfort._buttons.theme).toStrictEqual(document.querySelectorAll('[data-theme]'))
61
63
  expect(fakeComfort._buttons.style).toStrictEqual(document.querySelectorAll('[data-style]'))
64
+ expect(fakeComfort._inputs.style).toStrictEqual(document.querySelectorAll('[data-style-custom]'))
62
65
  })
63
66
 
64
67
  })
65
68
 
66
69
  describe('#Init()', () => {
67
70
 
71
+ beforeEach(() => {
72
+ vi.restoreAllMocks()
73
+ })
74
+
68
75
  test('Emit the setTheme() method when click on this._buttons.theme', () => {
69
76
  const methodSpy = vi.spyOn(fakeComfort, 'setTheme')
70
77
  fireEvent(document.getElementById('fakeDarkButton'), new MouseEvent('click'))
@@ -77,6 +84,14 @@ describe('#Init()', () => {
77
84
  expect(methodSpy).toHaveBeenCalled()
78
85
  })
79
86
 
87
+ test('Emit the setStyle() method when change on this._inputs.style ', () => {
88
+ const methodSpy = vi.spyOn(fakeComfort, 'setStyle')
89
+ const inputElement = document.getElementById('fakeColorInput')
90
+ inputElement.value = '#ff0000'
91
+ fireEvent.change(inputElement)
92
+ expect(methodSpy).toHaveBeenCalled()
93
+ })
94
+
80
95
  afterAll(() => {
81
96
  fakeComfort.reset()
82
97
  })
@@ -85,6 +100,10 @@ describe('#Init()', () => {
85
100
 
86
101
  describe('SetTheme()', () => {
87
102
 
103
+ beforeEach(() => {
104
+ vi.restoreAllMocks()
105
+ })
106
+
88
107
  test('Passing the correct parameters', () => {
89
108
  expect(() => fakeComfort.setTheme()).toThrowError(ErrorMessage.typeOf('value', 'string'))
90
109
  })
@@ -116,6 +135,10 @@ describe('SetTheme()', () => {
116
135
 
117
136
  describe('SetStyle()', () => {
118
137
 
138
+ beforeEach(() => {
139
+ vi.restoreAllMocks()
140
+ })
141
+
119
142
  test('Passing the correct parameters', () => {
120
143
  expect(() => fakeComfort.setStyle()).toThrowError(ErrorMessage.typeOf('name', 'string'))
121
144
  expect(() => fakeComfort.setStyle('font-size')).toThrowError(ErrorMessage.typeOf('value', 'string'))
@@ -178,7 +201,7 @@ describe('Reset()', () => {
178
201
  })
179
202
 
180
203
 
181
- describe('#ToggleTheme()', () => {
204
+ describe('#ToggleTheme() & #ToggleStyle()', () => {
182
205
 
183
206
  afterEach(() => {
184
207
  fakeComfort.reset()
@@ -216,4 +239,11 @@ describe('#ToggleTheme()', () => {
216
239
  expect(button.getAttribute('aria-pressed')).toBe('true')
217
240
  })
218
241
 
242
+ test('Add the [value] attribute on the <input>', () => {
243
+ const input = document.getElementById('fakeColorInput')
244
+ expect(input.hasAttribute('value')).toBeFalsy()
245
+ fakeComfort.setStyle('color', '#00ff00')
246
+ expect(input.getAttribute('value')).toBe('#00ff00')
247
+ })
248
+
219
249
  })
@@ -60,6 +60,10 @@ describe('Structure of the class', () => {
60
60
 
61
61
  describe('#Init()', () => {
62
62
 
63
+ beforeEach(() => {
64
+ vi.restoreAllMocks()
65
+ })
66
+
63
67
  test('Make sure that the dialog is open if the cookie doesn\'t exist', () => {
64
68
  expect(fakeCookie.value).toStrictEqual({})
65
69
  expect(fakeCookie._dialog.open).toBeTruthy()
@@ -76,6 +76,7 @@ describe('Open()', () => {
76
76
 
77
77
  afterEach(() => {
78
78
  fakeDialog._element.removeAttribute('open')
79
+ vi.restoreAllMocks()
79
80
  })
80
81
 
81
82
  test('Add the [open] attribute on the <dialog>', () => {
@@ -98,6 +99,7 @@ describe('Close()', () => {
98
99
 
99
100
  beforeEach(() => {
100
101
  fakeDialog._element.setAttribute('open', true)
102
+ vi.restoreAllMocks()
101
103
  })
102
104
 
103
105
  test('Remove the [open] attribute on the <dialog>', () => {
@@ -120,11 +122,12 @@ describe('Submit()', () => {
120
122
 
121
123
  beforeEach(() => {
122
124
  fakeFormModal._element.setAttribute('open', true)
125
+ vi.restoreAllMocks()
123
126
  })
124
127
 
125
128
  test('By default will exectute submit event', () => {
126
129
  fakeFormModal._form.setAttribute('method', 'POST')
127
- const submitSpy = vi.spyOn(fakeFormModal._form, 'submit')
130
+ const submitSpy = vi.spyOn(HTMLFormElement.prototype, 'submit')
128
131
  expect(submitSpy).not.toHaveBeenCalled()
129
132
  fakeFormModal.submit()
130
133
  expect(submitSpy).toHaveBeenCalled()
@@ -84,6 +84,10 @@ describe('#Init()', () => {
84
84
 
85
85
  describe('#Toggle()', () => {
86
86
 
87
+ beforeEach(() => {
88
+ vi.restoreAllMocks()
89
+ })
90
+
87
91
  test('Toggle the [aria-pressed] and [aria-expanded] attribute on the <button>', () => {
88
92
  expect(fakeDropdown._button.getAttribute('aria-pressed')).toBe('false')
89
93
  expect(fakeDropdown._button.getAttribute('aria-expanded')).toBe('false')
@@ -103,7 +103,7 @@ describe('ToggleAttributes', () => {
103
103
  expect(fieldA.value).toBe('aaa')
104
104
  expect(fieldB.value).toBe('bbb')
105
105
  FormHelper.toggleAttributes(fakeFields, false, { reset: ['fakeFieldA'] })
106
- expect(fieldA.value).toBe('null')
106
+ expect(fieldA.value).toBe('')
107
107
  expect(fieldB.value).toBe('bbb')
108
108
  })
109
109
 
@@ -144,7 +144,7 @@ describe('ToggleAttributes', () => {
144
144
  expect(fieldB.disabled).toBeFalsy()
145
145
  expect(fieldB.required).toBeFalsy()
146
146
  FormHelper.toggleAttributes(fakeFields, false, { reset: true, disabled: true, required: true, unchanged: ['fakeFieldB'] })
147
- expect(fieldA.value).toBe('null')
147
+ expect(fieldA.value).toBe('')
148
148
  expect(fieldA.disabled).toBeTruthy()
149
149
  expect(fieldA.required).toBeFalsy()
150
150
  expect(fieldB.value).toBe('bbb')
@@ -99,6 +99,10 @@ describe('Structure of the class', () => {
99
99
 
100
100
  describe('#Init()', () => {
101
101
 
102
+ beforeEach(() => {
103
+ vi.restoreAllMocks()
104
+ })
105
+
102
106
  test('Emit the scrollTop() method when click on this._buttons.top', () => {
103
107
  const methodSpy = vi.spyOn(fakeDivScroll, 'scrollTop')
104
108
  fireEvent(document.querySelector('[data-scroll-top="fakeDiv"]'), new MouseEvent('click'))
@@ -121,6 +125,10 @@ describe('#Init()', () => {
121
125
 
122
126
  describe('GoTo()', () => {
123
127
 
128
+ beforeEach(() => {
129
+ vi.restoreAllMocks()
130
+ })
131
+
124
132
  test('Passing the correct parameters ', () => {
125
133
  expect(() => fakeDivScroll.goTo()).toThrowError(ErrorMessage.typeOf('distance', 'number'))
126
134
  expect(() => fakeDivScroll.goTo('make-error')).toThrowError(ErrorMessage.typeOf('distance', 'number'))
@@ -136,6 +144,10 @@ describe('GoTo()', () => {
136
144
 
137
145
  describe('ScrollTop()', () => {
138
146
 
147
+ beforeEach(() => {
148
+ vi.restoreAllMocks()
149
+ })
150
+
139
151
  test('Emit a goTo() method with parameter as 0', () => {
140
152
  const methodSpy = vi.spyOn(fakeDivScroll, 'goTo')
141
153
  fakeDivScroll.scrollTop()
@@ -158,24 +170,26 @@ describe('#Scroll()', () => {
158
170
 
159
171
  test('Toggle the [hidden] attribute on the [data-scroll-top] button', () => {
160
172
  const topButton = document.querySelector('[data-scroll-top="fakeDiv"]')
173
+ const scrollTopSpy = vi.spyOn(Element.prototype, 'scrollTop', 'get').mockReturnValue(300)
161
174
  expect(topButton.hidden).toBeTruthy()
162
- Object.defineProperty(fakeDiv, 'scrollTop', { configurable: true, value: 300 })
163
175
  fireEvent.scroll(fakeDiv)
164
176
  expect(topButton.hidden).toBeFalsy()
165
- Object.defineProperty(fakeDiv, 'scrollTop', { configurable: true, value: 0 })
177
+ scrollTopSpy.mockReturnValue(0)
166
178
  fireEvent.scroll(fakeDiv)
167
179
  expect(topButton.hidden).toBeTruthy()
180
+ scrollTopSpy.mockRestore()
168
181
  })
169
182
 
170
183
  test('Toggle the [hidden] attribute on the [data-scroll-bottom] button', () => {
171
184
  const topButton = document.querySelector('[data-scroll-bottom="fakeDiv"]')
185
+ const scrollTopSpy = vi.spyOn(Element.prototype, 'scrollTop', 'get').mockReturnValue(600)
172
186
  expect(topButton.hidden).toBeFalsy()
173
- Object.defineProperty(fakeDiv, 'scrollTop', { configurable: true, value: 600 })
174
187
  fireEvent.scroll(fakeDiv)
175
188
  expect(topButton.hidden).toBeTruthy()
176
- Object.defineProperty(fakeDiv, 'scrollTop', { configurable: true, value: 0 })
189
+ scrollTopSpy.mockReturnValue(0)
177
190
  fireEvent.scroll(fakeDiv)
178
191
  expect(topButton.hidden).toBeFalsy()
192
+ scrollTopSpy.mockRestore()
179
193
  })
180
194
 
181
195
  })
@@ -185,19 +199,20 @@ describe('#Spy()', () => {
185
199
  test('Toggle the [aria-current] attribute on the <a> ', () => {
186
200
  const one = document.querySelector('a[href="#one"]')
187
201
  const two = document.querySelector('a[href="#two"]')
202
+ const scrollTopSpy = vi.spyOn(Element.prototype, 'scrollTop', 'get').mockReturnValue(200)
188
203
  expect(fakeDivScroll._spy.current).toBe(2)
189
204
  expect(one.hasAttribute('aria-current')).toBeFalsy() //200
190
205
  expect(two.hasAttribute('aria-current')).toBeFalsy() //400
191
- Object.defineProperty(fakeDiv, 'scrollTop', { configurable: true, value: 200 })
192
206
  fireEvent.scroll(fakeDiv)
193
207
  expect(fakeDivScroll._spy.current).toBe(0)
194
208
  expect(one.hasAttribute('aria-current')).toBeTruthy()
195
209
  expect(two.hasAttribute('aria-current')).toBeFalsy()
196
- Object.defineProperty(fakeDiv, 'scrollTop', { configurable: true, value: 400 })
210
+ scrollTopSpy.mockReturnValue(400)
197
211
  fireEvent.scroll(fakeDiv)
198
212
  expect(fakeDivScroll._spy.current).toBe(1)
199
213
  expect(one.hasAttribute('aria-current')).toBeFalsy()
200
214
  expect(two.hasAttribute('aria-current')).toBeTruthy()
215
+ scrollTopSpy.mockRestore()
201
216
  })
202
217
 
203
218
  })
@@ -23,7 +23,7 @@
23
23
 
24
24
  */
25
25
 
26
- import { describe, test, expect, beforeAll, vi, afterAll } from "vitest"
26
+ import { describe, test, expect, beforeAll, beforeEach, vi, afterAll } from "vitest"
27
27
  import { fireEvent } from "@testing-library/dom"
28
28
  import Slider from "../_slider"
29
29
  import ErrorMessage from "../utilities/_error"
@@ -79,7 +79,7 @@ beforeAll(() => {
79
79
  Object.defineProperty(fakeSlider._slides[2], 'offsetLeft', { configurable: true, value: 200 })
80
80
 
81
81
  let val = 0
82
- fakeSliderLoop._element.children.forEach(child => {
82
+ Array.from(fakeSliderLoop._element.children).forEach(child => {
83
83
  Object.defineProperty(child, 'offsetLeft', { configurable: true, value: val })
84
84
  val = val + 100
85
85
  })
@@ -125,6 +125,10 @@ describe('Structure of the class', () => {
125
125
 
126
126
  describe('#Init()', () => {
127
127
 
128
+ beforeEach(() => {
129
+ vi.restoreAllMocks()
130
+ })
131
+
128
132
  test('Loop will clone the first and last slide', () => {
129
133
  expect(fakeSliderLoop._slides.length).toBe(3)
130
134
  expect(fakeSliderLoop._element.children.length).toBe(5)
@@ -151,6 +155,7 @@ describe('#Init()', () => {
151
155
  test('Click on <button> with [data-slider-prev] emmit the prev() method', () => {
152
156
  const fakePrev = fakeSlider._buttons.prev
153
157
  const methodSpy = vi.spyOn(fakeSlider, 'prev')
158
+ fakeSlider.goTo(1)
154
159
  fireEvent(fakePrev, new MouseEvent('click'))
155
160
  expect(methodSpy).toHaveBeenCalled()
156
161
  })
@@ -166,6 +171,10 @@ describe('#Init()', () => {
166
171
 
167
172
  describe('GoTo()', () => {
168
173
 
174
+ beforeEach(() => {
175
+ vi.restoreAllMocks()
176
+ })
177
+
169
178
  test('Passing the correct parameters', () => {
170
179
  expect(() => fakeSlider.goTo()).toThrowError(ErrorMessage.typeOf('index', 'number'))
171
180
  })
@@ -222,6 +231,10 @@ describe('GoTo()', () => {
222
231
 
223
232
  describe('Prev()', () => {
224
233
 
234
+ beforeEach(() => {
235
+ vi.restoreAllMocks()
236
+ })
237
+
225
238
  afterAll(() => fakeSlider.goTo(0))
226
239
 
227
240
  test('Emit a goTo() method with correct index', () => {
@@ -242,6 +255,10 @@ describe('Prev()', () => {
242
255
 
243
256
  describe('Next()', () => {
244
257
 
258
+ beforeEach(() => {
259
+ vi.restoreAllMocks()
260
+ })
261
+
245
262
  afterAll(() => fakeSlider.goTo(0))
246
263
 
247
264
  test('Emit a goTo() method and index is X', () => {
@@ -86,6 +86,10 @@ describe('Mousedown & Mouseup', () => {
86
86
 
87
87
  describe('Drag()', () => {
88
88
 
89
+ beforeEach(() => {
90
+ vi.restoreAllMocks()
91
+ })
92
+
89
93
  test('Add the [aria-grabbed] attribute', () => {
90
94
  expect(fakeListItem.hasAttribute('aria-grabbed')).toBeFalsy()
91
95
  fireEvent(fakeListItem, new MouseEvent('mousedown'))
@@ -108,6 +112,10 @@ describe('Drag()', () => {
108
112
 
109
113
  describe('Drop()', () => {
110
114
 
115
+ beforeEach(() => {
116
+ vi.restoreAllMocks()
117
+ })
118
+
111
119
  test('Remove the [aria-grabbed] attribute', () => {
112
120
  expect(fakeListItem.hasAttribute('aria-grabbed')).toBeTruthy()
113
121
  fireEvent(fakeListItem, new MouseEvent('dragend'))
@@ -72,6 +72,10 @@ describe('Structure of the class', () => {
72
72
 
73
73
  describe('#Change()', () => {
74
74
 
75
+ beforeEach(() => {
76
+ vi.restoreAllMocks()
77
+ })
78
+
75
79
  test('Toggle the [aria-selected] attribute on the tab', () => {
76
80
  expect(fakeTabA.getAttribute('aria-selected')).toBe('true')
77
81
  expect(fakeTabB.getAttribute('aria-selected')).toBe('false')
@@ -150,6 +150,10 @@ describe('#Toggle()', () => {
150
150
 
151
151
  describe('Select', () => {
152
152
 
153
+ beforeEach(() => {
154
+ vi.restoreAllMocks()
155
+ })
156
+
153
157
  test('Toggle the [aria-expanded] attribute on the <select>', () => {
154
158
  expect(fakeToggleSelect._element.getAttribute('aria-expanded')).toBe('false')
155
159
  fireEvent.change(fakeToggleSelect._element, { target: { value: 'A' } })
@@ -87,6 +87,10 @@ describe('FocusOnFirst()', () => {
87
87
 
88
88
  describe('Toggle the trap', () => {
89
89
 
90
+ beforeEach(() => {
91
+ vi.restoreAllMocks()
92
+ })
93
+
90
94
  test('Activate the trap', () => {
91
95
  const eventSpy = vi.spyOn(document, 'addEventListener')
92
96
 
@@ -20,7 +20,7 @@ import { fireEvent } from "@testing-library/dom"
20
20
  import Tree from "../_tree"
21
21
 
22
22
 
23
- let fakeListTree, fakeGridTree, fakeLi, fakeRow, customClick
23
+ let fakeListTree, fakeGridTree, fakeLi, fakeRow
24
24
 
25
25
  /**
26
26
  * Before all tests
@@ -53,9 +53,6 @@ beforeAll(() => {
53
53
  fakeLi = fakeListTree._element.querySelector('li [aria-expanded]')
54
54
  fakeRow = fakeGridTree._element.querySelector('tr[aria-level="1"][aria-expanded]')
55
55
 
56
- customClick = new MouseEvent('click')
57
- Object.defineProperty(customClick, 'target', { value: fakeRow.querySelector('[data-handle=tree]') }) // Define the click event with custom target
58
-
59
56
  })
60
57
 
61
58
  describe('Structure of the class', () => {
@@ -110,23 +107,26 @@ describe('#Toggle()', () => {
110
107
  describe('Grid', () => {
111
108
 
112
109
  test('Update the [aria-expanded] attribute', () => {
110
+ const handle = fakeRow.querySelector('[data-handle=tree]')
113
111
  expect(fakeRow.getAttribute('aria-expanded')).toBe('false')
114
- fireEvent(fakeRow, customClick)
112
+ fireEvent(handle, new MouseEvent('click', { bubbles: true }))
115
113
  expect(fakeRow.getAttribute('aria-expanded')).toBe('true')
116
- fireEvent(fakeRow, customClick)
114
+ fireEvent(handle, new MouseEvent('click', { bubbles: true }))
117
115
  expect(fakeRow.getAttribute('aria-expanded')).toBe('false')
118
116
  })
119
117
 
120
118
  test('Update the [hidden] attribute on children', () => {
119
+ const handle = fakeRow.querySelector('[data-handle=tree]')
121
120
  const child = document.getElementById('lvl2')
122
121
  expect(child.hidden).toBeTruthy()
123
- fireEvent(fakeRow, customClick)
122
+ fireEvent(handle, new MouseEvent('click', { bubbles: true }))
124
123
  expect(child.hidden).toBeFalsy()
125
- fireEvent(fakeRow, customClick)
124
+ fireEvent(handle, new MouseEvent('click', { bubbles: true }))
126
125
  expect(child.hidden).toBeTruthy()
127
126
  })
128
127
 
129
128
  test('Collapse the sub-children', () => {
129
+ const handle = fakeRow.querySelector('[data-handle=tree]')
130
130
  const lvl2 = document.getElementById('lvl2')
131
131
  const lvl3 = document.getElementById('lvl3')
132
132
 
@@ -136,7 +136,7 @@ describe('#Toggle()', () => {
136
136
  const customClickLvl3 = new MouseEvent('click')
137
137
  Object.defineProperty(customClickLvl3, 'target', { value: lvl3.querySelector('[data-handle=tree]') }) // Define the click event with custom target
138
138
 
139
- fireEvent(fakeRow, customClick)
139
+ fireEvent(handle, new MouseEvent('click', { bubbles: true }))
140
140
  fireEvent(lvl2, customClickLvl2)
141
141
  fireEvent(lvl3, customClickLvl3)
142
142
 
@@ -145,7 +145,7 @@ describe('#Toggle()', () => {
145
145
  expect(lvl2.getAttribute('aria-expanded')).toBe('true')
146
146
  expect(lvl3.hidden).toBeFalsy()
147
147
 
148
- fireEvent(fakeRow, customClick)
148
+ fireEvent(handle, new MouseEvent('click', { bubbles: true }))
149
149
 
150
150
  expect(fakeRow.getAttribute('aria-expanded')).toBe('false')
151
151
  expect(lvl2.hidden).toBeTruthy()
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@natachah/vanilla-frontend",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
+ "type": "module",
4
5
  "description": "A vanilla frontend framework",
5
6
  "keywords": [
6
7
  "html5",
@@ -14,7 +15,6 @@
14
15
  "email": "info@natachaherth.ch"
15
16
  },
16
17
  "license": "MIT",
17
- "readme": "README.md",
18
18
  "scripts": {
19
19
  "test": "vitest --coverage",
20
20
  "code:build": "node esbuild.mjs",
@@ -28,16 +28,16 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@testing-library/dom": "^9.3.4",
31
- "@vitest/coverage-v8": "^1.3.1",
31
+ "@vitest/coverage-v8": "^4.0.17",
32
32
  "autoprefixer": "^10.4.19",
33
- "esbuild": "0.21.5",
33
+ "esbuild": "^0.27.2",
34
34
  "esbuild-sass-plugin": "^3.3.1",
35
35
  "fast-glob": "^3.3.2",
36
- "happy-dom": "^13.6.2",
36
+ "happy-dom": "^20.3.3",
37
37
  "postcss": "^8.4.38",
38
38
  "sass": "^1.77.5",
39
39
  "shiki": "^1.7.0",
40
- "vite": "^5.2.0",
41
- "vitest": "^1.3.1"
40
+ "vite": "^7.3.1",
41
+ "vitest": "^4.0.17"
42
42
  }
43
43
  }
package/vitest.config.js CHANGED
@@ -2,6 +2,7 @@ import { defineConfig } from 'vite'
2
2
 
3
3
  export default defineConfig({
4
4
  test: {
5
- environment: 'happy-dom'
5
+ environment: 'happy-dom',
6
+ globals: true,
6
7
  }
7
8
  })
Binary file