Skip to content

Commit 1fa4b9f

Browse files
committed
fixing failing test
1 parent c46b88e commit 1fa4b9f

File tree

3 files changed

+17
-10
lines changed
  • packages/components/src/components/hds/advanced-table/models
  • showcase/tests/integration/components/hds/advanced-table

3 files changed

+17
-10
lines changed

packages/components/src/components/hds/advanced-table/models/row.ts

-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ export default class HdsAdvancedTableRow {
2727
return this.isOpen && this.hasChildren;
2828
}
2929

30-
get allDescendantsAreOpen(): boolean {
31-
return this.children.every(
32-
(child) => child.isOpen && child.allDescendantsAreOpen
33-
);
34-
}
35-
3630
constructor(args: HdsAdvancedTableRowArgs) {
3731
// set row data
3832
Object.assign(this, args);

packages/components/src/components/hds/advanced-table/models/table.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ export default class HdsAdvancedTableTableModel {
3434
});
3535
}
3636

37+
get totalRowCount(): number {
38+
function getChildrenCount(rows: HdsAdvancedTableRow[]): number {
39+
return rows.reduce((acc, row) => {
40+
return acc + 1 + getChildrenCount(row.children);
41+
}, 0);
42+
}
43+
44+
return this.rows.reduce((acc, row) => {
45+
return acc + 1 + getChildrenCount(row.children);
46+
}, 0);
47+
}
48+
3749
get flattenedVisibleRows(): HdsAdvancedTableRow[] {
3850
return getVisibleRows(this.rows);
3951
}
@@ -46,12 +58,12 @@ export default class HdsAdvancedTableTableModel {
4658
return this.rows.some((row) => row.hasChildren);
4759
}
4860

49-
get allDescendantsAreOpen(): boolean {
50-
return this.rows.every((row) => row.isOpen && row.allDescendantsAreOpen);
61+
get allRowsAreOpen(): boolean {
62+
return this.flattenedVisibleRows.length === this.totalRowCount;
5163
}
5264

5365
get expandState(): HdsAdvancedTableExpandState {
54-
if (this.allDescendantsAreOpen) {
66+
if (this.allRowsAreOpen) {
5567
return true;
5668
} else if (this.rows.some((row) => row.isOpen)) {
5769
return 'mixed';
@@ -72,7 +84,7 @@ export default class HdsAdvancedTableTableModel {
7284

7385
@action
7486
toggleAll() {
75-
if (this.allDescendantsAreOpen) {
87+
if (this.allRowsAreOpen) {
7688
this.collapseAll();
7789
} else {
7890
this.openAll();

showcase/tests/integration/components/hds/advanced-table/index-test.js

+1
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,7 @@ module('Integration | Component | hds/advanced-table/index', function (hooks) {
10601060

10611061
for (let i = 0; i < rowToggles.length; i++) {
10621062
await click(rowToggles[i]);
1063+
10631064
if (i < rowToggles.length - 1) {
10641065
assert.dom(expandAllButton).hasAria('expanded', 'mixed');
10651066
}

0 commit comments

Comments
 (0)