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

Cypress amplify testing #2966

Open
wants to merge 4 commits into
base: develop-1.1.0
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions apps/retail/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# nmHoistingLimits: workspaces
56 changes: 56 additions & 0 deletions apps/retail/cypress/e2e/auth.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { testIds } from '../../../../shared/dataTestIds'

// boc testing level 2

describe('Check Auth flow', () => {
context('Signin flow', () => {
beforeEach(() => {
cy.visit(testIds.url_base_retail)
})

it('should display the sign-in form with email and password fields', () => {
cy.getByData(testIds.auth_inputEmail).should('exist').and('be.visible')
cy.getByData(testIds.auth_inputPassword).should('exist').and('be.visible')
})

it('should display the sign-in and sign-up buttons', () => {
cy.getByData(testIds.auth_loginButton).should('exist').and('be.visible')
cy.getByData(testIds.auth_registerButton).should('exist').and('be.visible')
})

it('should disable the signin button when form is submitted with empty fields', () => {
cy.getByData(testIds.auth_loginButton).should('be.disabled')
})

it('should update email and password fields when typed into', () => {
cy.getByData(testIds.auth_inputEmail).type(testIds.user_validEmail)
cy.getByData(testIds.auth_inputEmail).should('have.value', testIds.user_validEmail)
cy.getByData(testIds.auth_inputPassword).type(testIds.user_validPassword)
cy.getByData(testIds.auth_inputPassword).should('have.value', testIds.user_validPassword)
})

it('should enable the Sign In button when both fields are filled', () => {
cy.getByData(testIds.auth_inputEmail).type(testIds.user_validEmail)
cy.getByData(testIds.auth_inputPassword).type(testIds.user_validPassword)
cy.getByData(testIds.auth_loginButton).should('not.be.disabled')
})

it('should show error toast on unsuccessful login', () => {
cy.getByData(testIds.auth_inputEmail).type(testIds.user_validEmail)
cy.getByData(testIds.auth_inputPassword).type(testIds.user_invalidPassword)
cy.getByData(testIds.auth_loginButton).click()
cy.getByData(testIds.feedback).should('contain.text', 'Error!')
})

it('should navigate to sign-up page when Sign Up button is clicked', () => {
cy.contains('button', 'Sign Up').click()
cy.url().should('include', testIds.url_signup)
})

it('should redirect to homePage and have token in cookie on successful login', () => {
cy.login(testIds.url_base_retail, testIds.user_validEmail, testIds.user_validPassword)
cy.url().should('include', testIds.url_home)
cy.getCookie('authToken').should('exist')
})
})
})
120 changes: 120 additions & 0 deletions apps/retail/cypress/e2e/cart.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { testIds } from '../../../../shared/dataTestIds'
describe('Cart Page Tests', () => {
before(() => {
cy.login(testIds.url_base_retail, testIds.user_validEmail, testIds.user_validPassword)
})
context('When there are no items in cart', () => {
const searchTerm = 'sunglass'
beforeEach(() => {
cy.visit(`${testIds.url_base_retail}${testIds.url_home}`)
cy.setGeolocation('getAddress')
cy.wait('@getAddress')
cy.performSearch(searchTerm, {
fixture: 'searchPage/searchResults.json'
})
cy.getByData(testIds.cartButton).click()
})

it('should render the cart page with no items', () => {
cy.url().should('include', testIds.url_cart)
cy.getByData(testIds.cartpage_emptyheading).should('contain.text', 'The Cart is Empty')
cy.getByData(testIds.cartpage_emptySubHeading).should(
'contain.text',
'Looks like you haven’t made your choice yet'
)
cy.getByData(testIds.cartpage_emptyImage).should('have.attr', 'src')
cy.getByData(testIds.cartpage_emptyButton).should('contain.text', 'Shop')
})
})
context('should render When there are Items in Cart', () => {
const searchTerm = 'sunglass'
beforeEach(() => {
cy.visit(`${testIds.url_base_retail}${testIds.url_home}`)
cy.setGeolocation('getAddress')
cy.wait('@getAddress')
cy.performSearch(searchTerm, {
fixture: 'searchPage/searchResults.json'
})
cy.getByData(testIds.searchpage_products).first().click()
cy.url().should('include', testIds.url_product)
cy.getByData(testIds.productpage_addTocartButton).click()
cy.intercept('POST', '/select', { fixture: 'cart/selectResult.json' }).as('selectCall')
cy.getByData(testIds.cartButton).click()
cy.wait('@selectCall')
})

afterEach(() => {
cy.clearAllLocalStorage()
})

it('should render and display cart page with result', () => {
cy.getByData(testIds.cartpage_itemImage).should('have.attr', 'src')
cy.getByData(testIds.cartpage_itemName).should('be.visible')
cy.getByData(testIds.cartpage_productPrice).should('be.visible')
cy.url().should('include', testIds.url_cart)
})
it('should render and display cart page Order Summary ', () => {
cy.getByData(testIds.cartpage_orderSummaryText).should('contain.text', 'Order Summary')
cy.getByData(testIds.cartpage_totalQuantityText).should('contain.text', 'Total Quantity')
cy.getByData(testIds.cartpage_totalAmountText).should('contain.text', 'Total Amount')
})

it('should render the cart page when counter is one and trash button is clicked', () => {
cy.getByData(testIds.cartpage_trashButton).click()
cy.url().should('include', testIds.url_cart)
cy.getByData(testIds.cartpage_emptyheading).should('contain.text', 'The Cart is Empty')
cy.getByData(testIds.cartpage_emptySubHeading).should(
'contain.text',
'Looks like you haven’t made your choice yet'
)
cy.getByData(testIds.cartpage_emptyImage).should('have.attr', 'src')
cy.getByData(testIds.cartpage_emptyButton).should('contain.text', 'Shop')
})
it('increments the counter and updates the total amount when the increment button is clicked', () => {
cy.fixture('cart/selectResult.json').then(data => {
const item = data.data[0].message.order.items[0]
const initialQuantity = item.quantity.selected.count
const itemPrice = parseFloat(item.price.value)

const expectedQuantity = initialQuantity + 1
const expectedTotalPrice = (itemPrice * expectedQuantity).toFixed(2)

cy.performSelect({ fixture: 'cart/selectResult.json' }, 'selectResponse', testIds.cartpage_incrementButton)
cy.wait('@selectResponse')
cy.getByData(testIds.cartpage_input)
.invoke('val')
.then(val => {
expect(Number(val)).to.equal(expectedQuantity)
})
cy.getByData(testIds.cartpage_productPrice).should('be.visible')
cy.getByData(testIds.item_price).should('contain.text', `₹${expectedTotalPrice}`)
})
})

it('decrements the counter and updates the total amount correctly', () => {
cy.performSelect({ fixture: 'cart/selectResult.json' }, 'selectResponse', testIds.cartpage_incrementButton)
cy.wait('@selectResponse')
cy.fixture('cart/selectResult.json').then(data => {
const item = data.data[0].message.order.items[0]
const initialQuantity = item.quantity.selected.count
const itemPrice = parseFloat(item.price.value)
const decrementedQuantity = initialQuantity
const expectedDecrementedTotalPrice = (itemPrice * decrementedQuantity).toFixed(2)

cy.getByData(testIds.cartpage_decrementButton).click()
cy.getByData(testIds.cartpage_input)
.invoke('val')
.then(val => {
expect(Number(val)).to.equal(decrementedQuantity)
})
cy.getByData(testIds.cartpage_productPrice).should('be.visible')
cy.getByData(testIds.item_price).should('contain.text', `₹${expectedDecrementedTotalPrice}`)
})
})

it('Should conatin order Button and click on it render it on checkout page', () => {
cy.getByData(testIds.cartpage_cartOrderButton).should('contain.text', 'Order')
cy.getByData(testIds.cartpage_cartOrderButton).click()
})
})
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/retail/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../../../../cypress/support/commands'
11 changes: 9 additions & 2 deletions apps/retail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"build": "next build",
"start": "next start",
"postbuild": "next-sitemap",
"export": "next export"
"export": "next export",
"cy:open": "cypress open",
"cy:run": "cypress run"
},
"prettier": "@beckn-ui/prettier-config",
"dependencies": {
Expand Down Expand Up @@ -37,6 +39,10 @@
"js-cookie": "^3.0.1",
"jsonwebtoken": "^8.5.1",
"leaflet": "^1.9.4",
"mocha": "^10.7.3",
"mochawesome": "^7.1.3",
"mochawesome-merge": "^4.3.0",
"mochawesome-report-generator": "^6.2.0",
"next": "^13.4.19",
"next-connect": "^0.12.2",
"next-sanity-image": "^3.2.1",
Expand All @@ -61,7 +67,8 @@
"redux-persist": "^6.0.0",
"slick-carousel": "^1.8.1",
"stripe": "^9.1.0",
"url-loader": "^4.1.1"
"url-loader": "^4.1.1",
"wait-on": "^8.0.1"
},
"devDependencies": {
"@beckn-ui/prettier-config": "workspace:^",
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"dev:retail": "yarn workspace @beckn-ui/retail dev",
"build:retail": "yarn workspace @beckn-ui/retail build",
"start:retail": "yarn workspace @beckn-ui/retail start",
"e2e-run:retail": "yarn workspace @beckn-ui/retail cy:run",
"e2e-open:retail": "yarn workspace @beckn-ui/retail cy:open",
"dev:mobility-bap": "yarn workspace @beckn-ui/mobility-bap dev",
"build:mobility-bap": "yarn workspace @beckn-ui/mobility-bap build",
"start:mobility-bap": "yarn workspace @beckn-ui/mobility-bap start",
Expand Down Expand Up @@ -96,9 +98,14 @@
"@types/googlemaps": "^3.43.3",
"@types/mongoose": "^5.11.97",
"eslint-config-next": "latest",
"mocha": "^10.7.3",
"mochawesome": "link:./null",
"mochawesome-merge": "link:./null",
"mochawesome-report-generator": "link:./null",
"mongodb": "^6.2.0",
"mongoose": "^8.0.0",
"uuid": "^9.0.1"
"uuid": "^9.0.1",
"wait-on": "link:./null"
},
"devDependencies": {
"@beckn-ui/prettier-config": "workspace:^",
Expand Down
Loading