@natachah/vanilla-frontend 0.1.14 → 0.1.16

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.
@@ -9,21 +9,18 @@
9
9
  * - Constructor: Return the correct properties
10
10
  * - #Init(): Loop will clone the first and last slide
11
11
  * - #Init(): Autoplay will emmit next() method every X ms
12
- * - #Init(): Scroll will change the current attributes
13
12
  * - #Init(): Click on <button> with [role=tab] emmit the goTo() method
14
13
  * - #Init(): Click on <button> with [data-slider-prev] emmit the prev() method
15
14
  * - #Init(): Click on <button> with [data-slider-next] emmit the next() method
16
15
  * - GoTo(): Passing the correct parameters
17
- * - GoTo(): Emit a scroll() method
16
+ * - GoTo(): Go to the first or last slide via toGo() method
17
+ * - GoTo(): Change the [aria-selected], [aria-hidden] and [disabled] attributes
18
+ * - GoTo(): Emmit the slider:changed events
18
19
  * - Prev(): Emmit the goTo() method with correct index
19
20
  * - Prev(): Don't emmit the goTo() method if already first slide
20
21
  * - Next(): Emmit the goTo() method with correct index
21
22
  * - Next(): Don't emmit the goTo() method if already last slide
22
- * - #Change(): Change the [aria-selected], [aria-hidden] and [disabled] attributes
23
- * - #Change(): Emmit the slider:changing and slider:changed events
24
- * - #Loop(): Go to the last slide if too much left
25
- * - #Loop(): Go to the first slide if too much right
26
- * - #Loop(): Go to the first or last slide via toGo() method
23
+
27
24
  */
28
25
 
29
26
  import { describe, test, expect, beforeAll, vi, afterAll } from "vitest"
@@ -33,12 +30,6 @@ import ErrorMessage from "../utilities/_error"
33
30
 
34
31
  let fakeDiv, fakeSlider, fakeDivLoop, fakeSliderLoop
35
32
 
