@@ -3,9 +3,9 @@ import { fixtureSync, nextFrame, nextResize } from '@vaadin/testing-helpers';
3
3
import '../vaadin-dashboard-layout.js' ;
4
4
import '../vaadin-dashboard-section.js' ;
5
5
import '../vaadin-dashboard-widget.js' ;
6
- import type { DashboardLayout } from '../vaadin-dashboard-layout.js' ;
7
- import type { DashboardSection } from '../vaadin-dashboard-section.js' ;
8
- import type { DashboardWidget } from '../vaadin-dashboard-widget.js' ;
6
+ import { DashboardLayout } from '../vaadin-dashboard-layout.js' ;
7
+ import { DashboardSection } from '../vaadin-dashboard-section.js' ;
8
+ import { DashboardWidget } from '../vaadin-dashboard-widget.js' ;
9
9
import {
10
10
assertHeadingLevel ,
11
11
expectLayout ,
@@ -621,25 +621,30 @@ describe('dashboard layout', () => {
621
621
} ) ;
622
622
623
623
describe ( 'root heading level' , ( ) => {
624
- let dashboard : DashboardLayout ;
624
+ let dashboardLayout : DashboardLayout ;
625
+ let newDashboardLayout : DashboardLayout ;
625
626
let section : DashboardSection ;
626
627
let widget : DashboardWidget ;
627
628
let nestedWidget : DashboardWidget ;
628
629
629
630
beforeEach ( async ( ) => {
630
- dashboard = fixtureSync ( `
631
- <vaadin-dashboard-layout>
632
- <vaadin-dashboard-widget widget-title="Widget"></vaadin-dashboard-widget>
633
- <vaadin-dashboard-section section-title="Section">
634
- <vaadin-dashboard-widget widget-title="Nested Widget"></vaadin-dashboard-widget>
635
- </vaadin-dashboard-section>
636
- </vaadin-dashboard-layout>
637
- ` ) ;
631
+ const container = fixtureSync ( `
632
+ <div>
633
+ <vaadin-dashboard-layout id="layout1">
634
+ <vaadin-dashboard-widget widget-title="Widget"></vaadin-dashboard-widget>
635
+ <vaadin-dashboard-section section-title="Section">
636
+ <vaadin-dashboard-widget widget-title="Nested Widget"></vaadin-dashboard-widget>
637
+ </vaadin-dashboard-section>
638
+ </vaadin-dashboard-layout>
639
+ <vaadin-dashboard-layout id="layout2" root-heading-level="3"></vaadin-dashboard-layout>
640
+ </div>
641
+ ` ) ;
638
642
await nextFrame ( ) ;
639
- await nextResize ( dashboard ) ;
640
- widget = dashboard . querySelector ( 'vaadin-dashboard-widget' ) as DashboardWidget ;
641
- section = dashboard . querySelector ( 'vaadin-dashboard-section' ) as DashboardSection ;
643
+ dashboardLayout = container . querySelector ( '#layout1' ) as DashboardLayout ;
644
+ widget = dashboardLayout . querySelector ( 'vaadin-dashboard-widget' ) as DashboardWidget ;
645
+ section = dashboardLayout . querySelector ( 'vaadin-dashboard-section' ) as DashboardSection ;
642
646
nestedWidget = section . querySelector ( 'vaadin-dashboard-widget' ) as DashboardWidget ;
647
+ newDashboardLayout = container . querySelector ( '#layout2' ) as DashboardLayout ;
643
648
} ) ;
644
649
645
650
function assertHeadingLevels ( expectedHeadingLevel : number ) {
@@ -653,31 +658,75 @@ describe('root heading level', () => {
653
658
} ) ;
654
659
655
660
it ( 'should use custom title heading level when set on dashboard layout' , async ( ) => {
656
- dashboard . rootHeadingLevel = 4 ;
661
+ dashboardLayout . rootHeadingLevel = 4 ;
657
662
await nextFrame ( ) ;
658
663
assertHeadingLevels ( 4 ) ;
659
664
} ) ;
660
665
661
666
it ( 'should revert to default title heading level (2) when set to null' , async ( ) => {
662
- dashboard . rootHeadingLevel = 4 ;
667
+ dashboardLayout . rootHeadingLevel = 4 ;
663
668
await nextFrame ( ) ;
664
- dashboard . rootHeadingLevel = null ;
669
+ dashboardLayout . rootHeadingLevel = null ;
665
670
await nextFrame ( ) ;
666
671
assertHeadingLevels ( 2 ) ;
667
672
} ) ;
668
673
669
674
it ( 'should update heading levels for newly added components' , async ( ) => {
670
- dashboard . rootHeadingLevel = 3 ;
675
+ dashboardLayout . rootHeadingLevel = 3 ;
671
676
await nextFrame ( ) ;
672
677
const newWidget = document . createElement ( 'vaadin-dashboard-widget' ) ;
673
- dashboard . appendChild ( newWidget ) ;
678
+ dashboardLayout . appendChild ( newWidget ) ;
674
679
const newSection = document . createElement ( 'vaadin-dashboard-section' ) ;
675
680
const nestedInNewSection = document . createElement ( 'vaadin-dashboard-widget' ) ;
676
681
newSection . appendChild ( nestedInNewSection ) ;
677
- dashboard . appendChild ( newSection ) ;
682
+ dashboardLayout . appendChild ( newSection ) ;
678
683
await nextFrame ( ) ;
679
684
assertHeadingLevel ( newWidget , 3 ) ;
680
685
assertHeadingLevel ( newSection , 3 ) ;
681
686
assertHeadingLevel ( nestedInNewSection , 4 ) ;
682
687
} ) ;
688
+
689
+ describe ( 'moving between parents' , ( ) => {
690
+ it ( 'should update heading level when moved to another dashboard layout' , async ( ) => {
691
+ newDashboardLayout . appendChild ( section ) ;
692
+ await nextFrame ( ) ;
693
+ assertHeadingLevel ( section , 3 ) ;
694
+ assertHeadingLevel ( nestedWidget , 4 ) ;
695
+ } ) ;
696
+
697
+ it ( 'should update heading level when a new widget is added' , async ( ) => {
698
+ const newWidget = document . createElement ( 'vaadin-dashboard-widget' ) ;
699
+ newWidget . widgetTitle = 'New Widget' ;
700
+ section . appendChild ( newWidget ) ;
701
+ await nextFrame ( ) ;
702
+ assertHeadingLevel ( newWidget , 3 ) ;
703
+ newDashboardLayout . appendChild ( section ) ;
704
+ await nextFrame ( ) ;
705
+ assertHeadingLevel ( newWidget , 4 ) ;
706
+ } ) ;
707
+ } ) ;
708
+
709
+ it ( 'should update heading level when custom elements are used' , async ( ) => {
710
+ class CustomLayout extends DashboardLayout { }
711
+ customElements . define ( 'custom-dashboard-layout' , CustomLayout ) ;
712
+ class CustomSection extends DashboardSection { }
713
+ customElements . define ( 'custom-dashboard-section' , CustomSection ) ;
714
+ class CustomWidget extends DashboardWidget { }
715
+ customElements . define ( 'custom-dashboard-widget' , CustomWidget ) ;
716
+ const customLayout = fixtureSync ( `
717
+ <custom-dashboard-layout root-heading-level="5">
718
+ <custom-dashboard-widget widget-title="Custom Widget"></custom-dashboard-widget>
719
+ <custom-dashboard-section section-title="Custom Section">
720
+ <custom-dashboard-widget widget-title="Custom Nested Widget"></custom-dashboard-widget>
721
+ </custom-dashboard-section>
722
+ </custom-dashboard-layout>
723
+ ` ) as CustomLayout ;
724
+ await nextFrame ( ) ;
725
+ const widget = customLayout . querySelector ( 'custom-dashboard-widget' ) as CustomWidget ;
726
+ const section = customLayout . querySelector ( 'custom-dashboard-section' ) as CustomSection ;
727
+ const nestedWidget = section . querySelector ( 'custom-dashboard-widget' ) as CustomWidget ;
728
+ assertHeadingLevel ( widget , 5 ) ;
729
+ assertHeadingLevel ( section , 5 ) ;
730
+ assertHeadingLevel ( nestedWidget , 6 ) ;
731
+ } ) ;
683
732
} ) ;
0 commit comments