mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-01-12 22:51:18 +08:00
chore: add tests for tabs
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/satya164/react-navigation.git"
|
||||
},
|
||||
"author": "Satyajit Sahoo <satyajit.happy@gmail.com> (https://github.com/satya164/)",
|
||||
"author": "Satyajit Sahoo <satyajit.happy@gmail.com> (https://github.com/satya164/), Michał Osadnik <micosa97@gmail.com> (https://github.com/osdnk/)",
|
||||
"scripts": {
|
||||
"lint": "eslint --ext '.js,.ts,.tsx' .",
|
||||
"typescript": "tsc --noEmit",
|
||||
|
||||
150
packages/routers/__tests__/TabRouter.test.tsx
Normal file
150
packages/routers/__tests__/TabRouter.test.tsx
Normal file
@@ -0,0 +1,150 @@
|
||||
import { BaseActions } from '@react-navigation/core';
|
||||
import { TabRouter } from '../src';
|
||||
|
||||
jest.mock('shortid', () => () => 'test');
|
||||
|
||||
it('handles navigate action', () => {
|
||||
const router = TabRouter({});
|
||||
|
||||
expect(
|
||||
router.getStateForAction(
|
||||
{
|
||||
stale: false,
|
||||
key: 'root',
|
||||
index: 1,
|
||||
routeNames: ['baz', 'bar'],
|
||||
routeKeyHistory: [],
|
||||
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
|
||||
},
|
||||
BaseActions.navigate('baz', { answer: 42 })
|
||||
)
|
||||
).toEqual({
|
||||
stale: false,
|
||||
key: 'root',
|
||||
index: 0,
|
||||
routeNames: ['baz', 'bar'],
|
||||
routeKeyHistory: ['bar'],
|
||||
routes: [
|
||||
{ key: 'baz', name: 'baz', params: { answer: 42 } },
|
||||
{ key: 'bar', name: 'bar' },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('handles jump to action', () => {
|
||||
const router = TabRouter({});
|
||||
|
||||
expect(
|
||||
router.getStateForAction(
|
||||
{
|
||||
stale: false,
|
||||
key: 'root',
|
||||
index: 0,
|
||||
routeNames: ['baz', 'bar'],
|
||||
routeKeyHistory: [],
|
||||
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
|
||||
},
|
||||
{ type: 'JUMP_TO', payload: { name: 'bar' } }
|
||||
)
|
||||
).toEqual({
|
||||
stale: false,
|
||||
key: 'root',
|
||||
index: 1,
|
||||
routeNames: ['baz', 'bar'],
|
||||
routeKeyHistory: ['baz'],
|
||||
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
|
||||
});
|
||||
});
|
||||
|
||||
it('handles history back action', () => {
|
||||
const router = TabRouter({});
|
||||
|
||||
expect(
|
||||
router.getStateForAction(
|
||||
{
|
||||
stale: false,
|
||||
key: 'root',
|
||||
index: 0,
|
||||
routeNames: ['baz', 'bar'],
|
||||
routeKeyHistory: ['bar'],
|
||||
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
|
||||
},
|
||||
{ type: 'GO_BACK' }
|
||||
)
|
||||
).toEqual({
|
||||
stale: false,
|
||||
key: 'root',
|
||||
index: 1,
|
||||
routeNames: ['baz', 'bar'],
|
||||
routeKeyHistory: [],
|
||||
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
|
||||
});
|
||||
});
|
||||
|
||||
it('handles order back action', () => {
|
||||
const router = TabRouter({ backBehavior: 'order' });
|
||||
|
||||
expect(
|
||||
router.getStateForAction(
|
||||
{
|
||||
stale: false,
|
||||
key: 'root',
|
||||
index: 1,
|
||||
routeNames: ['baz', 'bar'],
|
||||
routeKeyHistory: [],
|
||||
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
|
||||
},
|
||||
{ type: 'GO_BACK' }
|
||||
)
|
||||
).toEqual({
|
||||
stale: false,
|
||||
key: 'root',
|
||||
index: 0,
|
||||
routeNames: ['baz', 'bar'],
|
||||
routeKeyHistory: [],
|
||||
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
|
||||
});
|
||||
});
|
||||
|
||||
it('handles order back action', () => {
|
||||
const router = TabRouter({ backBehavior: 'initialRoute' });
|
||||
|
||||
expect(
|
||||
router.getStateForAction(
|
||||
{
|
||||
stale: false,
|
||||
key: 'root',
|
||||
index: 1,
|
||||
routeNames: ['baz', 'bar'],
|
||||
routeKeyHistory: [],
|
||||
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
|
||||
},
|
||||
{ type: 'GO_BACK' }
|
||||
)
|
||||
).toEqual({
|
||||
stale: false,
|
||||
key: 'root',
|
||||
index: 0,
|
||||
routeNames: ['baz', 'bar'],
|
||||
routeKeyHistory: [],
|
||||
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
|
||||
});
|
||||
});
|
||||
|
||||
it('handles none back action', () => {
|
||||
const router = TabRouter({ backBehavior: 'none' });
|
||||
|
||||
expect(
|
||||
router.getStateForAction(
|
||||
{
|
||||
stale: false,
|
||||
key: 'root',
|
||||
index: 0,
|
||||
routeNames: ['baz', 'bar'],
|
||||
routeKeyHistory: [],
|
||||
routes: [{ key: 'baz', name: 'baz' }, { key: 'bar', name: 'bar' }],
|
||||
},
|
||||
{ type: 'GO_BACK' }
|
||||
)
|
||||
).toEqual(null);
|
||||
});
|
||||
Reference in New Issue
Block a user