11import $ from 'jquery' ;
22import domUtils from '__internal/core/utils/m_dom' ;
3+ import { EmptyTemplate } from '__internal/core/templates/m_empty_template' ;
34import support from '__internal/core/utils/m_support' ;
45import styleUtils from 'core/utils/style' ;
56import devices from '__internal/core/m_devices' ;
@@ -8,6 +9,36 @@ import keyboardMock from '../../helpers/keyboardMock.js';
89
910QUnit . module ( 'createMarkup' ) ;
1011
12+ QUnit . test ( 'normalizeTemplateElement returns a wrapper if given an element' , function ( assert ) {
13+ const domElement = document . createElement ( 'span' ) ;
14+
15+ domElement . innerHTML = 'Some text' ;
16+
17+ const $result = domUtils . normalizeTemplateElement ( domElement ) ;
18+
19+ assert . equal ( $result . length , 1 , 'normalizeTemplateElement works with elements' ) ;
20+ assert . equal ( $result [ 0 ] . localName , 'span' , 'normalizeTemplateElement works with elements' ) ;
21+ assert . equal ( $result . text ( ) , 'Some text' , 'normalizeTemplateElement works with elements' ) ;
22+ } ) ;
23+
24+ QUnit . test ( 'normalizeTemplateElement returns a wrapper if given an HTML string' , function ( assert ) {
25+ const htmlString = '<span>Some text</span>' ;
26+
27+ const $result = domUtils . normalizeTemplateElement ( htmlString ) ;
28+
29+ assert . equal ( $result . length , 1 , 'normalizeTemplateElement works with strings' ) ;
30+ assert . equal ( $result [ 0 ] . localName , 'span' , 'normalizeTemplateElement works with strings' ) ;
31+ assert . equal ( $result . text ( ) , 'Some text' , 'normalizeTemplateElement works with strings' ) ;
32+ } ) ;
33+
34+ QUnit . test ( 'normalizeTemplateElement returns an empty element for other inputs (T1280032) (jQuery 4)' , function ( assert ) {
35+ const template = new EmptyTemplate ( ) ;
36+
37+ const $result = domUtils . normalizeTemplateElement ( template ) ;
38+
39+ assert . equal ( $result . length , 0 , 'normalizeTemplateElement works with TemplateBase objects' ) ;
40+ } ) ;
41+
1142QUnit . test ( 'normalizeTemplateElement with script element' , function ( assert ) {
1243 const domElement = document . createElement ( 'script' ) ;
1344
@@ -18,7 +49,6 @@ QUnit.test('normalizeTemplateElement with script element', function(assert) {
1849 assert . equal ( $result . text ( ) , 'Test' , 'template based on script element works fine' ) ;
1950} ) ;
2051
21-
2252QUnit . module ( 'clipboard' ) ;
2353
2454QUnit . test ( 'get text from clipboard' , function ( assert ) {
0 commit comments