Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
thednp committed Aug 11, 2024
1 parent 978439a commit 2739b94
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions cypress/e2e/dommatrix.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import CSSMatrix from '../../src/index';
import type { Matrix, Matrix3d } from '../../src/types';
import testSamples from '../fixtures/testSamples';

const roundTo4 = (x: number) => Math.round(x * 10000) / 10000

describe('DOMMatrix Class Test', () => {

beforeEach(() => {
Expand Down Expand Up @@ -115,10 +117,10 @@ describe('DOMMatrix Class Test', () => {
// for some reason DOMMatrix in
// expect(m1.toFloat32Array()).to.deep.equal(d1.toFloat32Array());
// expect(m1.toFloat64Array()).to.deep.equal(d1.toFloat64Array());
expect(Array.from(m1.toFloat32Array()).map(x => x.toFixed(5)))
.to.deep.equal(Array.from(d1.toFloat32Array()).map(x => x.toFixed(5)));
expect(Array.from(m1.toFloat64Array()).map(x => x.toFixed(5)))
.to.deep.equal(Array.from(d1.toFloat64Array()).map(x => x.toFixed(5)));
expect(Array.from(m1.toFloat32Array()).map(roundTo4))
.to.deep.equal(Array.from(d1.toFloat32Array()).map(roundTo4));
expect(Array.from(m1.toFloat64Array()).map(roundTo4))
.to.deep.equal(Array.from(d1.toFloat64Array()).map(roundTo4));
});

cy.log('CSSMatrix.rotate(x:25, y:15)').then(() => {
Expand All @@ -137,10 +139,10 @@ describe('DOMMatrix Class Test', () => {
// same here
// expect(m2.toFloat32Array()).to.deep.equal(d2.toFloat32Array());
// expect(m2.toFloat64Array()).to.deep.equal(d2.toFloat64Array());
expect(Array.from(m2.toFloat32Array()).map(x => x.toFixed(5)))
.to.deep.equal(Array.from(d2.toFloat32Array()).map(x => x.toFixed(5)));
expect(Array.from(m2.toFloat64Array()).map(x => x.toFixed(5)))
.to.deep.equal(Array.from(d2.toFloat64Array()).map(x => x.toFixed(5)));
expect(Array.from(m2.toFloat32Array()).map(roundTo4))
.to.deep.equal(Array.from(d2.toFloat32Array()).map(roundTo4));
expect(Array.from(m2.toFloat64Array()).map(roundTo4))
.to.deep.equal(Array.from(d2.toFloat64Array()).map(roundTo4));
});

cy.log('CSSMatrix.translate(x:150)').then(() => {
Expand All @@ -155,8 +157,12 @@ describe('DOMMatrix Class Test', () => {
})
expect(m3.isIdentity).to.equal(d3.isIdentity);
expect(m3.is2D).to.equal(d3.is2D);
expect(m3.toFloat32Array()).to.deep.equal(d3.toFloat32Array());
expect(m3.toFloat64Array()).to.deep.equal(d3.toFloat64Array());
// expect(m3.toFloat32Array()).to.deep.equal(d3.toFloat32Array());
// expect(m3.toFloat64Array()).to.deep.equal(d3.toFloat64Array());
expect(Array.from(m3.toFloat32Array()).map(roundTo4))
.to.deep.equal(Array.from(d3.toFloat32Array()).map(roundTo4));
expect(Array.from(m3.toFloat64Array()).map(roundTo4))
.to.deep.equal(Array.from(d3.toFloat64Array()).map(roundTo4));
});

cy.log('CSSMatrix.skew(x:15, y:-20)').then(() => {
Expand All @@ -171,8 +177,12 @@ describe('DOMMatrix Class Test', () => {
})
expect(m4.isIdentity).to.equal(d4.isIdentity);
expect(m4.is2D).to.equal(d4.is2D);
expect(m4.toFloat32Array()).to.deep.equal(d4.toFloat32Array());
expect(m4.toFloat64Array()).to.deep.equal(d4.toFloat64Array());
// expect(m4.toFloat32Array()).to.deep.equal(d4.toFloat32Array());
// expect(m4.toFloat64Array()).to.deep.equal(d4.toFloat64Array());
expect(Array.from(m4.toFloat32Array()).map(roundTo4))
.to.deep.equal(Array.from(d4.toFloat32Array()).map(roundTo4));
expect(Array.from(m4.toFloat64Array()).map(roundTo4))
.to.deep.equal(Array.from(d4.toFloat64Array()).map(roundTo4));
});

cy.log('CSSMatrix.scale(x:1.3)').then(() => {
Expand All @@ -186,8 +196,12 @@ describe('DOMMatrix Class Test', () => {
})
expect(m5.isIdentity).to.equal(d5.isIdentity);
expect(m5.is2D).to.equal(d5.is2D);
expect(m5.toFloat32Array()).to.deep.equal(d5.toFloat32Array());
expect(m5.toFloat64Array()).to.deep.equal(d5.toFloat64Array());
// expect(m5.toFloat32Array()).to.deep.equal(d5.toFloat32Array());
// expect(m5.toFloat64Array()).to.deep.equal(d5.toFloat64Array());
expect(Array.from(m5.toFloat32Array()).map(roundTo4))
.to.deep.equal(Array.from(d5.toFloat32Array()).map(roundTo4));
expect(Array.from(m5.toFloat64Array()).map(roundTo4))
.to.deep.equal(Array.from(d5.toFloat64Array()).map(roundTo4));
});

cy.log('CSSMatrix.scale(x:1.3,y:1.8)').then(() => {
Expand All @@ -201,8 +215,12 @@ describe('DOMMatrix Class Test', () => {
})
expect(m6.isIdentity).to.equal(d6.isIdentity);
expect(m6.is2D).to.equal(d6.is2D);
expect(m6.toFloat32Array()).to.deep.equal(d6.toFloat32Array());
expect(m6.toFloat64Array()).to.deep.equal(d6.toFloat64Array());
// expect(m6.toFloat32Array()).to.deep.equal(d6.toFloat32Array());
// expect(m6.toFloat64Array()).to.deep.equal(d6.toFloat64Array());
expect(Array.from(m6.toFloat32Array()).map(roundTo4))
.to.deep.equal(Array.from(d6.toFloat32Array()).map(roundTo4));
expect(Array.from(m6.toFloat64Array()).map(roundTo4))
.to.deep.equal(Array.from(d6.toFloat64Array()).map(roundTo4));
});

cy.log('CSSMatrix.transformPoint').then(() => {
Expand Down Expand Up @@ -295,10 +313,11 @@ describe('DOMMatrix Class Test', () => {
cy.get('.bg-secondary').then(($el) => {
$el[0].style.transform = dom.toString();
});

cy.log('Due to the nature of the native DOMMatrix RegExp, for consistency reasons we\'re rounding numbers to 6 decimals in this test.')

expect(Array.from(css.toFloat32Array()).map(x=> Math.floor(x * 10**6) / 10**6))
.to.deep.equal(Array.from(dom.toFloat32Array()).map(x=> Math.floor(x * 10**6) / 10**6));
expect(Array.from(css.toFloat32Array()).map(roundTo4))
.to.deep.equal(Array.from(dom.toFloat32Array()).map(roundTo4));

cy.wrap(css).as('css')
.log('The native `DOMMatrix` is a little weird when it comes to rotateAxisAngle, it falsely claims the identity matrix is NOT `is2D`')
Expand Down

0 comments on commit 2739b94

Please sign in to comment.