Skip to content

Commit

Permalink
test: Enhance e2e tests with buyer 'Cancel' action (#17797)
Browse files Browse the repository at this point in the history
Closes: CXSPA-4263
  • Loading branch information
Stofftiger authored Aug 28, 2023
1 parent 7221c81 commit b675c8d
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,37 @@ context('Quote', () => {

describe('Request quote process', () => {
it('should display a global message and disable submit button if threshold is not met', () => {
quote.requestQuote(POWERTOOLS, TEST_PRODUCT_HAMMER_DRILLING_ID, '1');
quote.checkQuoteInDraftState(false, TEST_PRODUCT_HAMMER_DRILLING_ID);
quote.prepareQuote(POWERTOOLS, TEST_PRODUCT_HAMMER_DRILLING_ID, 1, false);
});

it('should be possible(submit) if threshold is met', () => {
quote.requestQuote(POWERTOOLS, TEST_PRODUCT_HAMMER_DRILLING_ID, '30');
quote.checkQuoteInDraftState(true, TEST_PRODUCT_HAMMER_DRILLING_ID);
quote.prepareQuote(
POWERTOOLS,
TEST_PRODUCT_HAMMER_DRILLING_ID,
PRODUCT_AMOUNT_30,
true
);

quote.addHeaderComment(
'Can you please make me a good offer for this large volume of goods?'
);

quote.checkComment(
1,
'Can you please make me a good offer for this large volume of goods?'
);

quote.addItemComment(
TEST_PRODUCT_HAMMER_DRILLING_NAME,
'since there is a newer model out, is it possible to get a discount for this item?'
);

quote.checkItemComment(
2,
TEST_PRODUCT_HAMMER_DRILLING_NAME,
'since there is a newer model out, is it possible to get a discount for this item?'
);

quote.clickItemLinkInComment(2, TEST_PRODUCT_HAMMER_DRILLING_NAME);
quote.checkLinkedItemInViewport(1);
quote.submitQuote();
Expand All @@ -66,12 +74,12 @@ context('Quote', () => {

describe('Edit quote process - buyer perspective', () => {
beforeEach(() => {
quote.requestQuote(
quote.prepareQuote(
POWERTOOLS,
TEST_PRODUCT_HAMMER_DRILLING_ID,
PRODUCT_AMOUNT_30.toString()
PRODUCT_AMOUNT_30,
true
);
quote.checkQuoteInDraftState(true, TEST_PRODUCT_HAMMER_DRILLING_ID);
});

it('should edit quantity of items within a buyer quote draft (CXSPA-3852)', () => {
Expand Down Expand Up @@ -103,9 +111,9 @@ context('Quote', () => {
});
});

// these tests should be removed, as soon as the quote list navigation is part of the above process tests
describe('Quote list', () => {
describe('Navigate to quote list', () => {
it('should be accessible from My Account', () => {
quote.requestQuote(POWERTOOLS, TEST_PRODUCT_HAMMER_DRILLING_ID, '1');
quote.navigateToQuoteListFromMyAccount();
quote.checkQuoteListPresent();
});
Expand All @@ -115,5 +123,18 @@ context('Quote', () => {
quote.navigateToQuoteListFromQuoteDetails();
quote.checkQuoteListPresent();
});

it('should cancel a quote and be redirected back to the quote list (CXSPA-4035)', () => {
quote.prepareQuote(
POWERTOOLS,
TEST_PRODUCT_HAMMER_DRILLING_ID,
PRODUCT_AMOUNT_30,
true
);
quote.cancelQuote();
quote.checkQuoteListPresent();
quote.gotToQuoteDetailsOverviewPage();
quote.checkQuoteState(quote.STATUS_CANCELED);
});
});
});
94 changes: 74 additions & 20 deletions projects/storefrontapp-e2e-cypress/cypress/helpers/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as common from './common';
/** alias for GET Quote Route */
export const GET_QUOTE_ALIAS = '@GET_QUOTE';
export const STATUS_SUBMITTED = 'Submitted';
export const STATUS_CANCELED = 'Cancelled';
const STATUS_DRAFT = 'Draft';
const CARD_TITLE_QUOTE_INFORMATION = 'Quote Information';
const SUBMIT_BTN = 'Submit Quote';
Expand Down Expand Up @@ -52,6 +53,27 @@ export function login(email: string, password: string, name: string): void {
cy.get('cx-login').should('not.contain', 'Sign In');
}

/**
* Requests a quote and verifies if it is in draft state.
*
* @param shopName Name of the given shop
* @param productId Id of the product added to the quote
* @param productAmount Amount of the product added to the quote
*/
export function prepareQuote(
shopName: String,
productId: String,
productAmount: number,
inDraftState: boolean
) {
log(
'Requests a quote and verifies if it is in draft state',
prepareQuote.name
);
this.requestQuote(shopName, productId, productAmount.toString());
this.checkQuoteInDraftState(inDraftState, productId);
}

/**
* Requests a quote from cart and verifies the quote page is visible.
*
Expand All @@ -70,7 +92,7 @@ export function requestQuote(
cy.location('pathname').should('contain', '/quote');
cy.get('cx-quote-details-overview').should('be.visible');
cy.get('cx-quote-actions-by-role').should('be.visible');
cy.url().as('quoteURL');
cy.url().should('contain', '/quote').as('quoteURL');
}

/**
Expand Down Expand Up @@ -102,7 +124,7 @@ export function submitQuote(): void {
);
this.clickSubmitQuoteBtn();
this.clickOnYesBtnWithinRequestPopUp();
cy.get<string>('@quoteURL').then(cy.visit);
gotToQuoteDetailsOverviewPage();
}

/**
Expand Down Expand Up @@ -170,7 +192,7 @@ export function changeItemQuantityByCounter(
}

/**
* Verifies the quantity of an item at the given index equals the expected quantity given.
* Verifies if the quantity of an item at the given index equals the expected quantity given.
*
* @param itemIndex Index of the Item in the QDP cart list
* @param expectedQuantity Expected quantity of the item
Expand All @@ -180,7 +202,7 @@ export function checkItemQuantity(
expectedQuantity: string
): void {
log(
'Verifies the quantity of an item at the given index equals the expected quantity given',
'Verifies if the quantity of an item at the given index equals the expected quantity given',
checkItemQuantity.name
);
cy.get(
Expand All @@ -202,7 +224,7 @@ export function removeItem(itemIndex: number): void {
).within(() => {
cy.get('button').contains('Remove').click();
});
cy.get<string>('@quoteURL').then(cy.visit);
gotToQuoteDetailsOverviewPage();
}

/**
Expand All @@ -228,7 +250,7 @@ export function checkItemVisible(itemIndex: number, productID: string): void {
* @param productID Id of the product
*/
export function checkItemExists(itemIndex: number, productID: string): void {
log('Verifies the item at the given index exists', checkItemExists.name);
log('Verifies if the item at the given index exists', checkItemExists.name);
if (itemIndex === 1) {
cy.get(
`cx-quote-details-cart .cx-item-list-row:nth-child(${itemIndex})`
Expand All @@ -241,13 +263,13 @@ export function checkItemExists(itemIndex: number, productID: string): void {
}

/**
* Verifies the "Quote Information" card tile is in edit mode.
* Verifies if the "Quote Information" card tile is in edit mode.
*
* @param isEditModeActive Indicates if the card is in edit mode
*/
export function checkQuoteInformationCard(isEditModeActive: boolean): void {
log(
'Verifies the "Quote Information" card tile is in edit mode',
'Verifies if the "Quote Information" card tile is in edit mode',
checkQuoteInformationCard.name
);
cy.get(`cx-quote-details-overview .cx-container .card-body`)
Expand Down Expand Up @@ -317,7 +339,7 @@ export function checkQuoteInformationCardContent(
expectedQuoteInformationContent: string
): void {
log(
'Verifies the expected quote name equals the current quote name',
'Verifies if the expected quote name equals the current quote name',
checkQuoteInformationCardContent.name
);
cy.get('cx-quote-details-overview .cx-container .card-body')
Expand Down Expand Up @@ -363,7 +385,7 @@ export function clickOnYesBtnWithinRequestPopUp(): void {
*/
export function checkGlobalMessageDisplayed(isDisplayed: boolean): void {
log(
'Verifies whether global message is displayed on the top of the page.',
'Verifies if the global message is displayed on the top of the page.',
checkGlobalMessageDisplayed.name
);
if (isDisplayed) {
Expand All @@ -378,7 +400,7 @@ export function checkGlobalMessageDisplayed(isDisplayed: boolean): void {
*/
export function checkSubmitBtn(isEnabled: boolean): void {
log(
'Verifies "Submit" button on the quote details overview page',
'Verifies if "Submit" button on the quote details overview page',
checkSubmitBtn.name
);
if (isEnabled) {
Expand All @@ -403,7 +425,7 @@ export function checkCommentsNotEditable(): void {
* Verifies if the quote list exists.
*/
export function checkQuoteListPresent() {
log('Verifies presence of quote list', checkQuoteListPresent.name);
log('Verifies if the quote list exists', checkQuoteListPresent.name);
cy.get('cx-quote-list').should('exist');
}

Expand Down Expand Up @@ -451,7 +473,7 @@ export function navigateToQuoteListFromQuoteDetails() {
}

/**
* Verifies the displayed quote is in draft state.
* Verifies if the displayed quote is in draft state.
*
* @param meetsThreshold Does the quote meet the threshold
* @param productId Product id of a product which is part of the quote
Expand All @@ -461,7 +483,7 @@ export function checkQuoteInDraftState(
productId: string
) {
log(
'Verifies the displayed quote is in draft state',
'Verifies if the displayed quote is in draft state',
checkQuoteInDraftState.name
);
checkQuoteState(STATUS_DRAFT);
Expand All @@ -471,12 +493,15 @@ export function checkQuoteInDraftState(
}

/**
* Verifies the given item exists within the quote cart.
* Verifies if the given item exists within the quote cart.
*
* @param productId Product ID of the item that should exist in the cart
*/
export function checkItem(productId: string) {
log('Verifies the given item exists within the quote cart', checkItem.name);
log(
'Verifies if the given item exists within the quote cart',
checkItem.name
);
cy.get('cx-quote-details-cart .cx-table-item-container .cx-info').contains(
productId
);
Expand Down Expand Up @@ -578,15 +603,44 @@ export function clickItemLinkInComment(index: number, item: string) {
* @param index Index of the quote details cart row.
*/
export function checkLinkedItemInViewport(index: number) {
log(
'Verifies whether the item in the viewport',
checkLinkedItemInViewport.name
);
log('Verifies if the item in the viewport', checkLinkedItemInViewport.name);
cy.get(`cx-quote-details-cart .cx-item-list-row:nth-child(${index})`).should(
'be.visible'
);
}

/**
* Cancels the quote.
*/
export function cancelQuote() {
log('Cancels the quote', cancelQuote.name);
clickCancelQuoteBtn();
clickOnYesBtnWithinRequestPopUp();
}

/**
* Clicks on "Cancel Quote" button.
*/
function clickCancelQuoteBtn() {
log('Clicks on "Cancel Quote" button', clickCancelQuoteBtn.name);
cy.get('cx-quote-actions-by-role button.btn-secondary')
.click()
.then(() => {
cy.get('cx-quote-confirm-action-dialog').should('be.visible');
});
}

/**
* Go to the quote details overview page.
*/
export function gotToQuoteDetailsOverviewPage() {
log(
'Go to the quote details overview page',
gotToQuoteDetailsOverviewPage.name
);
cy.get<string>('@quoteURL').then(cy.visit);
}

/**
* Registers GET quote route.
*/
Expand Down

0 comments on commit b675c8d

Please sign in to comment.