Skip to content

Commit

Permalink
test(os-159): added e2e tests for breadcrumbs (#6267)
Browse files Browse the repository at this point in the history
* Sync `release-2.4` with `release/next` (#6237)

* test(os-159): added e2e tests for breadcrumbs on category page

* Update packages/commercetools/theme/tests/e2e/integration/e2e-breadcrumbs.spec.ts
  • Loading branch information
dawid-ziobro authored Sep 8, 2021
1 parent acc3e54 commit 3ca1442
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"Should display breadcrumbs list properly - category": {
"category": "women",
"expectedLength": 2
},
"Should display breadcrumbs list properly - subcategory": {
"category": "women",
"subcategory": "women-clothing",
"expectedLength": 3
},
"Should display breadcrumbs list properly - nested subcategory": {
"category": "women",
"subcategory": "women-clothing-jackets",
"expectedLength": 4
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import page from '../pages/factory';

const testsCases = [
'category',
'subcategory',
'nested subcategory'
];

const breadcrumbsNames = [
'Home',
'Women',
'Clothing',
'Jackets'
];

context(['regression'], 'Breadcrumbs', () => {
beforeEach(function () {
cy.fixture('test-data/e2e-breadcrumbs').then((fixture) => {
this.fixtures = {
data: fixture
};
});
});

testsCases.forEach(testCase => {
it(`Should display breadcrumbs list properly - ${testCase}`, function () {
const data = this.fixtures.data[this.test.title];
const category = page.category(data.category, data.subcategory);

category.visit();

page.components.breadcrumbs.container.should('not.be.empty');
page.components.breadcrumbs.listItems.should('have.length', data.expectedLength);

page.components.breadcrumbs.listItems.each((item, index) => {
expect(item.text()).to.contain(breadcrumbsNames[index]);
});
});
});
});
10 changes: 8 additions & 2 deletions packages/commercetools/theme/tests/e2e/pages/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ type View = 'tiles' | 'list'
export class Category extends Base {

private readonly _category: string;
private readonly _subcategory: string;
private _view: View = 'tiles';

constructor(category?: string) {
constructor(category?: string, subcategory?: string) {
super();
if (category) this._category = category;
if (subcategory) this._subcategory = subcategory;
}

set view(view: View) {
Expand All @@ -25,8 +27,12 @@ export class Category extends Base {
return this._category;
}

get subcategory(): string {
return this._subcategory;
}

get path(): string {
return `/c/${this.category}`;
return `/c/${this.category}${this.subcategory ? `/${this.subcategory}` : ''}`;
}

get products(): Cypress.Chainable {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { el } from '../utils/element';

class Breadcrumbs {

get container(): Cypress.Chainable {
return el('breadcrumbs');
}

get listItems(): Cypress.Chainable {
return el('breadcrumbs', '.sf-breadcrumbs__list-item');
}
}

export default new Breadcrumbs();
8 changes: 5 additions & 3 deletions packages/commercetools/theme/tests/e2e/pages/factory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Billing, Payment, Shipping, ThankYou } from './checkout';
import Breadcrumbs from './components/breadcrumbs';
import Cart from './components/cart-sidebar';
import LoginModal from './components/login-modal';
import Home from './home';
Expand All @@ -19,7 +20,8 @@ const page = {
get components() {
return {
cart: Cart,
loginModal: LoginModal
loginModal: LoginModal,
breadcrumbs: Breadcrumbs
};
},

Expand All @@ -34,8 +36,8 @@ const page = {
};
},

category(category?: string) {
return new Category(category);
category(category?: string, subcategory?: string) {
return new Category(category, subcategory);
},

product(id?: string, slug?: string) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/nuxt-theme-module/theme/pages/Category.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<div id="category">
<SfBreadcrumbs
v-e2e="'breadcrumbs'"
class="breadcrumbs desktop-only"
:breadcrumbs="breadcrumbs"
/>
Expand Down

0 comments on commit 3ca1442

Please sign in to comment.