|
1 | 1 | import { testA11y } from 'cypress/support/utils'; |
2 | 2 |
|
3 | 3 | 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 | + } |
4 | 28 |
|
5 | | - it('should pass accessibility tests', () => { |
| 29 | + beforeEach(() => { |
6 | 30 | cy.visit('/community-list'); |
7 | 31 |
|
8 | 32 | // <ds-community-list-page> tag must be loaded |
9 | 33 | cy.get('ds-community-list-page').should('be.visible'); |
10 | 34 |
|
| 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', () => { |
11 | 85 | // Open every expand button on page, so that we can scan sub-elements as well |
12 | 86 | cy.get('[data-test="expand-button"]').click({ multiple: true }); |
13 | 87 |
|
|
0 commit comments