Skip to content

Commit a3bb6bb

Browse files
committed
Fixed tests with cms blocks.
1 parent 9219e04 commit a3bb6bb

File tree

6 files changed

+115
-2
lines changed

6 files changed

+115
-2
lines changed

cypress/e2e/yves/customer-account-management/customer-auth-dms.cy.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { container } from '@utils';
22
import { LoginPage, CustomerOverviewPage } from '@pages/yves';
33
import { CustomerAuthDmsDynamicFixtures, CustomerAuthDmsStaticFixtures } from '@interfaces/yves';
4-
import { CreateStoreScenario, UserLoginScenario } from '@scenarios/backoffice';
4+
import { CreateStoreScenario, EnableCmsBlockForAllStoresScenario, UserLoginScenario } from '@scenarios/backoffice';
55
import { SelectStoreScenario } from '@scenarios/yves';
66

77
describeIfDynamicStoreEnabled(
@@ -13,6 +13,7 @@ describeIfDynamicStoreEnabled(
1313
const userLoginScenario = container.get(UserLoginScenario);
1414
const createStoreScenario = container.get(CreateStoreScenario);
1515
const selectStoreScenario = container.get(SelectStoreScenario);
16+
const enableCmsBlockForAllStoresScenario = container.get(EnableCmsBlockForAllStoresScenario);
1617

1718
let dynamicFixtures: CustomerAuthDmsDynamicFixtures;
1819
let staticFixtures: CustomerAuthDmsStaticFixtures;
@@ -26,6 +27,17 @@ describeIfDynamicStoreEnabled(
2627
});
2728

2829
createStoreScenario.execute({ store: staticFixtures.store, shouldTriggerPublishAndSync: true });
30+
31+
enableCmsBlockForAllStoresScenario.execute({
32+
cmsBlockName: 'customer-registration_token--text',
33+
storeName: staticFixtures.store.name,
34+
shouldTriggerPublishAndSync: true,
35+
});
36+
enableCmsBlockForAllStoresScenario.execute({
37+
cmsBlockName: 'customer-registration_token--html',
38+
storeName: staticFixtures.store.name,
39+
shouldTriggerPublishAndSync: true,
40+
});
2941
});
3042

3143
beforeEach((): void => {

cypress/support/pages/backoffice/backoffice-page.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,55 @@ export class BackofficePage extends AbstractPage {
6060
});
6161
});
6262
};
63+
64+
public findWithRetry = (params: UpdateWithRetryParams): Cypress.Chainable => {
65+
const retryCount = 2;
66+
let attempts = 0;
67+
68+
const searchAndIntercept = (): Cypress.Chainable => {
69+
attempts++;
70+
// eslint-disable-next-line cypress/unsafe-to-chain-command
71+
cy.get('[type="search"]')
72+
.clear()
73+
.then(() => {
74+
cy.visitBackoffice(params.pageUrl);
75+
});
76+
77+
return this.interceptTable({ url: params.tableUrl }).then(() => {
78+
// eslint-disable-next-line cypress/unsafe-to-chain-command
79+
cy.get('[type="search"]')
80+
.invoke('val', params.searchQuery)
81+
.trigger('input')
82+
.then(() => {
83+
return this.interceptTable({ url: params.tableUrl, expectedCount: params.expectedCount }, () => {
84+
cy.get('tbody > tr:visible').then(($rows) => {
85+
let rows = Cypress.$($rows);
86+
87+
if (params.rowFilter && params.rowFilter.length > 0) {
88+
params.rowFilter.forEach((filterFn) => {
89+
if (rows.length > 0) {
90+
rows = rows.filter((index, row) => filterFn(Cypress.$(row)));
91+
}
92+
});
93+
}
94+
95+
if (rows.length > 0) {
96+
return cy.wrap(rows.first());
97+
} else if (attempts < retryCount) {
98+
cy.log(`Retrying... Attempt ${attempts}`);
99+
return searchAndIntercept();
100+
} else {
101+
cy.log('No rows found after filtering');
102+
return null;
103+
}
104+
});
105+
});
106+
});
107+
});
108+
};
109+
110+
return searchAndIntercept();
111+
};
63112
}
64113

