/** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import {DynamicContentProjectionHelper} from '@angular/upgrade/src/dynamic/content_projection_helper'; import {nodes} from './test_helpers'; export function main() { describe('groupNodesBySelector', () => { let groupNodesBySelector: (ngContentSelectors: string[], nodes: Node[]) => Node[][]; beforeEach(() => { const projectionHelper = new DynamicContentProjectionHelper(); groupNodesBySelector = projectionHelper.groupNodesBySelector.bind(projectionHelper); }); it('should return an array of node collections for each selector', () => { const contentNodes = nodes( '
div-1 content
' + '' + '' + 'span content' + '
div-2 content
'); const selectors = ['input[type=date]', 'span', '.x']; const projectableNodes = groupNodesBySelector(selectors, contentNodes); expect(projectableNodes[0]).toEqual(nodes('')); expect(projectableNodes[1]).toEqual(nodes('span content')); expect(projectableNodes[2]) .toEqual(nodes( '
div-1 content
' + '
div-2 content
')); }); it('should collect up unmatched nodes for the wildcard selector', () => { const contentNodes = nodes( '
div-1 content
' + '' + '' + 'span content' + '
div-2 content
'); const selectors = ['.x', '*', 'input[type=date]']; const projectableNodes = groupNodesBySelector(selectors, contentNodes); expect(projectableNodes[0]) .toEqual(nodes( '
div-1 content
' + '
div-2 content
')); expect(projectableNodes[1]) .toEqual(nodes( '' + 'span content')); expect(projectableNodes[2]).toEqual(nodes('')); }); it('should return an array of empty arrays if there are no nodes passed in', () => { const selectors = ['.x', '*', 'input[type=date]']; const projectableNodes = groupNodesBySelector(selectors, []); expect(projectableNodes).toEqual([[], [], []]); }); it('should return an empty array for each selector that does not match', () => { const contentNodes = nodes( '
div-1 content
' + '' + '' + 'span content' + '
div-2 content
'); const noSelectorNodes = groupNodesBySelector([], contentNodes); expect(noSelectorNodes).toEqual([]); const noMatchSelectorNodes = groupNodesBySelector(['.not-there'], contentNodes); expect(noMatchSelectorNodes).toEqual([[]]); }); }); }