36
- function setScroll(value = 0, el = fakeDiv) {
37
- Object.assign(el, { scrollLeft: value })
38
- fireEvent.scroll(el, { target: { scrollX: value } })
39
- vi.runAllTimers()
40
- }
41
-
42
33
  /**
43
34
  * Before all tests
44
35
  *
@@ -118,7 +109,7 @@ describe('Structure of the class', () => {
118
109
  expect(fakeSlider).toHaveProperty('_current')
119
110
  expect(fakeSlider).toHaveProperty('_interval')
120
111
  expect(fakeSlider._slides).toBeTypeOf('object')
121
- expect(fakeSlider._slides).toStrictEqual(document.querySelectorAll('#slider [role=tabpanel]'))
112
+ expect(fakeSlider._slides).toStrictEqual(Array.from(document.querySelectorAll('#slider [role=tabpanel]')))
122
113
  expect(fakeSlider._buttons).toBeTypeOf('object')
123
114
  expect(fakeSlider._buttons.prev).toBeTypeOf('object')
124
115
  expect(fakeSlider._buttons.next).toBeTypeOf('object')
@@ -150,12 +141,6 @@ describe('#Init()', () => {
150
141
  clearInterval(fakeSliderAuto._interval)
151
142
  })
152
143
 
153
- test('Scroll will change the current attributes', () => {
154
- expect(fakeSlider._current).toBe(0)
155
- setScroll(100)
156
- expect(fakeSlider._current).toBe(1)
157
- })
158
-
159
144
  test('Click on <button> with [role=tab] emmit the goTo() method', () => {
160
145
  const fakeTab = fakeSlider._buttons.tabs[0]
161
146
  const methodSpy = vi.spyOn(fakeSlider, 'goTo')
@@ -185,22 +170,62 @@ describe('GoTo()', () => {
185
170
  expect(() => fakeSlider.goTo()).toThrowError(ErrorMessage.typeOf('index', 'number'))
186
171
  })
187
172
 
188
- test('Emit a scroll() method', () => {
189
- const scrollSpy = vi.spyOn(fakeDiv, 'scroll')
173
+ test('Toggle the [aria-selected], [aria-hidden] and [disabled] attributes', () => {
190
174
  fakeSlider.goTo(0)
175
+ expect(fakeSlider._current).toBe(0)
176
+ expect(fakeSlider._slides[0].getAttribute('aria-hidden')).toBe('false')
177
+ expect(fakeSlider._buttons.tabs[0].getAttribute('aria-selected')).toBe('true')
178
+ expect(fakeSlider._buttons.prev.hasAttribute('disabled')).toBeTruthy()
179
+ fakeSlider.goTo(1)
180
+ expect(fakeSlider._current).toBe(1)
181
+ expect(fakeSlider._slides[0].getAttribute('aria-hidden')).toBe('true')
182
+ expect(fakeSlider._slides[1].getAttribute('aria-hidden')).toBe('false')
183
+ expect(fakeSlider._buttons.tabs[0].getAttribute('aria-selected')).toBe('false')
184
+ expect(fakeSlider._buttons.tabs[1].getAttribute('aria-selected')).toBe('true')
185
+ expect(fakeSlider._buttons.prev.hasAttribute('disabled')).toBeFalsy()
186
+ fakeSlider.goTo(2)
187
+ expect(fakeSlider._current).toBe(2)
188
+ expect(fakeSlider._slides[1].getAttribute('aria-hidden')).toBe('true')
189
+ expect(fakeSlider._slides[2].getAttribute('aria-hidden')).toBe('false')
190
+ expect(fakeSlider._buttons.tabs[1].getAttribute('aria-selected')).toBe('false')
191
+ expect(fakeSlider._buttons.tabs[2].getAttribute('aria-selected')).toBe('true')
192
+ expect(fakeSlider._buttons.next.hasAttribute('disabled')).toBeTruthy()
193
+ })
194
+
195
+ test('Go to the first or last slide via toGo() method', () => {
196
+
197
+ const scrollSpy = vi.spyOn(fakeDivLoop, 'scroll')
198
+
199
+ fakeSliderLoop.goTo(-1)
200
+
191
201
  expect(scrollSpy).toHaveBeenCalledWith({
192
202
  behavior: "smooth",
193
203
  left: 0,
194
204
  }, undefined)
205
+
206
+ fakeSliderLoop.goTo(3)
207
+
208
+ expect(scrollSpy).toHaveBeenCalledWith({
209
+ behavior: "smooth",
210
+ left: 400,
211
+ }, undefined)
212
+
213
+ })
214
+
215
+ test('Emmit the slider:changed events', () => {
216
+ const eventSpy = vi.spyOn(fakeSlider, 'emmitEvent')
217
+ fakeSlider.goTo(0)
218
+ expect(eventSpy).toHaveBeenCalledWith('changed', { current: 0, previous: 2 })
195
219
  })
196
220
 
197
221
  })
198
222
 
199
223
  describe('Prev()', () => {
200
224
 
201
- afterAll(() => setScroll())
225
+ afterAll(() => fakeSlider.goTo(0))
202
226
 
203
227
  test('Emit a goTo() method with correct index', () => {
228
+ fakeSlider.goTo(1)
204
229
  const methodSpy = vi.spyOn(fakeSlider, 'goTo')
205
230
  fakeSlider.prev()
206
231
  expect(methodSpy).toHaveBeenCalledWith(0)
@@ -217,7 +242,7 @@ describe('Prev()', () => {
217
242
 
218
243
  describe('Next()', () => {
219
244
 
220
- afterAll(() => setScroll())
245
+ afterAll(() => fakeSlider.goTo(0))
221
246
 
222
247
  test('Emit a goTo() method and index is X', () => {
223
248
  const methodSpy = vi.spyOn(fakeSlider, 'goTo')
@@ -232,76 +257,4 @@ describe('Next()', () => {
232
257
  expect(methodSpy).not.toHaveBeenCalled()
233
258
  })
234
259
 
235
- })
236
-
237
- describe('#Change()', () => {
238
-
239
- test('Toggle the [aria-selected], [aria-hidden] and [disabled] attributes', () => {
240
- expect(fakeSlider._current).toBe(0)
241
- expect(fakeSlider._slides[0].getAttribute('aria-hidden')).toBe('false')
242
- expect(fakeSlider._buttons.tabs[0].getAttribute('aria-selected')).toBe('true')
243
- expect(fakeSlider._buttons.prev.hasAttribute('disabled')).toBeTruthy()
244
- setScroll(100)
245
- expect(fakeSlider._current).toBe(1)
246
- expect(fakeSlider._slides[0].getAttribute('aria-hidden')).toBe('true')
247
- expect(fakeSlider._slides[1].getAttribute('aria-hidden')).toBe('false')
248
- expect(fakeSlider._buttons.tabs[0].getAttribute('aria-selected')).toBe('false')
249
- expect(fakeSlider._buttons.tabs[1].getAttribute('aria-selected')).toBe('true')
250
- expect(fakeSlider._buttons.prev.hasAttribute('disabled')).toBeFalsy()
251
- setScroll(200)
252
- expect(fakeSlider._current).toBe(2)
253
- expect(fakeSlider._slides[1].getAttribute('aria-hidden')).toBe('true')
254
- expect(fakeSlider._slides[2].getAttribute('aria-hidden')).toBe('false')
255
- expect(fakeSlider._buttons.tabs[1].getAttribute('aria-selected')).toBe('false')
256
- expect(fakeSlider._buttons.tabs[2].getAttribute('aria-selected')).toBe('true')
257
- expect(fakeSlider._buttons.next.hasAttribute('disabled')).toBeTruthy()
258
- })
259
-
260
- test('Emmit the slider:changing and slider:changed events', () => {
261
- const eventSpy = vi.spyOn(fakeSlider, 'emmitEvent')
262
- setScroll(0)
263
- expect(eventSpy).toHaveBeenCalledWith('changing', { current: 2 })
264
- expect(eventSpy).toHaveBeenCalledWith('changed', { current: 0 })
265
- })
266
-
267
- })
268
-
269
- describe('#Loop()', () => {
270
-
271
- test('Go to the last slide if too much left', () => {
272
- const scrollSpy = vi.spyOn(fakeDivLoop, 'scroll')
273
- expect(fakeSliderLoop._current).toBe(0)
274
- setScroll(0, fakeDivLoop)
275
- expect(fakeSliderLoop._current).toBe(2)
276
- expect(scrollSpy).toHaveBeenCalledWith(300, 0)
277
- })
278
-
279
- test('Go to the first slide if too much right', () => {
280
- const scrollSpy = vi.spyOn(fakeDivLoop, 'scroll')
281
- expect(fakeSliderLoop._current).toBe(2)
282
- setScroll(400, fakeDivLoop)
283
- expect(fakeSliderLoop._current).toBe(0)
284
- expect(scrollSpy).toHaveBeenCalledWith(100, 0)
285
- })
286
-
287
- test('Go to the first or last slide via toGo() method', () => {
288
-
289
- const scrollSpy = vi.spyOn(fakeDivLoop, 'scroll')
290
-
291
- fakeSliderLoop.goTo(-1)
292
-
293
- expect(scrollSpy).toHaveBeenCalledWith({
294
- behavior: "smooth",
295
- left: 0,
296
- }, undefined)
297
-
298
- fakeSliderLoop.goTo(3)
299
-
300
- expect(scrollSpy).toHaveBeenCalledWith({
301
- behavior: "smooth",
302
- left: 400,
303
- }, undefined)
304
-
305
- })
306
-
307
260
  })
@@ -8,12 +8,10 @@
8
8
  * - Constructor: Return the correct properties
9
9
  * - Mousedown & Mouseup: Without handle toggle the [draggable] attribute
10
10
  * - Mousedown & Mouseup: With handle toggle the [draggable] attribute
11
- * - #Drag(): Add the [aria-grabbed] attribute
12
- * - #Drag(): Emmit the sortable:drag event
13
- * - #Drop(): Remove the [aria-grabbed] attribute
14
- * - #Drop(): Emmit the sortable:drop event
15
- * - #Move(): Go down on click and emmit the sortable:moved event
16
- * - #Move(): Go up on click and emmit the sortable:moved event
11
+ * - Drag(): Add the [aria-grabbed] attribute
12
+ * - Drag(): Emmit the sortable:drag event
13
+ * - Drop(): Remove the [aria-grabbed] attribute
14
+ * - Drop(): Emmit the sortable:drop event
17
15
  */
