-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
test(): Add cursor animation testing and migrate some easy one to jest #9829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
813bce9
f826bc6
1867255
177f5e2
97756d5
c18fb7c
60e4135
0be933a
a4b6263
9aaa03a
800b9bb
c664e8f
ca6c7e3
09d7107
2800a49
682855c
6965c29
b488664
e241e5d
7947e4d
4862bfa
9c896c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import { roundSnapshotOptions } from '../../../jest.extend'; | ||
| import { IText } from './IText'; | ||
|
|
||
| import { ValueAnimation } from '../../util/animation/ValueAnimation'; | ||
|
|
||
| export function matchTextStateSnapshot(text: IText) { | ||
| const { | ||
| styles, | ||
|
|
@@ -90,3 +92,84 @@ describe('text imperative changes', () => { | |
| expect(iText.missingNewlineOffset(0)).toBe(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe('IText cursor animation snapshot', () => { | ||
| let currentAnimation: string[] = []; | ||
| const origCalculate = ValueAnimation.prototype.calculate; | ||
| beforeAll(() => { | ||
| ValueAnimation.prototype.calculate = function (timeElapsed: number) { | ||
| const value = origCalculate.call(this, timeElapsed); | ||
| currentAnimation.push(value.value.toFixed(3)); | ||
| return value; | ||
| }; | ||
| jest.useFakeTimers(); | ||
| }); | ||
| beforeEach(() => { | ||
| jest.runAllTimers(); | ||
| currentAnimation = []; | ||
| }); | ||
| afterAll(() => { | ||
| ValueAnimation.prototype.calculate = origCalculate; | ||
| jest.useRealTimers(); | ||
| }); | ||
| test('initDelayedCursor false - with delay', () => { | ||
| const iText = new IText('', { canvas: {} }); | ||
| iText.initDelayedCursor(); | ||
| jest.advanceTimersByTime(2000); | ||
| expect(currentAnimation).toMatchSnapshot(); | ||
| iText.abortCursorAnimation(); | ||
| }); | ||
| test('initDelayedCursor true - with NO delay', () => { | ||
| const iText = new IText('', { canvas: {} }); | ||
| iText.initDelayedCursor(true); | ||
| jest.advanceTimersByTime(2000); | ||
| expect(currentAnimation).toMatchSnapshot(); | ||
| iText.abortCursorAnimation(); | ||
| }); | ||
| test('selectionStart/selection end will abort animation', () => { | ||
| const iText = new IText('asd', { canvas: {} }); | ||
| iText.initDelayedCursor(true); | ||
| jest.advanceTimersByTime(160); | ||
| iText.selectionStart = 0; | ||
| iText.selectionEnd = 3; | ||
| jest.advanceTimersByTime(2000); | ||
| expect(currentAnimation).toMatchSnapshot(); | ||
| iText.abortCursorAnimation(); | ||
| }); | ||
| test('exiting from a canvas will abort animation', () => { | ||
| const iText = new IText('asd', { canvas: {} }); | ||
| iText.initDelayedCursor(true); | ||
| jest.advanceTimersByTime(160); | ||
| iText.canvas = undefined; | ||
| jest.advanceTimersByTime(2000); | ||
| expect(currentAnimation).toMatchSnapshot(); | ||
| iText.abortCursorAnimation(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('IText _tick', () => { | ||
| const _tickMock = jest.fn(); | ||
| beforeEach(() => { | ||
| _tickMock.mockClear(); | ||
| }); | ||
| test('enter Editing will call _tick', () => { | ||
| const iText = new IText('hello\nhello'); | ||
| iText._tick = _tickMock; | ||
asturur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| iText.enterEditing(); | ||
| expect(iText._tick).toHaveBeenCalledWith(); | ||
|
||
| }); | ||
| test('mouse up will fire an animation restart with 0 delay if is a click', () => { | ||
| const iText = new IText('hello\nhello'); | ||
| iText._tick = _tickMock; | ||
| iText.enterEditing(); | ||
| expect(iText._tick).toHaveBeenCalledWith(); | ||
asturur marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _tickMock.mockClear(); | ||
| iText.__lastSelected = true; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think setting internal state makes a robust test
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is how it was before, otherwise i have to go with a full canvas where i click and select, i just moved the old tests as much as possible |
||
| iText.mouseUpHandler({ | ||
| e: { | ||
| button: 0, | ||
| }, | ||
| }); | ||
| expect(iText._tick).toHaveBeenCalledWith(0); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.