diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb index eae51b5af..dcac944ac 100644 --- a/app/views/admin/users/index.html.erb +++ b/app/views/admin/users/index.html.erb @@ -100,6 +100,13 @@ <% end %> + + <% if @users.empty? %> +
+

No members found under these filters.

+

Try broadening or removing the filters.

+
+ <% end %>
diff --git a/cypress/integration/seededFlows/adminFlows/users/userIndexView.spec.js b/cypress/integration/seededFlows/adminFlows/users/userIndexView.spec.js index c668d6726..f7c901dd6 100644 --- a/cypress/integration/seededFlows/adminFlows/users/userIndexView.spec.js +++ b/cypress/integration/seededFlows/adminFlows/users/userIndexView.spec.js @@ -170,6 +170,43 @@ describe('User index view', () => { .should('equal', 'admin@forem.local'); }); }); + + describe('Empty state', () => { + // Search and filter controls are initialized async. + // This helper function allows us to use `pipe` to retry commands in case the test runner clicks before the JS has run + const click = (el) => el.click(); + + it('Displays an empty state when no results are returned when searching for a user', () => { + cy.findByRole('button', { name: 'Expand search' }) + .should('have.attr', 'aria-expanded', 'false') + .pipe(click) + .should('have.attr', 'aria-expanded', 'true'); + + cy.findByRole('textbox', { + name: 'Search member by name, username or email', + }).type('Not a member'); + + cy.findByRole('button', { name: 'Search' }).click(); + + // Since there aren't any results, the following message should be displayed + cy.findByText('No members found under these filters.').should('exist'); + }); + + it('Displays an empty state when no results are returned when filtering for a user', () => { + cy.findByRole('button', { name: 'Expand filter' }) + .should('have.attr', 'aria-expanded', 'false') + .pipe(click) + .should('have.attr', 'aria-expanded', 'true'); + + cy.findByRole('combobox', { name: 'User role' }).select( + 'codeland_admin', + ); + cy.findByRole('button', { name: 'Filter' }).click(); + + // Since there aren't any results, the following message should be displayed + cy.findByText('No members found under these filters.').should('exist'); + }); + }); }); describe('large screens', () => { @@ -233,6 +270,29 @@ describe('User index view', () => { }); }); + describe('Empty state', () => { + it('Displays an empty state when no results are returned when searching for a user', () => { + cy.findByRole('textbox', { + name: 'Search member by name, username or email', + }).type('Not a member'); + + cy.findByRole('button', { name: 'Search' }).click(); + + // Since there aren't any results, the following message should be displayed + cy.findByText('No members found under these filters.').should('exist'); + }); + + it('Displays an empty state when no results are returned when filtering for a user', () => { + cy.findByRole('combobox', { name: 'User role' }).select( + 'codeland_admin', + ); + cy.findByRole('button', { name: 'Filter' }).click(); + + // Since there aren't any results, the following message should be displayed + cy.findByText('No members found under these filters.').should('exist'); + }); + }); + describe('User actions', () => { it('Copies user email to clipboard', () => { // Helper function for cypress-pipe