@@ -4,9 +4,9 @@ import '../vaadin-dashboard-layout.js';
4
4
import '../vaadin-dashboard-section.js' ;
5
5
import '../vaadin-dashboard-widget.js' ;
6
6
import '@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' ;
10
10
import {
11
11
assertHeadingLevel ,
12
12
expectLayout ,
@@ -618,25 +618,30 @@ describe('dashboard layout', () => {
618
618
} ) ;
619
619
620
620
describe ( 'root heading level' , ( ) => {
621
- let dashboard : DashboardLayout ;
621
+ let dashboardLayout : DashboardLayout ;
622
+ let newDashboardLayout : DashboardLayout ;
622
623
let section : DashboardSection ;
623
624
let widget : DashboardWidget ;
624
625
let nestedWidget : DashboardWidget ;
625
626
626
627
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
+ ` ) ;
635
639
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 ;
639
643
nestedWidget = section . querySelector ( 'vaadin-dashboard-widget' ) as DashboardWidget ;
644
+ newDashboardLayout = container . querySelector ( '#layout2' ) as DashboardLayout ;
640
645
} ) ;
641
646
642
647
function assertHeadingLevels ( expectedHeadingLevel : number ) {
@@ -650,31 +655,75 @@ describe('root heading level', () => {
650
655
} ) ;
651
656
652
657
it ( 'should use custom title heading level when set on dashboard layout' , async ( ) => {
653
- dashboard . rootHeadingLevel = 4 ;
658
+ dashboardLayout . rootHeadingLevel = 4 ;
654
659
await nextFrame ( ) ;
655
660
assertHeadingLevels ( 4 ) ;
656
661
} ) ;
657
662
658
663
it ( 'should revert to default title heading level (2) when set to null' , async ( ) => {
659
- dashboard . rootHeadingLevel = 4 ;
664
+ dashboardLayout . rootHeadingLevel = 4 ;
660
665
await nextFrame ( ) ;
661
- dashboard . rootHeadingLevel = null ;
666
+ dashboardLayout . rootHeadingLevel = null ;
662
667
await nextFrame ( ) ;
663
668
assertHeadingLevels ( 2 ) ;
664
669
} ) ;
665
670
666
671
it ( 'should update heading levels for newly added components' , async ( ) => {
667
- dashboard . rootHeadingLevel = 3 ;
672
+ dashboardLayout . rootHeadingLevel = 3 ;
668
673
await nextFrame ( ) ;
669
674
const newWidget = document . createElement ( 'vaadin-dashboard-widget' ) ;
670
- dashboard . appendChild ( newWidget ) ;
675
+ dashboardLayout . appendChild ( newWidget ) ;
671
676
const newSection = document . createElement ( 'vaadin-dashboard-section' ) ;
672
677
const nestedInNewSection = document . createElement ( 'vaadin-dashboard-widget' ) ;
673
678
newSection . appendChild ( nestedInNewSection ) ;
674
- dashboard . appendChild ( newSection ) ;
679
+ dashboardLayout . appendChild ( newSection ) ;
675
680
await nextFrame ( ) ;
676
681
assertHeadingLevel ( newWidget , 3 ) ;
677
682
assertHeadingLevel ( newSection , 3 ) ;
678
683
assertHeadingLevel ( nestedInNewSection , 4 ) ;
679
684
} ) ;
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
+ } ) ;
680
729
} ) ;
0 commit comments