|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright (C) 2016-present Chi Vinh Le and contributors. |
| 4 | + * |
| 5 | + * This software may be modified and distributed under the terms |
| 6 | + * of the MIT license. See the LICENSE file for details. |
| 7 | + */ |
| 8 | + |
| 9 | +import * as React from "react"; |
| 10 | +import { StatelessComponent } from "react"; |
| 11 | +import { assert } from "chai"; |
| 12 | +import { mount, ReactWrapper } from "enzyme"; |
| 13 | +import { spy, SinonSpy } from "sinon"; |
| 14 | +import { assemble } from "react-assemble"; |
| 15 | + |
| 16 | +import { preventPhantomEvents } from "./preventPhantomEvents"; |
| 17 | +const Component: StatelessComponent<any> = ({onTransitionEnd}) => <span {...{ onTransitionEnd }} />; |
| 18 | + |
| 19 | +describe("preventPhantomEvents", () => { |
| 20 | + const composable = preventPhantomEvents; |
| 21 | + const Assembly = assemble<any, any>(composable)(Component); |
| 22 | + let onTransitionEnd: SinonSpy; |
| 23 | + let wrapper: ReactWrapper<any, any>; |
| 24 | + |
| 25 | + beforeEach(() => { |
| 26 | + onTransitionEnd = spy(); |
| 27 | + wrapper = mount(<Assembly onTransitionEnd={onTransitionEnd} />); |
| 28 | + }); |
| 29 | + |
| 30 | + it("should block onTransitionEnd", () => { |
| 31 | + wrapper.setProps({ active: true }); |
| 32 | + const event = { timeStamp: Date.now() }; |
| 33 | + wrapper.simulate("transitionEnd", event); |
| 34 | + assert.isTrue(onTransitionEnd.notCalled); |
| 35 | + }); |
| 36 | + |
| 37 | + it("should call onTransitionEnd", () => { |
| 38 | + wrapper.setProps({ active: true }); |
| 39 | + const event = { timeStamp: Date.now() + 20 }; |
| 40 | + wrapper.simulate("transitionEnd", event); |
| 41 | + assert.isTrue(onTransitionEnd.called); |
| 42 | + }); |
| 43 | + |
| 44 | + it("should block onTransitionEnd comparing precision time", () => { |
| 45 | + wrapper.setProps({ active: true }); |
| 46 | + const event = { timeStamp: performance.now() }; |
| 47 | + wrapper.simulate("transitionEnd", event); |
| 48 | + assert.isTrue(onTransitionEnd.notCalled); |
| 49 | + }); |
| 50 | + |
| 51 | + it("should call onTransitionEnd comparing precision time", () => { |
| 52 | + wrapper.setProps({ active: true }); |
| 53 | + const event = { timeStamp: performance.now() + 20 }; |
| 54 | + wrapper.simulate("transitionEnd", event); |
| 55 | + assert.isTrue(onTransitionEnd.called); |
| 56 | + }); |
| 57 | +}); |
0 commit comments