const portlets = require( '../../../resources/skins.vector.legacy.js/portlets.js' ); const mustache = require( 'mustache' ); const fs = require( 'fs' ); const menuTemplate = fs.readFileSync( 'includes/templates/LegacyMenu.mustache', 'utf8' ); const menuContentsTemplate = fs.readFileSync( 'includes/templates/MenuContents.mustache', 'utf8' ); describe( 'portlets', () => { test( 'portlets that go through the hook method should match the menu template HTML (non-dropdown version)', () => { const id = 'foo'; const label = 'label text'; const portletHTML = mustache.render( menuTemplate, { id, class: '', label }, { MenuContents: menuContentsTemplate } ); const element = document.createElement( 'div' ); element.id = id; if ( label ) { const labelElement = document.createElement( 'label' ); labelElement.textContent = label; element.appendChild( labelElement ); } element.appendChild( document.createElement( 'ul' ) ); const actual = portlets.addPortletHandler( element ).outerHTML.replace( /[\s\n]/gi, '' ) // Known Difference 1: `div` elements need `role="navigation"`. // `nav` elements do not. .replace( /role="navigation"/g, '' ); const expected = portletHTML.replace( /[\s\n]/gi, '' ) // Known Difference 2: Portlets created via JS are `div` elements not `nav` .replace( /