From 52eaa3f629a8e0e18228265c3da354607abdb8a4 Mon Sep 17 00:00:00 2001 From: Sartxi Date: Thu, 3 Aug 2023 15:11:30 -0600 Subject: [PATCH] action scroller test converage --- .../action-scroller/action-scroller.test.js | 33 +++++ test/blocks/action-scroller/mocks/body.html | 120 ++++++++++++++++++ 2 files changed, 153 insertions(+) diff --git a/test/blocks/action-scroller/action-scroller.test.js b/test/blocks/action-scroller/action-scroller.test.js index 6dd5fedb63..1b732ef766 100644 --- a/test/blocks/action-scroller/action-scroller.test.js +++ b/test/blocks/action-scroller/action-scroller.test.js @@ -1,11 +1,25 @@ import { readFile } from '@web/test-runner-commands'; import { expect } from '@esm-bundle/chai'; +import { loadStyle } from '../../../libs/utils/utils.js'; +import { delay } from '../../helpers/waitfor.js'; document.body.innerHTML = await readFile({ path: './mocks/body.html' }); const { default: init } = await import('../../../libs/blocks/action-scroller/action-scroller.js'); const variants = ['navigation']; +const loadStyles = (path) => new Promise((resolve) => { + loadStyle(`../../../../libs/${path}`, resolve); +}); + describe('action scrollers', () => { + before(async () => { + await Promise.all([ + loadStyles('../../../libs/styles/styles.css'), + loadStyles('../../../libs/blocks/action-scroller/action-scroller.css'), + loadStyles('../../../libs/blocks/section-metadata/section-metadata.css') + ]); + }); + const actionScroller = document.querySelectorAll('.action-scroller'); actionScroller.forEach((scroller) => { init(scroller); @@ -28,6 +42,25 @@ describe('action scrollers', () => { const next = scroller.querySelector('.next'); expect(next).to.exist; }); + + it('can scroll next', async () => { + const scrollArea = scroller.querySelector('.section.scrolling'); + const nextBtn = scroller.querySelector('.next-button'); + nextBtn.click(); + await delay(200); + const scrolled = scrollArea.scrollLeft > 0; + expect(scrolled).to.be.true; + }); + + it('can scroll previous', async () => { + const scrollArea = scroller.querySelector('.section.scrolling'); + const prevBtn = scroller.querySelector('.previous-button'); + const initScrollPos = scrollArea.scrollLeft; + prevBtn.click(); + await delay(200); + const scrolledBack = initScrollPos > scrollArea.scrollLeft; + expect(scrolledBack).to.be.true; + }); } }); }); diff --git a/test/blocks/action-scroller/mocks/body.html b/test/blocks/action-scroller/mocks/body.html index 6b21167dae..de2fd499a1 100644 --- a/test/blocks/action-scroller/mocks/body.html +++ b/test/blocks/action-scroller/mocks/body.html @@ -31,6 +31,66 @@
https://www.adobe.com/
+
+
+ + + +
+
+
https://www.adobe.com/
+
+
+
+
+ + + +
+
+
https://www.adobe.com/
+
+
+
+
+ + + +
+
+
https://www.adobe.com/
+
+
+
+
+ + + +
+
+
https://www.adobe.com/
+
+
+
+
+ + + +
+
+
https://www.adobe.com/
+
+
+
+
+ + + +
+
+
https://www.adobe.com/
+
+
+
+
+ + + +
+
+
https://www.adobe.com/
+
+
+
+
+ + + +
+
+
https://www.adobe.com/
+
+
+
+
+ + + +
+
+
https://www.adobe.com/
+
+
+
+
+ + + +
+
+
https://www.adobe.com/
+
+
+
+
+ + + +
+
+
https://www.adobe.com/
+
+
+
+
+ + + +
+
+
https://www.adobe.com/
+
+