Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/update-tests-to-new-archetype #147

Merged
merged 4 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"cy:run": "cypress run --headless --browser chrome",
"test:e2e": "start-server-and-test build:serve http://localhost:8080 cy:open",
"test:e2e:ci": "start-server-and-test serve:dist http://localhost:8080 cy:run",
"test": "echo everything is on fire, and this is fine",
"test": "npm run test:e2e:ci",
"test:unit": "vue-cli-service test:unit",
"lint": "eslint src tests build --ext .ts,.tsx,.vue,.js,.jsx",
"lint:fix": "npm run lint -- --fix",
Expand Down
6 changes: 4 additions & 2 deletions src/components/desktop/desktop-toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
data-test="total-results"
>
<span
v-html="$t('totalResults.message', { totalResults: $x.totalResults, query: $x.query.search })"
v-html="
$t('totalResults.message', { totalResults: $x.totalResults, query: $x.query.searchBox })
"
class="x-list__item--expand x-font-size--05"
/>

<ColumnPicker />
<ColumnPicker data-test="column-picker" />

<BaseIdModalOpen
modalId="right-aside"
Expand Down
4 changes: 2 additions & 2 deletions src/components/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
:class="{ 'x-margin--left-05 x-margin--right-05': $x.device === 'mobile' }"
>
<template>
<SpellcheckMessage />
<NoResultsMessage />
<SpellcheckMessage data-test="spellcheck-message" />
<NoResultsMessage data-test="no-results-message" />
</template>
</div>

