Skip to content

Commit 64842d0

Browse files
committed
(test): ensure getCanvas and getTrimmedCanvas work properly
- needed to add width & height to element as otherwise trimming would fail due to non-existent width & height - add initial and trimmed width & height as fixtures - tried using some dataURL fixtures but they would end up slightly different, so I suppose a bit of that is implementation-specific
1 parent 29dd1bb commit 64842d0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/index.spec.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { mount } from 'enzyme'
33
import React from 'react'
44

55
import SignatureCanvas from './index.js'
6-
import { dotData } from '../test-utils/fixtures.js'
6+
import { dotData, canvasProps, trimmedSize } from '../test-utils/fixtures.js'
77

88
test('mounts canvas and instance properly', () => {
99
const wrapper = mount(<SignatureCanvas />)
@@ -85,3 +85,21 @@ describe('SigCanvas wrapper methods return equivalent to SigPad', () => {
8585
expect(isEmpty).toBe(sigPad.isEmpty())
8686
})
8787
})
88+
89+
describe('get methods return correct canvases', () => {
90+
const instance = mount(
91+
<SignatureCanvas canvasProps={canvasProps} />
92+
).instance()
93+
instance.fromData(dotData)
94+
95+
test('getCanvas should return the same underlying canvas', () => {
96+
const canvas = instance.getCanvas()
97+
expect(instance.toDataURL()).toBe(canvas.toDataURL())
98+
})
99+
100+
test('getTrimmedCanvas should return a trimmed canvas', () => {
101+
const trimmed = instance.getTrimmedCanvas()
102+
expect(trimmed.width).toBe(trimmedSize.width)
103+
expect(trimmed.height).toBe(trimmedSize.height)
104+
})
105+
})

test-utils/fixtures.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export const dotData = [
22
[{ x: 466.59375, y: 189, time: 1564339579755, color: 'black' }]
33
]
4+
export const canvasProps = { width: 1011, height: 326 }
5+
export const trimmedSize = { width: 4, height: 4 }

0 commit comments

Comments
 (0)