65114
export enum ActionEnum {
@@ -84,3 +133,11 @@ interface UpdateParams {
84133
rowFilter?: Array<(row: JQuery<HTMLElement>) => boolean>;
85134
expectedCount?: number;
86135
}
136+
137+
interface UpdateWithRetryParams {
138+
searchQuery: string;
139+
tableUrl: string;
140+
rowFilter?: Array<(row: JQuery<HTMLElement>) => boolean>;
141+
expectedCount?: number | null;
142+
pageUrl: string;
143+
}

cypress/support/pages/backoffice/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export * from './merchant/create/merchant-create-page';
77
export * from './merchant/list/merchant-list-page';
88
export * from './merchant/update/merchant-update-page';
99
export * from './merchant-user/create/merchant-user-create-page';
10+
export * from './cms/block/list/block-list-page';
11+
export * from './cms/block/update/block-update-page';
1012
export * from './cms/page/create/cms-page-create-page';
1113
export * from './cms/cms-placeholder/edit/cms-placeholder-edit-page';
1214
export * from './sales/detail/sales-detail-page';

cypress/support/pages/backoffice/product-management/edit/variant/product-management-edit-variant-repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export class ProductManagementEditVariantRepository {
1212
getSearchableENCheckbox = (): Cypress.Chainable => cy.get('#product_concrete_form_edit_general_en_US_is_searchable');
1313
getPriceStockTab = (): Cypress.Chainable => cy.get('[data-tab-content-id="tab-content-price"]');
1414
getIsNeverOutOfStockCheckbox = (): Cypress.Chainable =>
15-
cy.get('#product_concrete_form_edit_price_and_stock_1_is_never_out_of_stock');
15+
cy.get('#product_concrete_form_edit_price_and_stock_0_is_never_out_of_stock');
1616
getSaveButton = (): Cypress.Chainable => cy.get('[type="submit"]');
1717
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { autoWired } from '@utils';
2+
import { inject, injectable } from 'inversify';
3+
import { BlockUpdatePage, BlockListPage } from '@pages/backoffice';
4+
5+
@injectable()
6+
@autoWired
7+
export class EnableCmsBlockForAllStoresScenario {
8+
@inject(BlockUpdatePage) private blockUpdatePage: BlockUpdatePage;
9+
@inject(BlockListPage) private blockListPage: BlockListPage;
10+
11+
execute = (params: ExecuteParams): void => {
12+
this.blockListPage.visit();
13+
14+
this.blockListPage.interceptTable({ url: '/cms-block-gui/list-block/table**' }).then(() => {
15+
this.blockListPage
16+
.findWithRetry({
17+
searchQuery: params.cmsBlockName,
18+
tableUrl: '/cms-block-gui/list-block/table**',
19+
pageUrl: this.blockListPage.getPageUrl(),
20+
})
21+
.then(($storeRow) => {
22+
if (!this.blockListPage.rowIsAssignedToStore({ row: $storeRow, storeName: params.storeName })) {
23+
this.blockListPage.clickEditAction($storeRow);
24+
25+
this.blockUpdatePage.assignAllAvailableStore();
26+
this.blockUpdatePage.save();
27+
28+
if (params?.shouldTriggerPublishAndSync) {
29+
cy.runCliCommands(['console queue:worker:start --stop-when-empty']);
30+
}
31+
}
32+
});
33+
});
34+
};
35+
}
36+
37+
interface ExecuteParams {
38+
cmsBlockName: string;
39+
shouldTriggerPublishAndSync?: boolean;
40+
storeName?: string;
41+
}

cypress/support/scenarios/backoffice/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export * from './assign-store-to-default-shipment-methods-scenario';
1212
export * from './assign-store-to-default-payment-methods-scenario';
1313
export * from './assign-store-to-default-shipment-types-scenario';
1414
export * from './assign-store-to-default-warehouse-scenario';
15+
export * from './enable-cms-block-for-all-stores-scenario';

0 commit comments

Comments
 (0)