Skip to content

Commit 5362f99

Browse files
devversionannieyw
authored andcommitted
refactor(material/list): retrieve subheader texts in test harness concurrently
Currently the test harness for the list provides a method for retrieving list items grouped by subheaders. The subheaders with their corresponding list items are iteratively collected but the headings are retrieved once previous headings have been retrieved/awaited. We can improve this by retrieving the headings concurrently and waiting for all asynchronous tasks to complete at the end.
1 parent 3654a63 commit 5362f99

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/material/list/testing/list-harness-base.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ export class MatListHarnessBase
5656
*/
5757
async getItemsGroupedBySubheader(filters?: F): Promise<ListSection<C>[]> {
5858
const listSections = [];
59-
let currentSection: ListSection<C> = {items: []};
59+
let currentSection: {items: C[], heading?: Promise<string>} = {items: []};
6060
const itemsAndSubheaders =
6161
await this.getItemsWithSubheadersAndDividers({item: filters, divider: false});
6262
for (const itemOrSubheader of itemsAndSubheaders) {
6363
if (itemOrSubheader instanceof MatSubheaderHarness) {
6464
if (currentSection.heading !== undefined || currentSection.items.length) {
6565
listSections.push(currentSection);
6666
}
67-
currentSection = {heading: await itemOrSubheader.getText(), items: []};
67+
currentSection = {heading: itemOrSubheader.getText(), items: []};
6868
} else {
6969
currentSection.items.push(itemOrSubheader);
7070
}
@@ -73,7 +73,10 @@ export class MatListHarnessBase
7373
!listSections.length) {
7474
listSections.push(currentSection);
7575
}
76-
return listSections;
76+
77+
// Concurrently wait for all sections to resolve their heading if present.
78+
return Promise.all(listSections.map(async (s) =>
79+
({items: s.items, heading: await s.heading})));
7780
}
7881

7982
/**

0 commit comments

Comments
 (0)