@@ -4,9 +4,9 @@ import '../vaadin-dashboard-layout.js';
44import '../vaadin-dashboard-section.js' ;
55import '../vaadin-dashboard-widget.js' ;
66import '@vaadin/vaadin-lumo-styles/spacing.js' ;
7- import type { DashboardLayout } from '../vaadin-dashboard-layout.js' ;
8- import type { DashboardSection } from '../vaadin-dashboard-section.js' ;
9- import type { DashboardWidget } from '../vaadin-dashboard-widget.js' ;
7+ import { DashboardLayout } from '../vaadin-dashboard-layout.js' ;
8+ import { DashboardSection } from '../vaadin-dashboard-section.js' ;
9+ import { DashboardWidget } from '../vaadin-dashboard-widget.js' ;
1010import {
1111 assertHeadingLevel ,
1212 expectLayout ,
@@ -618,25 +618,30 @@ describe('dashboard layout', () => {
618618} ) ;
619619
620620describe ( 'root heading level' , ( ) => {
621- let dashboard : DashboardLayout ;
621+ let dashboardLayout : DashboardLayout ;
622+ let newDashboardLayout : DashboardLayout ;
622623 let section : DashboardSection ;
623624 let widget : DashboardWidget ;
624625 let nestedWidget : DashboardWidget ;
625626
626627 beforeEach ( async ( ) => {
627- dashboard = fixtureSync ( `
628- <vaadin-dashboard-layout>
629- <vaadin-dashboard-widget widget-title="Widget"></vaadin-dashboard-widget>
630- <vaadin-dashboard-section section-title="Section">
631- <vaadin-dashboard-widget widget-title="Nested Widget"></vaadin-dashboard-widget>
632- </vaadin-dashboard-section>
633- </vaadin-dashboard-layout>
634- ` ) ;
628+ const container = fixtureSync ( `
629+ <div>
630+ <vaadin-dashboard-layout id="layout1">
631+ <vaadin-dashboard-widget widget-title="Widget"></vaadin-dashboard-widget>
632+ <vaadin-dashboard-section section-title="Section">
633+ <vaadin-dashboard-widget widget-title="Nested Widget"></vaadin-dashboard-widget>
634+ </vaadin-dashboard-section>
635+ </vaadin-dashboard-layout>
636+ <vaadin-dashboard-layout id="layout2" root-heading-level="3"></vaadin-dashboard-layout>
637+ </div>
638+ ` ) ;
635639 await nextFrame ( ) ;
636- await nextResize ( dashboard ) ;
637- widget = dashboard . querySelector ( 'vaadin-dashboard-widget' ) as DashboardWidget ;
638- section = dashboard . querySelector ( 'vaadin-dashboard-section' ) as DashboardSection ;
640+ dashboardLayout = container . querySelector ( '#layout1' ) as DashboardLayout ;
641+ widget = dashboardLayout . querySelector ( 'vaadin-dashboard-widget' ) as DashboardWidget ;
642+ section = dashboardLayout . querySelector ( 'vaadin-dashboard-section' ) as DashboardSection ;
639643 nestedWidget = section . querySelector ( 'vaadin-dashboard-widget' ) as DashboardWidget ;
644+ newDashboardLayout = container . querySelector ( '#layout2' ) as DashboardLayout ;
640645 } ) ;
641646
642647 function assertHeadingLevels ( expectedHeadingLevel : number ) {
@@ -650,31 +655,75 @@ describe('root heading level', () => {
650655 } ) ;
651656
652657 it ( 'should use custom title heading level when set on dashboard layout' , async ( ) => {
653- dashboard . rootHeadingLevel = 4 ;
658+ dashboardLayout . rootHeadingLevel = 4 ;
654659 await nextFrame ( ) ;
655660 assertHeadingLevels ( 4 ) ;
656661 } ) ;
657662
658663 it ( 'should revert to default title heading level (2) when set to null' , async ( ) => {
659- dashboard . rootHeadingLevel = 4 ;
664+ dashboardLayout . rootHeadingLevel = 4 ;
660665 await nextFrame ( ) ;
661- dashboard . rootHeadingLevel = null ;
666+ dashboardLayout . rootHeadingLevel = null ;
662667 await nextFrame ( ) ;
663668 assertHeadingLevels ( 2 ) ;
664669 } ) ;
665670
666671 it ( 'should update heading levels for newly added components' , async ( ) => {
667- dashboard . rootHeadingLevel = 3 ;
672+ dashboardLayout . rootHeadingLevel = 3 ;
668673 await nextFrame ( ) ;
669674 const newWidget = document . createElement ( 'vaadin-dashboard-widget' ) ;
670- dashboard . appendChild ( newWidget ) ;
675+ dashboardLayout . appendChild ( newWidget ) ;
671676 const newSection = document . createElement ( 'vaadin-dashboard-section' ) ;
672677 const nestedInNewSection = document . createElement ( 'vaadin-dashboard-widget' ) ;
673678 newSection . appendChild ( nestedInNewSection ) ;
674- dashboard . appendChild ( newSection ) ;
679+ dashboardLayout . appendChild ( newSection ) ;
675680 await nextFrame ( ) ;
676681 assertHeadingLevel ( newWidget , 3 ) ;
677682 assertHeadingLevel ( newSection , 3 ) ;
678683 assertHeadingLevel ( nestedInNewSection , 4 ) ;
679684 } ) ;
685+
686+ describe ( 'moving between parents' , ( ) => {
687+ it ( 'should update heading level when moved to another dashboard layout' , async ( ) => {
688+ newDashboardLayout . appendChild ( section ) ;
689+ await nextFrame ( ) ;
690+ assertHeadingLevel ( section , 3 ) ;
691+ assertHeadingLevel ( nestedWidget , 4 ) ;
692+ } ) ;
693+
694+ it ( 'should update heading level when a new widget is added' , async ( ) => {
695+ const newWidget = document . createElement ( 'vaadin-dashboard-widget' ) ;
696+ newWidget . widgetTitle = 'New Widget' ;
697+ section . appendChild ( newWidget ) ;
698+ await nextFrame ( ) ;
699+ assertHeadingLevel ( newWidget , 3 ) ;
700+ newDashboardLayout . appendChild ( section ) ;
701+ await nextFrame ( ) ;
702+ assertHeadingLevel ( newWidget , 4 ) ;
703+ } ) ;
704+ } ) ;
705+
706+ it ( 'should update heading level when custom elements are used' , async ( ) => {
707+ class CustomLayout extends DashboardLayout { }
708+ customElements . define ( 'custom-dashboard-layout' , CustomLayout ) ;
709+ class CustomSection extends DashboardSection { }
710+ customElements . define ( 'custom-dashboard-section' , CustomSection ) ;
711+ class CustomWidget extends DashboardWidget { }
712+ customElements . define ( 'custom-dashboard-widget' , CustomWidget ) ;
713+ const customLayout = fixtureSync ( `
714+ <custom-dashboard-layout root-heading-level="5">
715+ <custom-dashboard-widget widget-title="Custom Widget"></custom-dashboard-widget>
716+ <custom-dashboard-section section-title="Custom Section">
717+ <custom-dashboard-widget widget-title="Custom Nested Widget"></custom-dashboard-widget>
718+ </custom-dashboard-section>
719+ </custom-dashboard-layout>
720+ ` ) as CustomLayout ;
721+ await nextFrame ( ) ;
722+ const widget = customLayout . querySelector ( 'custom-dashboard-widget' ) as CustomWidget ;
723+ const section = customLayout . querySelector ( 'custom-dashboard-section' ) as CustomSection ;
724+ const nestedWidget = section . querySelector ( 'custom-dashboard-widget' ) as CustomWidget ;
725+ assertHeadingLevel ( widget , 5 ) ;
726+ assertHeadingLevel ( section , 5 ) ;
727+ assertHeadingLevel ( nestedWidget , 6 ) ;
728+ } ) ;
680729} ) ;
0 commit comments