Skip to content

Commit c75de94

Browse files
authored
Merge pull request DSpace#5091 from oscar-escire/Issue/3989-dspace-9_x
backport DSpace 9: Improve community list e2e tests
2 parents dcc1a9a + 4ade348 commit c75de94

2 files changed

Lines changed: 77 additions & 2 deletions

File tree

cypress/e2e/community-list.cy.ts

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

33
describe('Community List Page', () => {
44

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

833
// <ds-community-list-page> tag must be loaded
934
cy.get('ds-community-list-page').should('be.visible');
1035

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

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)