forked from italia/design-comuni-plone-theme
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'us_49548_extra_tags_in_blocks' into slate
- Loading branch information
Showing
12 changed files
with
170 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import config from '@plone/volto/registry'; | ||
|
||
export function getComponentWithFallback(options) { | ||
if (typeof options === 'object') { | ||
const { name, dependencies = '' } = options; | ||
if (dependencies && Array.isArray(dependencies)) { | ||
const component = config.getComponent(options); | ||
if (!component.component && dependencies.length > 0) { | ||
const newDeps = [...dependencies]; | ||
newDeps.pop(); | ||
return getComponentWithFallback({ name, dependencies: newDeps }); | ||
} else { | ||
return component; | ||
} | ||
} | ||
} | ||
return config.getComponent(options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { getComponentWithFallback } from './registry'; | ||
import config from '@plone/volto/registry'; | ||
|
||
config.set('components', { | ||
Test: { component: 'test' }, | ||
'Test|dep1': { component: 'test with dep1' }, | ||
'Test|dep1+dep2': { component: 'test with dep1 and dep2' }, | ||
}); | ||
|
||
describe('getComponentWithFallback', () => { | ||
it('returns a component', () => { | ||
const component = getComponentWithFallback({ | ||
name: 'Test', | ||
}); | ||
expect(component.component).toEqual('test'); | ||
}); | ||
it('returns a component with one dependency', () => { | ||
const component = getComponentWithFallback({ | ||
name: 'Test', | ||
dependencies: ['dep1'], | ||
}); | ||
expect(component.component).toEqual('test with dep1'); | ||
}); | ||
it('returns a component with two dependencies', () => { | ||
const component = getComponentWithFallback({ | ||
name: 'Test', | ||
dependencies: ['dep1', 'dep2'], | ||
}); | ||
expect(component.component).toEqual('test with dep1 and dep2'); | ||
}); | ||
it('returns a component with one dependency if the second is not found', () => { | ||
const component = getComponentWithFallback({ | ||
name: 'Test', | ||
dependencies: ['dep1', 'dep3'], | ||
}); | ||
expect(component.component).toEqual('test with dep1'); | ||
}); | ||
it('returns a component with no dependencies if none is found', () => { | ||
const component = getComponentWithFallback({ | ||
name: 'Test', | ||
dependencies: ['dep3'], | ||
}); | ||
expect(component.component).toEqual('test'); | ||
}); | ||
}); |