Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
case insensitive to tab view and lazy component (#115)
Browse files Browse the repository at this point in the history
* case insensitive to tab view component

* apply case insensitive to lazy component
  • Loading branch information
leonardosantiagozup authored Jun 9, 2020
1 parent 3a9aac0 commit 41a5b24
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
7 changes: 6 additions & 1 deletion __tests__/middlewares/beagleConvertToChildren.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {
treeWithChild, treeWithChildAndChildren, treeTestChild,
treeWithLazyComponent, treeWithLazyComponentParsed,
treeWithLazyComponentAndChild, treeWithLazyComponentAndChildParsed
treeWithLazyComponentAndChild, treeWithLazyComponentAndChildParsed, lazyComponentWithCaseInsensitive, parsedTabViewWithCaseInsensitive, parsedlazyComponentWithCaseInsensitive
} from '../mocks'
import beagleConvertToChildrenMiddleware from '../../src/middlewares/beagle-convert-to-children'

Expand Down Expand Up @@ -51,4 +51,9 @@ describe('ChildToChildren Middleware', () => {
const parsedTree = beagleConvertToChildrenMiddleware(treeWithLazyComponentAndChild)
expect(parsedTree).toEqual(treeWithLazyComponentAndChildParsed)
})

it('should ignore case insensitive and parse', () => {
const parsedTree = beagleConvertToChildrenMiddleware(lazyComponentWithCaseInsensitive)
expect(parsedTree).toEqual(parsedlazyComponentWithCaseInsensitive)
})
})
7 changes: 6 additions & 1 deletion __tests__/middlewares/tabViewComponent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
simpleTab, simpleTabParsed,
treeF,treeFParsed, treeA,
treeG, treeGParsed,
treeH, treeHParsed,
treeH, treeHParsed, tabViewWithCaseInsensitive, parsedTabViewWithCaseInsensitive,
} from '../mocks'
import beagleTabViewMiddleware from '../../src/middlewares/tab-view-component'

Expand Down Expand Up @@ -54,4 +54,9 @@ describe('TabViewMiddleware', () => {
expect(parsedTree).toEqual(treeA)
})

it('should ignore case insensitive and parse', () => {
const parsedTree = beagleTabViewMiddleware(tabViewWithCaseInsensitive)
expect(parsedTree).toEqual(parsedTabViewWithCaseInsensitive)
})

})
45 changes: 45 additions & 0 deletions __tests__/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,51 @@ export const treeWithLazyComponentAndChildParsed: IdentifiableBeagleUIElement =
]
}

export const tabViewWithCaseInsensitive: BeagleUIElement = {
_beagleComponent_: 'beagle:taBView',
tabItems: [
{
title: 'Container1',
child: {
_beagleComponent_: 'beagle:container'
}
},
]
}


export const parsedTabViewWithCaseInsensitive: BeagleUIElement = {
_beagleComponent_: 'beagle:taBView',
children: [
{
_beagleComponent_: 'beagle:tabitem',
title: 'Container1',
children: [{
_beagleComponent_: 'beagle:container'
}]
},
]
}

export const lazyComponentWithCaseInsensitive: IdentifiableBeagleUIElement = {
id: 'A',
_beagleComponent_: 'beagle:lazYComponent',
initialState: {
id: 'A.0',
_beagleComponent_: 'type-B',
},
}

export const parsedlazyComponentWithCaseInsensitive: IdentifiableBeagleUIElement = {
id: 'A',
_beagleComponent_: 'beagle:lazYComponent',
children: [{
id: 'A.0',
_beagleComponent_: 'type-B',
}],
}


export const configComponentsWrong: BeagleConfig<DefaultSchema>['components'] = {
'beagle:button': 'Teste',
'button': 'Teste'
Expand Down
3 changes: 2 additions & 1 deletion src/middlewares/beagle-convert-to-children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const convertChildToChildren = (uiTree: BeagleUIElement<any>) => {
}

const beagleLazyComponentMiddleware = (uiTree: BeagleUIElement<any>) => {
if (uiTree._beagleComponent_ === 'beagle:lazycomponent' && uiTree.initialState) {
const toLowerCaseName = uiTree._beagleComponent_.toString().toLowerCase()
if (toLowerCaseName === 'beagle:lazycomponent' && uiTree.initialState) {
const initialState = uiTree.initialState
if (typeof initialState !== 'object') return uiTree

Expand Down
3 changes: 2 additions & 1 deletion src/middlewares/tab-view-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ interface TabItem extends BeagleUIElement {
}

const beagleTabViewMiddleware = (uiTree: BeagleUIElement<any>) => {
if (uiTree._beagleComponent_ === 'beagle:tabview' && !uiTree.children) {
const toLowerCaseName = uiTree._beagleComponent_.toString().toLowerCase()
if (toLowerCaseName === 'beagle:tabview' && !uiTree.children) {
uiTree.children = []
const parsedItems = uiTree.tabItems.map((tab: TabItem) => {
tab._beagleComponent_ = 'beagle:tabitem'
Expand Down

0 comments on commit 41a5b24

Please sign in to comment.