Skip to content

Commit

Permalink
starting to add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
catdad committed Oct 1, 2023
1 parent 444a1d7 commit aeb70a2
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,37 @@ test('stops and removes canvas immediately when `reset` is called', async t => {
t.deepEqual(results, [false, true, false, 'done']);
});

/*
* Shape from path
*/
test('shapeFromPath: creates an object with a path and transform matrix', async t => {
const page = t.context.page = await fixturePage();

const result = await page.evaluate(`
confetti.shapeFromPath('M0 0 L10 0 L10 10 L0 10z');
`);

t.deepEqual(result, {
type: 'path',
path: 'M0 0 L10 0 L10 10 L0 10z',
matrix: [ 1, 0, 0, 1, -5, -5 ]
});
});

test('shapeFromPath: crops the shape and centers in the middle of the actual path object', async t => {
const page = t.context.page = await fixturePage();

const result = await page.evaluate(`
confetti.shapeFromPath('M100 100 L110 100 L110 110 L100 110z');
`);

t.deepEqual(result, {
type: 'path',
path: 'M100 100 L110 100 L110 110 L100 110z',
matrix: [ 1, 0, 0, 1, -105, -105 ]
});
});

/*
* Custom canvas
*/
Expand Down Expand Up @@ -994,3 +1025,9 @@ test('exposed confetti method has a `reset` property', async t => {

t.is(await page.evaluate(`typeof confettiAlias.reset`), 'function');
});

test('exposed confetti method has a `shapeFromPath` property', async t => {
const page = t.context.page = await fixturePage('fixtures/page.module.html');

t.is(await page.evaluate(`typeof confettiAlias.shapeFromPath`), 'function');
});

0 comments on commit aeb70a2

Please sign in to comment.