18
16
 
19
17
  import { describe, test, expect, beforeAll, vi } from "vitest"
@@ -54,8 +52,8 @@ describe('Structure of the class', () => {
54
52
  expect(fakeListSortable._withHandle).toBeTypeOf('boolean')
55
53
  expect(fakeListSortable._withHandle).toBe(false)
56
54
  expect(fakeTableSortable._withHandle).toBe(true)
57
- expect(fakeListSortable.items).toBeTypeOf('object')
58
- expect(fakeListSortable.items).toStrictEqual(document.querySelectorAll('#fakeList li'))
55
+ expect(fakeListSortable._items).toBeTypeOf('object')
56
+ expect(fakeListSortable._items).toStrictEqual(document.querySelectorAll('#fakeList li'))
59
57
  })
60
58
 
61
59
  })
@@ -86,7 +84,7 @@ describe('Mousedown & Mouseup', () => {
86
84
 
87
85
  })
88
86
 
89
- describe('#Drag()', () => {
87
+ describe('Drag()', () => {
90
88
 
91
89
  test('Add the [aria-grabbed] attribute', () => {
92
90
  expect(fakeListItem.hasAttribute('aria-grabbed')).toBeFalsy()
@@ -108,7 +106,7 @@ describe('#Drag()', () => {
108
106
 
109
107
  })
110
108
 
111
- describe('#Drop()', () => {
109
+ describe('Drop()', () => {
112
110
 
113
111
  test('Remove the [aria-grabbed] attribute', () => {
114
112
  expect(fakeListItem.hasAttribute('aria-grabbed')).toBeTruthy()
@@ -124,23 +122,4 @@ describe('#Drop()', () => {
124
122
  expect(eventSpy).toHaveBeenCalledWith('drop', { current: fakeListItem, items: fakeListSortable.items })
125
123
  })
126
124
 
127
- })
128
-
129
- describe('#Move()', () => {
130
-
131
- test('Go down on click and emmit the sortable:moved event', () => {
132
- const eventSpy = vi.spyOn(fakeListSortable, 'emmitEvent')
133
- fireEvent(fakeListItem.querySelector('[data-go=down]'), new MouseEvent('click'))
134
- expect(fakeListItem).toBe(document.getElementById('fakeList').children[1])
135
- expect(eventSpy).toHaveBeenCalledWith('moved', { current: fakeListItem, items: fakeListSortable.items })
136
- })
137
-
138
- test('Go up on click and emmit the sortable:moved event', () => {
139
- const eventSpy = vi.spyOn(fakeListSortable, 'emmitEvent')
140
- expect(fakeListItem).toBe(document.getElementById('fakeList').children[1])
141
- fireEvent(fakeListItem.querySelector('[data-go=up]'), new MouseEvent('click'))
142
- expect(fakeListItem).toBe(document.getElementById('fakeList').children[0])
143
- expect(eventSpy).toHaveBeenCalledWith('moved', { current: fakeListItem, items: fakeListSortable.items })
144
- })
145
-
146
125
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@natachah/vanilla-frontend",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "A vanilla frontend framework",
5
5
  "keywords": [
6
6
  "html5",
@@ -18,17 +18,18 @@
18
18
  grid-auto-flow: column;
19
19
  grid-auto-columns: calc((100% / var(--slider-columns, 1)) - var(--slider-gap, 0rem));
20
20
  gap: var(--slider-gap, 0);
21
- overscroll-behavior-inline: contain;
22
- overflow-x: auto;
23
- scroll-snap-type: inline mandatory;
21
+ overflow: hidden;
22
+ //overscroll-behavior-inline: contain;
23
+ //overflow-x: auto;
24
+ //scroll-snap-type: inline mandatory;
24
25
 
25
26
  // Remove Scrollbar
26
- scrollbar-width: none;
27
- -ms-overflow-style: none;
27
+ //scrollbar-width: none;
28
+ //-ms-overflow-style: none;
28
29
 
29
30
  > * {
30
- scroll-snap-align: start;
31
- scroll-padding-inline: 0;
31
+ //scroll-snap-align: start;
32
+ //scroll-padding-inline: 0;
32
33
  }
33
34
 
34
35
  }