Skip to content

Commit f807f5a

Browse files
authored
Merge pull request #4291 from oscar-escire/Issue/3989
Improve community list e2e tests
2 parents 417f835 + 492023c commit f807f5a

File tree

2 files changed

+76
-2
lines changed

2 files changed

+76
-2
lines changed

cypress/e2e/community-list.cy.ts

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,87 @@
11
import { testA11y } from 'cypress/support/utils';
22

33
describe('Community List Page', () => {
4+
function validateHierarchyLevel(currentLevel = 1): void {
5+
// Find all <cdk-tree-node> elements with the current aria-level
6+
cy.get(`ds-community-list cdk-tree-node.expandable-node[aria-level="${currentLevel}"]`).should('exist').then(($nodes) => {
7+
let sublevelExists = false;
8+
cy.wrap($nodes).each(($node) => {
9+
// Check if the current node has an expand button and click it
10+
if ($node.find('[data-test="expand-button"]').length) {
11+
sublevelExists = true;
12+
cy.wrap($node).find('[data-test="expand-button"]').click();
13+
}
14+
}).then(() => {
15+
// After expanding all buttons, validate if a sublevel exists
16+
if (sublevelExists) {
17+
const nextLevelSelector = `ds-community-list cdk-tree-node.expandable-node[aria-level="${currentLevel + 1}"]`;
18+
cy.get(nextLevelSelector).then(($nextLevel) => {
19+
if ($nextLevel.length) {
20+
// Recursively validate the next level
21+
validateHierarchyLevel(currentLevel + 1);
22+
}
23+
});
24+
}
25+
});
26+
});
27+
}
428

5-
it('should pass accessibility tests', () => {
29+
beforeEach(() => {
630
cy.visit('/community-list');
731

832
// <ds-community-list-page> tag must be loaded
933
cy.get('ds-community-list-page').should('be.visible');
1034

35+
// <ds-community-list-list> tag must be loaded
36+
cy.get('ds-community-list').should('be.visible');
37+
});
38+
39+
it('should expand community/collection hierarchy', () => {
40+
// Execute Hierarchy levels validation recursively
41+
validateHierarchyLevel(1);
42+
});
43+
44+
it('should display community/collections name with item count', () => {
45+
// Open every <cdk-tree-node>
46+
cy.get('[data-test="expand-button"]').click({ multiple: true });
47+
cy.wait(300);
48+
49+
// A first <cdk-tree-node> must be found and validate that <a> tag (community name) and <span> tag (item count) exists in it
50+
cy.get('ds-community-list').find('cdk-tree-node.expandable-node').then(($nodes) => {
51+
cy.wrap($nodes).each(($node) => {
52+
cy.wrap($node).find('a').should('exist');
53+
cy.wrap($node).find('span').should('exist');
54+
});
55+
});
56+
});
57+
58+
it('should enable "show more" button when 20 top-communities or more are presents', () => {
59+
cy.get('ds-community-list').find('cdk-tree-node.expandable-node[aria-level="1"]').then(($nodes) => {
60+
//Validate that there are 20 or more top-community elements
61+
if ($nodes.length >= 20) {
62+
//Validate that "show more" button is visible and then click on it
63+
cy.get('[data-test="show-more-button"]').should('be.visible');
64+
} else {
65+
cy.get('[data-test="show-more-button"]').should('not.exist');
66+
}
67+
});
68+
});
69+
70+
it('should show 21 or more top-communities if click "show more" button', () => {
71+
cy.get('ds-community-list').find('cdk-tree-node.expandable-node[aria-level="1"]').then(($nodes) => {
72+
//Validate that there are 20 or more top-community elements
73+
if ($nodes.length >= 20) {
74+
//Validate that "show more" button is visible and then click on it
75+
cy.get('[data-test="show-more-button"]').click();
76+
cy.wait(300);
77+
cy.get('ds-community-list').find('cdk-tree-node.expandable-node[aria-level="1"]').should('have.length.at.least', 21);
78+
} else {
79+
cy.get('[data-test="show-more-button"]').should('not.exist');
80+
}
81+
});
82+
});
83+
84+
it('should pass accessibility tests', () => {
1185
// Open every expand button on page, so that we can scan sub-elements as well
1286
cy.get('[data-test="expand-button"]').click({ multiple: true });
1387

src/app/community-list-page/community-list/community-list.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<div class="align-middle my-auto">
1313
@if ((dataSource.loading$ | async) !== true) {
1414
<button (click)="getNextPage(node)"
15-
class="btn btn-outline-primary btn-sm" role="button" tabindex="0">
15+
class="btn btn-outline-primary btn-sm" role="button" tabindex="0" data-test="show-more-button">
1616
<i class="fas fa-angle-down"></i> {{ 'communityList.showMore' | translate }}
1717
</button>
1818
}

0 commit comments

Comments
 (0)