Expand Down
1 change: 1 addition & 0 deletions src/components/search/facets/selected-filters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<ClearFilters
v-if="$x.device === 'desktop'"
v-slot="{ selectedFilters }"
data-test="clear-filters-toolbar"
class="
x-button--secondary x-button--round
x-padding--05 x-padding--top-03 x-padding--bottom-03
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/messages/en.messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"sort": {
"label": "Sort by",
"values": {
"price asc": "Price: Low to high",
"price asc": "Price: Low to High",
"price desc": "Price: High to Low",
"default": "Relevancy"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/cucumber/column-picker.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Feature: Column picker component
And grid shows <columns> results per row
Examples:
| query | columns | view |
| shirt | 6 | macbook-13 |
| shirt | 2 | macbook-13 |
8 changes: 2 additions & 6 deletions tests/e2e/cucumber/column-picker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ Then('grid shows {int} results per row', (columns: number) => {
});

When('value {int} from column picker list is clicked', (columns: number) => {
cy.getByDataTest('column-picker-list')
.children(`.x-column-picker-list__item--${columns}-cols`)
.should('be.visible')
.click();
cy.get(`.x-column-picker-list__item--${columns}-cols`).click({ scrollBehavior: false });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're not using the .getByDataTest('column-picker-list') here then change the test below to use the same formula as this one.

});

Then('column picker list value {int} is selected', (columns: number) => {
cy.getByDataTest('column-picker-list')
.children(`.x-column-picker-list__item--${columns}-cols`)
cy.get(`.x-column-picker-list__item--${columns}-cols`)
.children()
.should('have.attr', 'aria-selected', 'true');
});
32 changes: 27 additions & 5 deletions tests/e2e/cucumber/common-steps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ Given('start page with {string} size view', (view: ViewportPreset) => {
cy.visit('/');
});

Given('start page with {string} size view and mocked adapter', (view: ViewportPreset) => {
cy.viewport(view);
cy.visit('/useMockedAdapter=true');
});

Then('start button is clicked', () => {
cy.getByDataTest('x').should('exist');
cy.getByDataTest('start-button').click();
});

// Search
When('a {string} is typed', (query: string) => {
cy.typeQuery(query).then(() => {
cy.getByDataTest('search-input').invoke('val').as('searchedQuery');
Expand All @@ -28,6 +24,7 @@ When('{string} is searched', (query: string) => {
});
});

// Facets
When('facets are shown if hidden on {string}', (view: ViewportPreset) => {
if (!view.includes('macbook')) {
cy.getByDataTest('open-modal-id').click();
Expand All @@ -40,6 +37,31 @@ When('facets are hidden if shown on {string}', (view: ViewportPreset) => {
}
});

// Requests
Then('search request contains the origin {string} in the URL', (origin: string) => {
cy.wait('@interceptedResults').its('request.url').should('contain', `origin=${origin}`);
});

// Results
Then('related results are displayed', () => {
cy.getByDataTest('search-grid-result').first().scrollIntoView();
cy.getByDataTest('search-grid-result')
.should('be.visible')
.should('have.length.at.least', 1)
.invoke('text')
.as('resultsList');
});

Then('related results have changed', () => {
cy.getByDataTest('search-grid-result').first().scrollIntoView();
cy.get<string>('@resultsList').then(resultsList => {
cy.getByDataTest('search-grid-result')
.should('be.visible')
.should('have.length.at.least', 1)
.should(newResultsList => {
expect(newResultsList.text()).to.be.not.equal(resultsList);
})
.invoke('text')
.as('resultsList');
});
});
41 changes: 24 additions & 17 deletions tests/e2e/cucumber/facets.feature
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
Feature: Facets component

Scenario Outline: 1. Facets can be shown / hidden
Scenario Outline: 1. Facets modal can be shown / hidden
Given start page with "<view>" size view
When start button is clicked
And "<query>" is searched
Then facets are displayed is <areFacetsVisible>
When hide-show filters button is clicked on "<view>" after facets being displayed is <areFacetsVisible>
Then facets are displayed is <areFacetsVisibleAfterClick>
When hide-show filters button is clicked on "<view>" after facets being displayed is <areFacetsVisibleAfterClick>
Then facets are displayed is <areFacetsVisible>
Then related results are displayed
And facets are displayed is false
When sort and filter button is clicked on "<view>"
Then facets are displayed is true
When "<closeMethod>" is clicked to close the modal
Then facets are displayed is false
Examples:
| query | areFacetsVisible | areFacetsVisibleAfterClick | view |
| shirt | true | false | macbook-13 |
| shirt | false | true | iphone-7 |
| query | view | closeMethod |
| shirt | macbook-13 | close-modal-id |
| shirt | macbook-13 | modal-overlay |
| shirt | iphone-7 | close-modal-id |
| shirt | iphone-7 | modal-overlay |

Scenario Outline: 2. Filters can be selected and deselected / cleared
Given start page with "<view>" size view
When start button is clicked
And "<query>" is searched
And facets are shown if hidden on "<view>"
And facet "<facetName>" is unfolded
And sort and filter button is clicked on "<view>"
Then facets are displayed is true
When facet "<facetName>" is unfolded
And filter <filterNumber> from facet "<facetName>" is clicked
Then filter <filterNumber> from facet "<facetName>" is selected is true
When filter <filterNumber> from facet "<facetName>" is clicked
Expand All @@ -36,8 +40,9 @@ Feature: Facets component
Given start page with "<view>" size view
When start button is clicked
And "<query>" is searched
And facets are shown if hidden on "<view>"
And facet "<facetName>" is unfolded
And sort and filter button is clicked on "<view>"
Then facets are displayed is true
When facet "<facetName>" is unfolded
And filter <filterNumber> from facet "<facetName>" is clicked
Then filter <filterNumber> from facet "<facetName>" is selected is true
When filter <filterNumber2> from facet "<facetName>" is clicked
Expand All @@ -52,8 +57,9 @@ Feature: Facets component
Given start page with "<view>" size view
When start button is clicked
And "<query>" is searched
And facets are shown if hidden on "<view>"
And facet "<facetName>" is unfolded
And sort and filter button is clicked on "<view>"
Then facets are displayed is true
When facet "<facetName>" is unfolded
And filter <filterNumber> from facet "<facetName>" is clicked
Then filter <filterNumber> from facet "<facetName>" is selected is true
When facet "<facetName2>" is unfolded
Expand All @@ -70,8 +76,9 @@ Feature: Facets component
Given start page with "<view>" size view
When start button is clicked
And "<query>" is searched
And facets are shown if hidden on "<view>"
And facet "<facetName>" is unfolded
And sort and filter button is clicked on "<view>"
Then facets are displayed is true
When facet "<facetName>" is unfolded
And filter <hierarchicalFilter> from facet "<facetName>" is clicked
Then selection status of filter number <hierarchicalFilter> in facet "<facetName>" is true
When child filter <childFilter> from parent filter <hierarchicalFilter> in "<facetName>" is clicked
Expand Down
20 changes: 10 additions & 10 deletions tests/e2e/cucumber/facets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ Then('facets are displayed is {boolean}', (areVisible: boolean) => {
cy.getByDataTest('facets-facet').should(`${areVisible ? '' : 'not.'}exist`);
});

When(
'hide-show filters button is clicked on {string} after facets being displayed is {boolean}',
(view: ViewportPreset, areFacetsVisible: boolean) => {
if (view.includes('macbook')) {
cy.getByDataTest('toggle-facets-button').click();
} else {
cy.getByDataTest(`${areFacetsVisible ? 'close' : 'open'}-modal-id`).click();
}
When('sort and filter button is clicked on {string}', (view: ViewportPreset) => {
if (view.includes('macbook')) {
cy.getByDataTest('toggle-facets-button').click({ force: true });
} else {
cy.getByDataTest('open-modal-id').click();
}
);
});

When('{string} is clicked to close the modal', (closeMethod: string) => {
cy.getByDataTest(closeMethod).eq(0).click('topLeft', { force: true });
});
// Scenario 2
When('filter {int} from facet {string} is clicked', (filterNumber: number, facetName: string) => {
cy.getByDataTest(facetName)
Expand Down Expand Up @@ -51,7 +51,7 @@ When('clear filters button is clicked', () => {

// Scenario 4
When('facet {string} is unfolded', (facetName: string) => {
cy.getByDataTest(facetName).click();
cy.getByDataTest(facetName).getByDataTest('toggle-panel-header').click();
});

// Scenario 5
Expand Down
7 changes: 4 additions & 3 deletions tests/e2e/cucumber/multiple-interactions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ Feature: Multiple interactions
And next query number <nextQueryItem> is clicked
Then related results have changed
When scroll down for two seconds
And facets are shown if hidden on "<view>"
And facet "<facetName>" is unfolded
And sort and filter button is clicked on "<view>"
Then facets are displayed is true
When facet "<facetName>" is unfolded
And filter <filterNumber> from facet "<facetName>" is clicked
And facets are hidden if shown on "<view>"
And "modal-overlay" is clicked to close the modal
Then related results have changed
When scroll down for two seconds
And search input is cleared
Expand Down
25 changes: 1 addition & 24 deletions tests/e2e/cucumber/multiple-interactions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
import { Then, When } from 'cypress-cucumber-preprocessor/steps';

Then('related results are displayed', () => {
cy.getByDataTest('search-grid-result').first().scrollIntoView();
cy.getByDataTest('search-grid-result')
.should('be.visible')
.should('have.length.at.least', 1)
.invoke('text')
.as('resultsList');
});

Then('related results have changed', () => {
cy.getByDataTest('search-grid-result').first().scrollIntoView();
cy.get<string>('@resultsList').then(resultsList => {
cy.getByDataTest('search-grid-result')
.should('be.visible')
.should('have.length.at.least', 1)
.should(newResultsList => {
expect(newResultsList.text()).to.be.not.equal(resultsList);
})
.invoke('text')
.as('resultsList');
});
});
import { When } from 'cypress-cucumber-preprocessor/steps';

When('next query number {int} is clicked', (nextQueryItem: number) => {
cy.getByDataTest('next-query')
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/cucumber/no-results.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { And, Then } from 'cypress-cucumber-preprocessor/steps';

Then('no results message is displayed', () => {
cy.getByDataTest('no-results').should('exist');
cy.getByDataTest('no-results-message').should('exist');
});

And('there are no results', () => {
Expand Down
9 changes: 5 additions & 4 deletions tests/e2e/cucumber/predictive-components.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Feature: Predictive components
Then history queries are displayed
Examples:
| query | view |
| belt | macbook-13 |
| belt | iphone-7 |
| belt | macbook-13 |
| belt | iphone-7 |

Scenario Outline: 2. Related tags interaction
Given start page with "<view>" size view
Expand All @@ -39,7 +39,8 @@ Feature: Predictive components
Given start page with "<view>" size view
When start button is clicked
Given a "<list>" of queries already searched
When search input is focused
When focus is set on the search input
And history queries are displayed
And history query number <historyQueryItem> delete button is clicked
Then the deleted history query is removed from history queries
Examples:
Expand All @@ -51,7 +52,7 @@ Feature: Predictive components
Given start page with "<view>" size view
When start button is clicked
Given a "<list>" of queries already searched
When search input is focused
When focus is set on the search input
And clear history queries button is clicked
Then no history queries are displayed
Examples:
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/cucumber/predictive-components.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ When('history query number {int} delete button is clicked', (historyQueryItem: n
.invoke('text')
.as('deletedHistoryQuery')
.then(() => {
cy.focusSearchInput();
cy.getByDataTest('remove-history-query').eq(historyQueryItem).click();
});
});
Expand Down
21 changes: 12 additions & 9 deletions tests/e2e/cucumber/scroll.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ Feature: Scroll
Given start page with "<view>" size view
When start button is clicked
And "<query>" is searched
And scrolling down to result "<resultId>"
Then related results are displayed
When scrolling down to result "<resultId>"
Then url is updated with result "<resultId>"
When facets are shown if hidden on "<view>"
And "<sortOrder>" order is clicked
And facets are hidden if shown on "<view>"
Then scroll position is at top
When sort and filter button is clicked on "<view>"
And "<sortOrder>" order is clicked in "<sortMenuName>"
And "close-modal-id" is clicked to close the modal
Then related results have changed
And scroll position is at top
When scrolling down to result "<resultId>"
Then url is updated with result "<resultId>"
And facets are shown if hidden on "<view>"
When sort and filter button is clicked on "<view>"
And facet "<facetName>" is unfolded
And filter <filterIndex> from facet "<facetName>" is clicked
And "modal-overlay" is clicked to close the modal
Then scroll position is at top
Examples:
| query | view | resultId | sortOrder | filterIndex | facetName |
| shirt | macbook-13 | result-16 | price asc | 1 | price |
| shirt | iphone-7 | result-16 | price asc | 1 | price |
| query | view | resultId | sortMenuName | sortOrder | filterIndex | facetName |
| shirt | macbook-13 | result-16 | Sort by | Price: Low to High | 1 | price |
| shirt | iphone-7 | result-16 | Sort by | Price: Low to High | 1 | price |

4 changes: 1 addition & 3 deletions tests/e2e/cucumber/scroll.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ Then('url is updated with result {string}', (resultId: string) => {
});

Then('scroll position is at top', () => {
cy.get('#main-scroll').should(scrollContainer => {
expect(scrollContainer.scrollTop()).to.equal(0);
});
cy.url().should('not.contain', 'scroll');
});
Loading