@@ -2,10 +2,13 @@ import { expect } from '@vaadin/chai-plugins';
2
2
import { fixtureSync , nextFrame , nextResize } from '@vaadin/testing-helpers' ;
3
3
import '../vaadin-dashboard-layout.js' ;
4
4
import '../vaadin-dashboard-section.js' ;
5
+ import '../vaadin-dashboard-widget.js' ;
5
6
import '@vaadin/vaadin-lumo-styles/spacing.js' ;
6
7
import type { DashboardLayout } from '../vaadin-dashboard-layout.js' ;
7
8
import type { DashboardSection } from '../vaadin-dashboard-section.js' ;
9
+ import type { DashboardWidget } from '../vaadin-dashboard-widget.js' ;
8
10
import {
11
+ assertHeadingLevel ,
9
12
expectLayout ,
10
13
getColumnWidths ,
11
14
getRowHeights ,
@@ -613,3 +616,73 @@ describe('dashboard layout', () => {
613
616
} ) ;
614
617
} ) ;
615
618
} ) ;
619
+
620
+ describe ( 'root heading level' , ( ) => {
621
+ let dashboard : DashboardLayout ;
622
+ let section : DashboardSection ;
623
+ let widget : DashboardWidget ;
624
+ let nestedWidget : DashboardWidget ;
625
+
626
+ 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
+ ` ) ;
635
+ await nextFrame ( ) ;
636
+ await nextResize ( dashboard ) ;
637
+ widget = dashboard . querySelector ( 'vaadin-dashboard-widget' ) as DashboardWidget ;
638
+ section = dashboard . querySelector ( 'vaadin-dashboard-section' ) as DashboardSection ;
639
+ nestedWidget = section . querySelector ( 'vaadin-dashboard-widget' ) as DashboardWidget ;
640
+ } ) ;
641
+
642
+ function assertHeadingLevels ( expectedHeadingLevel : number ) {
643
+ assertHeadingLevel ( widget , expectedHeadingLevel ) ;
644
+ assertHeadingLevel ( section , expectedHeadingLevel ) ;
645
+ assertHeadingLevel ( nestedWidget , expectedHeadingLevel + 1 ) ;
646
+ }
647
+
648
+ it ( 'should use default title heading level (2) when not explicitly set' , ( ) => {
649
+ assertHeadingLevels ( 2 ) ;
650
+ } ) ;
651
+
652
+ it ( 'should use custom title heading level when set on dashboard layout' , async ( ) => {
653
+ dashboard . rootHeadingLevel = 4 ;
654
+ await nextFrame ( ) ;
655
+ assertHeadingLevels ( 4 ) ;
656
+ } ) ;
657
+
658
+ it ( 'should update title heading level when changed on dashboard layout' , async ( ) => {
659
+ dashboard . rootHeadingLevel = 3 ;
660
+ await nextFrame ( ) ;
661
+ dashboard . rootHeadingLevel = 1 ;
662
+ await nextFrame ( ) ;
663
+ assertHeadingLevels ( 1 ) ;
664
+ } ) ;
665
+
666
+ it ( 'should revert to default title heading level (2) when set to null' , async ( ) => {
667
+ dashboard . rootHeadingLevel = 4 ;
668
+ await nextFrame ( ) ;
669
+ dashboard . rootHeadingLevel = null ;
670
+ await nextFrame ( ) ;
671
+ assertHeadingLevels ( 2 ) ;
672
+ } ) ;
673
+
674
+ it ( 'should update heading levels for newly added components' , async ( ) => {
675
+ dashboard . rootHeadingLevel = 3 ;
676
+ await nextFrame ( ) ;
677
+ const newWidget = document . createElement ( 'vaadin-dashboard-widget' ) ;
678
+ dashboard . appendChild ( newWidget ) ;
679
+ const newSection = document . createElement ( 'vaadin-dashboard-section' ) ;
680
+ const nestedInNewSection = document . createElement ( 'vaadin-dashboard-widget' ) ;
681
+ newSection . appendChild ( nestedInNewSection ) ;
682
+ dashboard . appendChild ( newSection ) ;
683
+ await nextFrame ( ) ;
684
+ assertHeadingLevel ( newWidget , 3 ) ;
685
+ assertHeadingLevel ( newSection , 3 ) ;
686
+ assertHeadingLevel ( nestedInNewSection , 4 ) ;
687
+ } ) ;
688
+ } ) ;
0 commit comments