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