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/cc 34502/dev order amendment finalisation #72

Merged
merged 5 commits into from
Jan 17, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describeIfDynamicStoreEnabled(
salesIndexPage.visit();
salesIndexPage.view();

salesDetailPage.triggerOms({ state: 'skip grace period', shouldTriggerOmsInCli: true });
salesDetailPage.triggerOms({ state: 'Pay', shouldTriggerOmsInCli: true });
salesDetailPage.triggerOms({ state: 'Skip timeout', shouldTriggerOmsInCli: true });
salesDetailPage.triggerOms({ state: 'skip picking' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import { CatalogPage, ProductPage } from '@pages/yves';
salesIndexPage.visit();
salesIndexPage.view();

salesDetailPage.triggerOms({ state: 'skip grace period', shouldTriggerOmsInCli: true });
salesDetailPage.triggerOms({ state: 'Pay', shouldTriggerOmsInCli: true });
salesDetailPage.triggerOms({ state: 'Skip timeout', shouldTriggerOmsInCli: true });
salesDetailPage.triggerOms({ state: 'skip picking' });
Expand All @@ -68,6 +69,7 @@ import { CatalogPage, ProductPage } from '@pages/yves';
salesIndexPage.visit();
salesIndexPage.view();

salesDetailPage.triggerOms({ state: 'skip grace period', shouldTriggerOmsInCli: true });
salesDetailPage.triggerOms({ state: 'Pay', shouldTriggerOmsInCli: true });
salesDetailPage.triggerOms({ state: 'Skip timeout', shouldTriggerOmsInCli: true });
salesDetailPage.triggerOms({ state: 'skip picking' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { CheckoutMpScenario, CustomerLoginScenario, SelectStoreScenario } from '@scenarios/yves';
import { ActionEnum, SalesOrdersPage } from '@pages/mp';
import { MerchantUserLoginScenario } from '@scenarios/mp';
import { retryableBefore } from '../../../support/e2e';

describeDmsSuiteAndMp('order creation dms', { tags: ['@mp', '@marketplace-order-management', '@dms'] }, (): void => {
const catalogPage = container.get(CatalogPage);
Expand All @@ -32,7 +33,7 @@ describeDmsSuiteAndMp('order creation dms', { tags: ['@mp', '@marketplace-order-
let staticFixtures: OrderCreationDmsStaticFixtures;
let dynamicFixtures: OrderCreationDmsDynamicFixtures;

before((): void => {
retryableBefore((): void => {
({ staticFixtures, dynamicFixtures } = Cypress.env());

userLoginScenario.execute({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import { CheckoutScenario, CustomerLoginScenario } from '@scenarios/yves';
}

function closeOrderFromBackoffice(): void {
salesDetailPage.triggerOms({ state: 'skip grace period' });
salesDetailPage.triggerOms({ state: 'Pay' });
salesDetailPage.triggerOms({ state: 'Skip timeout' });
salesDetailPage.triggerOms({ state: 'skip picking' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { CheckoutScenario, CustomerLoginScenario } from '@scenarios/yves';
cartPage.assertCartName('Shopping cart');

customerOverviewPage.viewLastPlacedOrder();
orderDetailsPage.containsOrderState('Payment pending');
orderDetailsPage.containsOrderState('New');
});
});

Expand Down
14 changes: 6 additions & 8 deletions cypress/e2e/yves/order-amendment/order-amendment-start.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { DeactivateProductScenario } from '../../../support/scenarios/backoffice
placeCustomerOrder(dynamicFixtures.customer1.email, dynamicFixtures.address1.id_customer_address);

customerOverviewPage.viewLastPlacedOrder();
orderDetailsPage.containsOrderState('Payment pending');
orderDetailsPage.containsOrderState('New');

orderDetailsPage.getOrderReferenceBlock().then((orderReference: string) => {
orderDetailsPage.editOrder();
Expand All @@ -52,19 +52,17 @@ import { DeactivateProductScenario } from '../../../support/scenarios/backoffice
});
});

it('customer should not be able to create order amendment when order not in payment-pending state', (): void => {
it('customer should not be able to create order amendment when order not in "grace period started" state', (): void => {
placeCustomerOrder(dynamicFixtures.customer2.email, dynamicFixtures.address2.id_customer_address);
triggerOmsOrderToPaidState();
triggerOmsOrderToGracePeriodFinishedState();

customerLoginScenario.execute({
email: dynamicFixtures.customer2.email,
password: staticFixtures.defaultPassword,
});

customerOverviewPage.viewLastPlacedOrder();
orderDetailsPage.editOrder();

cy.contains('The order cannot be amended.').should('exist');
orderDetailsPage.doesNotContainEditOrderButton();
});

it('customer should be able to replace current cart (quote) with previous order items', (): void => {
Expand Down Expand Up @@ -193,7 +191,7 @@ import { DeactivateProductScenario } from '../../../support/scenarios/backoffice
});
}

function triggerOmsOrderToPaidState(): void {
function triggerOmsOrderToGracePeriodFinishedState(): void {
userLoginScenario.execute({
username: dynamicFixtures.rootUser.username,
password: staticFixtures.defaultPassword,
Expand All @@ -202,7 +200,7 @@ import { DeactivateProductScenario } from '../../../support/scenarios/backoffice
salesIndexPage.visit();
salesIndexPage.view();

salesDetailPage.triggerOms({ state: 'Pay', shouldTriggerOmsInCli: true });
salesDetailPage.triggerOms({ state: 'skip grace period', shouldTriggerOmsInCli: true });
}
}
);
39 changes: 23 additions & 16 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,31 @@ Cypress.Commands.add('resetMerchantPortalCookies', () => {
});
});

Cypress.Commands.add('reloadUntilFound', (url, findSelector, getSelector = 'body', retries = 3, retryWait = 1000) => {
if (retries === 0) {
throw `exhausted retries looking for ${getSelector} on ${url}`;
}

cy.visit(url);
cy.get(getSelector).then((body) => {
const msg = `url:${url} getSelector:${getSelector} findSelector:${findSelector} retries:${retries} retryWait:${retryWait}`;
Cypress.Commands.add(
'reloadUntilFound',
(url, findSelector, getSelector = 'body', retries = 3, retryWait = 1000, commands = []) => {
if (retries === 0) {
throw `exhausted retries looking for ${getSelector} on ${url}`;
}

if (body.find(findSelector).length === 1) {
cy.log(`found ${msg}`);
} else {
cy.log(`NOT found ${msg}`);
cy.wait(retryWait);
cy.reloadUntilFound(url, findSelector, getSelector, retries - 1, retryWait);
if (commands.length) {
cy.runCliCommands(commands);
}
});
});

cy.visit(url);
cy.get(getSelector).then((body) => {
const msg = `url:${url} getSelector:${getSelector} findSelector:${findSelector} retries:${retries} retryWait:${retryWait}`;

if (body.find(findSelector).length === 1) {
cy.log(`found ${msg}`);
} else {
cy.log(`NOT found ${msg}`);
cy.wait(retryWait);
cy.reloadUntilFound(url, findSelector, getSelector, retries - 1, retryWait, commands);
}
});
}
);

Cypress.Commands.add('runCliCommands', (commands) => {
const operations = commands.map((command) => {
Expand Down
9 changes: 8 additions & 1 deletion cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ declare namespace Cypress {
/**
* @example cy.reloadUntilFound('/transactions', 'td:contains($4.44)')
*/
reloadUntilFound(url: string, findSelector: string, getSelector: string, retries: number, retryWait: number): void;
reloadUntilFound(
url: string,
findSelector: string,
getSelector: string,
retries: number,
retryWait: number,
commands?: string[]
): void;

/**
* @example cy.runCliCommands(['console oms:check-condition', 'console oms:check-timeout'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export class SalesDetailPage extends BackofficePage {
this.repository.getOmsButtonSelector(params.state),
this.repository.getTriggerOmsDivSelector(),
25,
5000
5000,
params.shouldTriggerOmsInCli ? ['console oms:check-condition', 'console oms:check-timeout'] : []
);

cy.get(this.repository.getTriggerOmsDivSelector())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ export class OrderDetailsPage extends YvesPage {
containsOrderState = (orderState: string): void => {
cy.get('body').contains(orderState).should('exist');
};

doesNotContainEditOrderButton = (): void => {
this.repository.getEditOrderForm().should('not.exist');
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface OrderDetailsRepository {
getReorderSelectedItemsButton(): Cypress.Chainable;
getCartReorderItemCheckboxes(): Cypress.Chainable;
getEditOrderButton(): Cypress.Chainable;
getEditOrderForm(): Cypress.Chainable;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class B2bMpOrderDetailsRepository implements OrderDetailsRepository {
return cy.get('input[type="checkbox"][name="sales-order-item-ids[]"]');
}
getEditOrderButton(): Cypress.Chainable {
return cy.get('[data-qa="component remote-form-submit"]').find('button');
return this.getEditOrderForm().find('button');
}

getEditOrderForm(): Cypress.Chainable {
return cy.get('[data-qa="component remote-form-submit"]');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class B2bOrderDetailsRepository implements OrderDetailsRepository {
return cy.get('input[type="checkbox"][name="sales-order-item-ids[]"]');
}
getEditOrderButton(): Cypress.Chainable {
return cy.get('[data-qa="component remote-form-submit"]').find('button');
return this.getEditOrderForm().find('button');
}

getEditOrderForm(): Cypress.Chainable {
return cy.get('[data-qa="component remote-form-submit"]');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class B2cMpOrderDetailsRepository implements OrderDetailsRepository {
return cy.get('input[type="checkbox"][name="sales-order-item-ids[]"]');
}
getEditOrderButton(): Cypress.Chainable {
return cy.get('[data-qa="component remote-form-submit"]').find('button');
return this.getEditOrderForm().find('button');
}

getEditOrderForm(): Cypress.Chainable {
return cy.get('[data-qa="component remote-form-submit"]');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class B2cOrderDetailsRepository implements OrderDetailsRepository {
return cy.get('input[type="checkbox"][name="sales-order-item-ids[]"]');
}
getEditOrderButton(): Cypress.Chainable {
return cy.get('[data-qa="component remote-form-submit"]').find('button');
return this.getEditOrderForm().find('button');
}

getEditOrderForm(): Cypress.Chainable {
return cy.get('[data-qa="component remote-form-submit"]');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class SuiteOrderDetailsRepository implements OrderDetailsRepository {
return cy.get('input[type="checkbox"][name="sales-order-item-ids[]"]');
}
getEditOrderButton(): Cypress.Chainable {
return cy.get('[data-qa="component remote-form-submit"]').find('button');
return this.getEditOrderForm().find('button');
}

getEditOrderForm(): Cypress.Chainable {
return cy.get('[data-qa="component remote-form-submit"]');
}
}
Loading