test: SharedTransition unit tests

This commit is contained in:
Nathan Walker
2023-03-27 21:21:33 -07:00
parent 8a6ba6e2a0
commit 550501838d
2 changed files with 103 additions and 0 deletions

View File

@@ -83,6 +83,36 @@ global.CFRunLoopGetMain = function () {
global.kCFRunLoopDefaultMode = 1;
global.CFRunLoopPerformBlock = function (runloop, kCFRunLoopDefaultMode, func) {};
global.CFRunLoopWakeUp = function (runloop) {};
global.NativeScriptGlobals = {
events: {
on: (args) => {},
off: (args) => {},
notify: (args) => {},
hasListeners: (args) => {},
},
};
global.CADisplayLink = function () {};
global.NSNotification = function () {};
global.UIApplicationDelegate = function () {};
global.UIResponder = function () {};
global.UIResponder.extend = function () {};
global.UIViewController = function () {};
global.UIAdaptivePresentationControllerDelegate = function () {};
global.UIPopoverPresentationControllerDelegate = function () {};
global.UIContentSizeCategoryExtraSmall = 0.5;
global.UIContentSizeCategorySmall = 0.7;
global.UIContentSizeCategoryMedium = 0.85;
global.UIContentSizeCategoryLarge = 1;
global.UIContentSizeCategoryExtraLarge = 1.15;
global.UIContentSizeCategoryExtraExtraLarge = 1.3;
global.UIContentSizeCategoryExtraExtraExtraLarge = 1.5;
global.UIContentSizeCategoryAccessibilityMedium = 2;
global.UIContentSizeCategoryAccessibilityLarge = 2.5;
global.UIContentSizeCategoryAccessibilityExtraLarge = 3;
global.UIContentSizeCategoryAccessibilityExtraExtraLarge = 3.5;
global.UIContentSizeCategoryAccessibilityExtraExtraExtraLarge = 4;
// global.UIDocumentInteractionController = {
// interactionControllerWithURL(url: any) {
// return null;

View File

@@ -0,0 +1,73 @@
import { SharedTransition, SharedTransitionAnimationType } from './shared-transition';
describe('SharedTransition', () => {
it('custom should create a Transition instance', () => {
const transition = SharedTransition.custom(new CustomTransition());
expect(transition.instance.id).toBe(1);
});
it('custom should create a Transition with default state and options', () => {
const transition = SharedTransition.custom(new CustomTransition());
const state = SharedTransition.getState(transition.instance.id);
expect(state.activeType).toBe(SharedTransitionAnimationType.present);
expect(state.pageStart).toBeUndefined();
expect(state.pageEnd).toBeUndefined();
expect(state.pageReturn).toBeUndefined();
expect(state.interactive).toBeUndefined();
});
it('custom should create a Transition with custom options', () => {
const transition = SharedTransition.custom(new CustomTransition(), {
interactive: {
dismiss: {
finishThreshold: 0.6,
percentFormula: (args) => {
return args.deltaX - 0.2;
},
},
},
pageStart: {
x: 200,
y: 100,
spring: {
friction: 40,
},
},
pageEnd: {
x: 0,
y: 0,
},
pageReturn: {
x: -200,
y: -100,
width: 25,
},
});
const state = SharedTransition.getState(transition.instance.id);
expect(state.activeType).toBe(SharedTransitionAnimationType.present);
expect(state.interactive.dismiss.finishThreshold).toBe(0.6);
expect(state.interactive.dismiss.percentFormula({ deltaX: 0.9, deltaY: 0, state: 0, android: null, eventName: 'pan', ios: null, object: null, type: 3, view: null })).toBe(0.7);
expect(state.pageStart.x).toBe(200);
expect(state.pageStart.y).toBe(100);
expect(state.pageStart.spring.friction).toBe(40);
expect(state.pageEnd.x).toBe(0);
expect(state.pageEnd.y).toBe(0);
expect(state.pageReturn.x).toBe(-200);
expect(state.pageReturn.y).toBe(-100);
expect(state.pageReturn.width).toBe(25);
});
});
class CustomTransition {
id: number;
constructor() {
this.id = 1;
}
getDuration() {
return 0.35;
}
setDuration(value: number) {}
getCurve() {}
animateIOSTransition() {}
createAndroidAnimator() {}
}