123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- import * as SimpleLayouts from './SimpleLayouts';
- import LayoutTreeParser from './LayoutTreeParser';
-
- describe('LayoutTreeParser', () => {
- let uut;
-
- beforeEach(() => {
- uut = new LayoutTreeParser();
- });
-
- describe('parseFromSimpleJSON', () => {
- it('parses single screen', () => {
- expect(uut.parseFromSimpleJSON(SimpleLayouts.singleScreenApp))
- .toEqual({
- type: 'ContainerStack',
- children: [
- {
- type: 'Container',
- data: {
- name: 'com.example.MyScreen'
- },
- children: []
- }
- ]
- });
- });
-
- it('parses single screen with props', () => {
- expect(uut.parseFromSimpleJSON(SimpleLayouts.singleScreenWithAditionalParams))
- .toEqual({
- type: 'ContainerStack',
- children: [
- {
- type: 'Container',
- children: [],
- data: {
- name: 'com.example.MyScreen',
- passProps: SimpleLayouts.passProps,
- style: {},
- buttons: {}
- }
- }
- ]
- });
- const parsedPropsFn = uut.parseFromSimpleJSON(SimpleLayouts.singleScreenWithAditionalParams)
- .children[0].data.passProps.fnProp;
- expect(parsedPropsFn).toBe(SimpleLayouts.passProps.fnProp);
- expect(parsedPropsFn()).toEqual('Hello from a function');
- });
-
- it('parses tab based', () => {
- expect(uut.parseFromSimpleJSON(SimpleLayouts.tabBasedApp))
- .toEqual({
- type: 'BottomTabs',
- children: [
- {
- type: 'ContainerStack',
- children: [
- {
- type: 'Container',
- children: [],
- data: {
- name: 'com.example.ATab'
- }
- }
- ]
- },
- {
- type: 'ContainerStack',
- children: [
- {
- type: 'Container',
- children: [],
- data: {
- name: 'com.example.SecondTab'
- }
- }
- ]
- },
- {
- type: 'ContainerStack',
- children: [
- {
- type: 'Container',
- children: [],
- data: {
- name: 'com.example.ATab'
- }
- }
- ]
- }
- ]
- });
- });
-
- it('parses side menus', () => {
- expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithSideMenu))
- .toEqual({
- type: 'SideMenuRoot',
- children: [
- {
- type: 'SideMenuLeft',
- children: [
- {
- type: 'Container',
- data: {
- name: 'com.example.SideMenu'
- },
- children: []
- }
- ]
- },
- {
- type: 'SideMenuCenter',
- children: [
- {
- type: 'ContainerStack',
- children: [
- {
- type: 'Container',
- data: {
- name: 'com.example.MyScreen'
- },
- children: []
- }
- ]
- }
- ]
- }
- ]
- });
- });
-
- it('parses side menu right', () => {
- expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithRightSideMenu))
- .toEqual({
- type: 'SideMenuRoot',
- children: [
- {
- type: 'SideMenuCenter',
- children: [
- {
- type: 'ContainerStack',
- children: [
- {
- type: 'Container',
- data: {
- name: 'com.example.MyScreen'
- },
- children: []
- }
- ]
- }
- ]
- },
- {
- type: 'SideMenuRight',
- children: [
- {
- type: 'Container',
- data: {
- name: 'com.example.SideMenu'
- },
- children: []
- }
- ]
- }
- ]
- });
- });
-
- it('parses both side menus', () => {
- expect(uut.parseFromSimpleJSON(SimpleLayouts.singleWithBothMenus))
- .toEqual({
- type: 'SideMenuRoot',
- children: [
- {
- type: 'SideMenuLeft',
- children: [
- {
- type: 'Container',
- data: {
- name: 'com.example.Menu1'
- },
- children: []
- }
- ]
- },
- {
- type: 'SideMenuCenter',
- children: [
- {
- type: 'ContainerStack',
- children: [
- {
- type: 'Container',
- data: {
- name: 'com.example.MyScreen'
- },
- children: []
- }
- ]
- }
- ]
- },
- {
- type: 'SideMenuRight',
- children: [
- {
- type: 'Container',
- data: {
- name: 'com.example.Menu2'
- },
- children: []
- }
- ]
- }
- ]
- });
- });
-
- it('parses tabs with side menus', () => {
- expect(uut.parseFromSimpleJSON(SimpleLayouts.tabBasedWithBothSideMenus))
- .toEqual({
- type: 'SideMenuRoot',
- children: [
- {
- type: 'SideMenuLeft',
- children: [
- {
- type: 'Container',
- data: {
- name: 'com.example.Menu1'
- },
- children: []
- }
- ]
- },
- {
- type: 'SideMenuCenter',
- children: [
- {
- type: 'BottomTabs',
- children: [
- {
- type: 'ContainerStack',
- children: [
- {
- type: 'Container',
- data: {
- name: 'com.example.FirstTab'
- },
- children: []
- }
- ]
- },
- {
- type: 'ContainerStack',
- children: [
- {
- type: 'Container',
- data: {
- name: 'com.example.SecondTab'
- },
- children: []
- }
- ]
- }
- ]
- }
- ]
- },
- {
- type: 'SideMenuRight',
- children: [
- {
- type: 'Container',
- data: {
- name: 'com.example.Menu2'
- },
- children: []
- }
- ]
- }
- ]
- });
- });
- });
-
- describe('createContainer', () => {
- it('creates container object with passed data', () => {
- expect(uut.createContainer({ foo: 'bar' })).toEqual({ type: 'Container', data: { foo: 'bar' }, children: [] });
- });
- });
- });
|