@@ -3,6 +3,7 @@ import { test } from "qunit";
33import sinon from "sinon" ;
44import {
55 acceptance ,
6+ query ,
67 queryAll ,
78 visible ,
89} from "discourse/tests/helpers/qunit-helpers" ;
@@ -494,3 +495,64 @@ acceptance("Dropdown header - Redirect to URL", function (needs) {
494495 ) ;
495496 } ) ;
496497} ) ;
498+
499+ acceptance ( "Dropdown header - Mobile view" , function ( needs ) {
500+ needs . mobileView ( ) ;
501+
502+ needs . hooks . beforeEach ( ( ) => {
503+ settings . header_links = JSON . stringify ( headerLinksSettingFixtures ) ;
504+ settings . dropdown_links = JSON . stringify ( dropdownLinksSettingFixtures ) ;
505+ } ) ;
506+
507+ needs . hooks . afterEach ( ( ) => {
508+ settings . header_links = "[]" ;
509+ settings . dropdown_links = "[]" ;
510+ } ) ;
511+
512+ test ( "it toggles the header dropdown on click" , async function ( assert ) {
513+ await visit ( "/" ) ;
514+
515+ const headerLinkElement = query ( ".custom-header-links button" ) ;
516+ await click ( headerLinkElement ) ;
517+
518+ assert . ok (
519+ visible ( ".top-level-links" ) ,
520+ "The top header dropdown is visible"
521+ ) ;
522+
523+ const linksElements = queryAll ( ".custom-header-link" ) ;
524+ const linkElement = linksElements [ 0 ] ;
525+
526+ assert . ok (
527+ linkElement . classList . contains ( "is-open" ) ,
528+ "The header dropdown is visible initially"
529+ ) ;
530+
531+ await click ( linkElement ) ;
532+
533+ assert . notOk (
534+ linkElement . classList . contains ( "is-open" ) ,
535+ "The header dropdown is hidden after click"
536+ ) ;
537+ } ) ;
538+
539+ test ( "it doesn't render the caret icon on header link with URL defined" , async function ( assert ) {
540+ await visit ( "/" ) ;
541+
542+ const headerLinkElement = query ( ".custom-header-links button" ) ;
543+ await click ( headerLinkElement ) ;
544+
545+ const linksElements = queryAll ( ".custom-header-link" ) ;
546+ const caretElement = linksElements [ 1 ] . querySelector (
547+ ".custom-header-link-caret"
548+ ) ;
549+
550+ assert . strictEqual ( caretElement , null , `The caret wrapper is not rendered` ) ;
551+ assert . notOk (
552+ caretElement
553+ ?. querySelector ( "svg" )
554+ ?. classList . contains ( "d-icon-caret-down" ) ,
555+ `The icon is not rendered`
556+ ) ;
557+ } ) ;
558+ } ) ;
0 commit comments