Skip to content

Commit

Permalink
huge tests speed-up
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianDavideConte committed Jan 18, 2024
1 parent dd52a44 commit f120979
Show file tree
Hide file tree
Showing 18 changed files with 2,046 additions and 2,405 deletions.
104 changes: 47 additions & 57 deletions cypress/e2e/calcScrollbarsDimensions-tests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,73 +117,63 @@ describe("calcScrollbarsDimensions-webkit-scrollbar-modifiers", function () {
.then((win) => {
//Firefox doens't support the ::webkit-scrollbar css modifier
if (browserIsFirefox(win)) return;

cy.testFailingValues(uss.calcScrollbarsDimensions, {
0: [constants.failingValuesAllNoUndefined,
[true, false],
]
},
(res, v1, v2, v3, v4, v5, v6, v7) => {
expect(res).to.throw(constants.defaultUssException);
})
.then(() => {
const _maxDim = uss.getScrollbarsMaxDimension();

const _elementWithScrollbarOnTheXYAxes = win.document.getElementById("xy-scroller");
let _originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);
const _maxDim = uss.getScrollbarsMaxDimension();

const _elementWithScrollbarOnTheXYAxes = win.document.getElementById("xy-scroller");
let _originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);

expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes),
[_maxDim, _maxDim])
).to.be.true;
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes),
[_maxDim, _maxDim])
).to.be.true;
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;

_elementWithScrollbarOnTheXYAxes.classList.add("no-webkit-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);
_elementWithScrollbarOnTheXYAxes.classList.add("no-webkit-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);

expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, false),
[_maxDim, _maxDim])
).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, true),
[0, 0])
).to.be.true;
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, false),
[_maxDim, _maxDim])
).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, true),
[0, 0])
).to.be.true;
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;

_elementWithScrollbarOnTheXYAxes.classList.remove("no-webkit-scrollbars");
_elementWithScrollbarOnTheXYAxes.classList.add("width-0-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);
_elementWithScrollbarOnTheXYAxes.classList.remove("no-webkit-scrollbars");
_elementWithScrollbarOnTheXYAxes.classList.add("width-0-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);

expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, false),
[0, 0])
).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, true),
[0, _maxDim])
).to.be.true;
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, false),
[0, 0])
).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, true),
[0, _maxDim])
).to.be.true;
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;

_elementWithScrollbarOnTheXYAxes.classList.remove("width-0-scrollbars");
_elementWithScrollbarOnTheXYAxes.classList.add("height-0-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);
_elementWithScrollbarOnTheXYAxes.classList.remove("width-0-scrollbars");
_elementWithScrollbarOnTheXYAxes.classList.add("height-0-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);

expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, false),
[0, _maxDim])
).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, true),
[_maxDim, 0])
).to.be.true;
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, false),
[0, _maxDim])
).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, true),
[_maxDim, 0])
).to.be.true;
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;

_elementWithScrollbarOnTheXYAxes.classList.remove("height-0-scrollbars");
_elementWithScrollbarOnTheXYAxes.classList.add("width-0-height-0-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);
_elementWithScrollbarOnTheXYAxes.classList.remove("height-0-scrollbars");
_elementWithScrollbarOnTheXYAxes.classList.add("width-0-height-0-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);

expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, false),
[_maxDim, 0])
).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, true),
[0, 0])
).to.be.true;
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;
});
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, false),
[_maxDim, 0])
).to.be.true;
expect(constants.arraysAreEqual(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes, true),
[0, 0])
).to.be.true;
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;
});
});
});
93 changes: 42 additions & 51 deletions cypress/e2e/calcXScrollbarDimension-tests.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,65 +112,56 @@ describe("calcXScrollbarDimension-webkit-scrollbar-modifiers", function () {
//Firefox doens't support the ::webkit-scrollbar css modifier
if (browserIsFirefox(win)) return;

cy.testFailingValues(uss.calcXScrollbarDimension, {
0: [constants.failingValuesAllNoUndefined,
[true, false],
]
},
(res, v1, v2, v3, v4, v5, v6, v7) => {
expect(res).to.throw(constants.defaultUssException);
})
.then(() => {
const _maxDim = uss.getScrollbarsMaxDimension();

const _elementWithScrollbarOnTheXYAxes = win.document.getElementById("xy-scroller");
let _originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);
const _maxDim = uss.getScrollbarsMaxDimension();

const _elementWithScrollbarOnTheXYAxes = win.document.getElementById("xy-scroller");
let _originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);

expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(_maxDim);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(_maxDim);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], true);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], false);
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;

_elementWithScrollbarOnTheXYAxes.classList.add("no-webkit-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(_maxDim);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(_maxDim);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], true);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], false);
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;

_elementWithScrollbarOnTheXYAxes.classList.add("no-webkit-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);

expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(_maxDim);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(0);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], true);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], false);
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;

_elementWithScrollbarOnTheXYAxes.classList.remove("no-webkit-scrollbars");
_elementWithScrollbarOnTheXYAxes.classList.add("width-0-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(_maxDim);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(0);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], true);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], false);
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;

_elementWithScrollbarOnTheXYAxes.classList.remove("no-webkit-scrollbars");
_elementWithScrollbarOnTheXYAxes.classList.add("width-0-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);

expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(0);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(0);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], true);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], false);
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(0);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(0);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], true);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], false);
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;

_elementWithScrollbarOnTheXYAxes.classList.remove("width-0-scrollbars");
_elementWithScrollbarOnTheXYAxes.classList.add("height-0-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);
_elementWithScrollbarOnTheXYAxes.classList.remove("width-0-scrollbars");
_elementWithScrollbarOnTheXYAxes.classList.add("height-0-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);

expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(0);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(_maxDim);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], true);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], false);
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(0);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(_maxDim);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], true);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], false);
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;

_elementWithScrollbarOnTheXYAxes.classList.remove("height-0-scrollbars");
_elementWithScrollbarOnTheXYAxes.classList.add("width-0-height-0-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);
_elementWithScrollbarOnTheXYAxes.classList.remove("height-0-scrollbars");
_elementWithScrollbarOnTheXYAxes.classList.add("width-0-height-0-scrollbars");
_originalScrollPos = _getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes);

expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(_maxDim);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(0);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], true);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], false);
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;
});
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(_maxDim);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(0);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, true)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], true);
expect(uss.calcXScrollbarDimension(_elementWithScrollbarOnTheXYAxes, false)).to.equal(uss.calcScrollbarsDimensions(_elementWithScrollbarOnTheXYAxes)[0], false);
expect(constants.arraysAreEqual(_getCurrentScrollPos(_elementWithScrollbarOnTheXYAxes), _originalScrollPos)).to.be.true;
});
});
});
Loading

0 comments on commit f120979

Please sign in to comment.