2023-07-20 10:56:06 +00:00
|
|
|
const portlets = require( '../../../resources/skins.vector.js/portlets.js' );
|
|
|
|
const mustache = require( 'mustache' );
|
|
|
|
const fs = require( 'fs' );
|
|
|
|
const menuTemplate = fs.readFileSync( 'includes/templates/Menu.mustache', 'utf8' );
|
|
|
|
const menuContentsTemplate = fs.readFileSync( 'includes/templates/MenuContents.mustache', 'utf8' );
|
2023-10-03 21:51:49 +00:00
|
|
|
const dropdownOpen = fs.readFileSync( 'includes/templates/Dropdown/Open.mustache', 'utf8' );
|
|
|
|
const dropdownClose = fs.readFileSync( 'includes/templates/Dropdown/Close.mustache', 'utf8' );
|
2023-07-20 10:56:06 +00:00
|
|
|
|
|
|
|
describe( 'portlets', () => {
|
2023-10-03 21:51:49 +00:00
|
|
|
beforeEach( () => {
|
|
|
|
const marker = document.querySelector( '#vector-page-tools-dropdown' );
|
|
|
|
if ( marker ) {
|
|
|
|
marker.remove();
|
|
|
|
}
|
|
|
|
} );
|
2023-07-20 10:56:06 +00:00
|
|
|
test( 'portlets that go through the hook method should match the menu template HTML', () => {
|
|
|
|
const id = 'foo';
|
|
|
|
const label = 'label text';
|
|
|
|
const portletHTML = mustache.render( menuTemplate, {
|
2023-10-03 21:51:49 +00:00
|
|
|
id, class: '', label
|
2023-07-20 10:56:06 +00:00
|
|
|
}, {
|
|
|
|
MenuContents: menuContentsTemplate
|
|
|
|
} );
|
|
|
|
|
|
|
|
const element = document.createElement( 'div' );
|
|
|
|
element.id = id;
|
2023-10-03 21:51:49 +00:00
|
|
|
const labelElement = document.createElement( 'label' );
|
|
|
|
labelElement.textContent = label;
|
|
|
|
element.appendChild( labelElement );
|
2023-07-20 10:56:06 +00:00
|
|
|
element.appendChild( document.createElement( 'ul' ) );
|
2023-10-03 21:51:49 +00:00
|
|
|
expect( portlets.addPortletHandler( element ).outerHTML.replace( /[\s\n]/gi, '' ) )
|
2023-07-20 10:56:06 +00:00
|
|
|
.toBe( portletHTML.replace( /[\s\n]/gi, '' ) );
|
|
|
|
} );
|
2023-10-03 21:51:49 +00:00
|
|
|
|
|
|
|
test( 'portlets that go through the hook method should match the menu template HTML (dropdowns)', () => {
|
|
|
|
const id = 'foo';
|
|
|
|
const label = 'dropdown label text';
|
|
|
|
const marker = document.createElement( 'div' );
|
|
|
|
marker.id = 'vector-page-tools-dropdown';
|
|
|
|
document.body.appendChild( marker );
|
|
|
|
const dropdownHTML = mustache.render( dropdownOpen, {
|
2024-01-11 19:08:25 +00:00
|
|
|
id: `${ id }-dropdown`,
|
2023-10-03 21:51:49 +00:00
|
|
|
class: 'foo-dropdown',
|
|
|
|
label
|
|
|
|
}, {} ) + mustache.render( dropdownClose, {}, {} );
|
|
|
|
|
|
|
|
const element = document.createElement( 'div' );
|
|
|
|
element.id = id;
|
|
|
|
const labelElement = document.createElement( 'label' );
|
|
|
|
labelElement.textContent = label;
|
|
|
|
element.appendChild( labelElement );
|
|
|
|
element.appendChild( document.createElement( 'ul' ) );
|
|
|
|
document.body.appendChild( element );
|
|
|
|
|
|
|
|
const transformedPortlet = portlets.addPortletHandler( element, '#p-cactions' );
|
|
|
|
const dropdown = transformedPortlet.closest( '.vector-dropdown' );
|
|
|
|
// removing the portlet should give us an empty dropdown
|
|
|
|
transformedPortlet.remove();
|
|
|
|
|
|
|
|
expect( dropdown.outerHTML.replace( /[\s\n]/gi, '' ) )
|
|
|
|
.toBe( dropdownHTML.replace( /[\s\n]/gi, '' ) );
|
|
|
|
} );
|
2023-07-20 10:56:06 +00:00
|
|
|
} );
|