Skip to content

Commit

Permalink
Allow immediate setting of filter by pressing enter
Browse files Browse the repository at this point in the history
This is potentially useful for the user, but also especially for the
Cypress tests so we don't need to wait for the debounce.

Also tell Cypress to explicitly wait for the loading state of the table
to be gone. Because now use an inline loading state as opposed to
ember's route based loading system, Cypress was trying to click on the
table rows too quickly, before the actual results had rendered, which
caused the tests to fail.
  • Loading branch information
sergiofenoll committed Apr 16, 2022
1 parent 04d1484 commit 7794afa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions app/pods/agendas/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ export default class AgendasController extends Controller {
dateRegex = /^(?:\d{1,2}\/)??(?:\d{1,2}\/)?\d{4}$/;

@restartableTask
*setFilter(event) {
*debouncedSetFilter(event) {
yield timeout(500);
const date = event.target.value;
this.setFilter(event.target.value);
}

@action
setFilter(date) {
if (this.dateRegex.test(date)) {
this.filter = date;
} else if (date === '') {
Expand Down
8 changes: 6 additions & 2 deletions app/pods/agendas/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
@icon="search"
placeholder="bv. 01/2021"
value={{this.filter}}
{{on "input" (perform this.setFilter)}}
{{on "input" (perform this.debouncedSetFilter)}}
@enter={{this.setFilter}}
autocomplete="off"
/>
</Group.Item>
Expand Down Expand Up @@ -95,7 +96,10 @@
<tbody>
{{#if this.isLoadingModel}}
<tr>
<td colspan="5">
<td
data-test-route-agendas-overview-loader
colspan="5"
>
{{t "loading"}}
</td>
</tr>
Expand Down
1 change: 1 addition & 0 deletions cypress/selectors/route.selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const selectors = {
// agendas/overview/template.hbs
agendasOverview: {
dataTable: '[data-test-route-agendas-overview-data-table]',
loader: '[data-test-route-agendas-overview-loader]',
row: {
title: '[data-test-route-agendas-overview-row-title]',
kind: '[data-test-route-agendas-overview-row-kind]',
Expand Down
5 changes: 4 additions & 1 deletion cypress/support/commands/agenda-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,11 @@ function openAgendaForDate(agendaDate, index = 0) {

cy.visit('');
cy.get(route.agendasOverview.filter.container).within(() => {
cy.get(route.agendasOverview.filter.input).type(searchDate);
cy.get(route.agendasOverview.filter.input).type(`${searchDate}{enter}`);
});
cy.get(route.agendasOverview.loader, {
timeout: 5000,
}).should('not.exist');
cy.wait('@getFilteredAgendas', {
timeout: 20000,
});
Expand Down

0 comments on commit 7794afa

Please sign in to comment.