-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 [Frontend] 284 adding cypress e2e tests (#298)
- Loading branch information
Showing
27 changed files
with
3,080 additions
and
1,702 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { defineConfig } from 'cypress'; | ||
import dotEnv from 'dotenv'; | ||
import dotenvExpand from 'dotenv-expand'; | ||
import { resolve } from 'path'; | ||
|
||
const myEnv = dotEnv.config({ | ||
path: resolve(__dirname, '../../.env'), | ||
}); | ||
dotenvExpand.expand(myEnv); | ||
|
||
const { FRONTEND_ADDR = '', NODE_ENV, FRONTEND_PORT = '8080' } = process.env; | ||
|
||
const baseUrl = NODE_ENV === 'production' ? FRONTEND_ADDR : `http://localhost:${FRONTEND_PORT}`; | ||
|
||
export default defineConfig({ | ||
env: { | ||
baseUrl, | ||
}, | ||
e2e: { | ||
baseUrl, | ||
setupNodeEvents(on, config) { | ||
// implement node event listeners here | ||
}, | ||
supportFile: false, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { CypressFields, getElementByField } from '../../utils/Cypress'; | ||
|
||
describe('Checkout Flow', () => { | ||
beforeEach(() => { | ||
cy.visit('/'); | ||
}); | ||
|
||
it('should create an order with two items', () => { | ||
getElementByField(CypressFields.ProductCard).first().click(); | ||
getElementByField(CypressFields.ProductAddToCart).click(); | ||
|
||
getElementByField(CypressFields.CartItemCount).should('contain', '1'); | ||
|
||
cy.visit('/'); | ||
|
||
getElementByField(CypressFields.ProductCard).last().click(); | ||
getElementByField(CypressFields.ProductAddToCart).click(); | ||
|
||
getElementByField(CypressFields.CartItemCount).should('contain', '2'); | ||
|
||
getElementByField(CypressFields.CartIcon).click(); | ||
getElementByField(CypressFields.CartGoToShopping).click(); | ||
|
||
cy.location('href').should('match', /\/cart$/); | ||
|
||
getElementByField(CypressFields.CheckoutPlaceOrder).click(); | ||
|
||
cy.wait(5000); | ||
cy.location('href').should('match', /\/checkout/); | ||
getElementByField(CypressFields.CheckoutItem).should('have.length', 2); | ||
}); | ||
}); | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import getSymbolFromCurrency from 'currency-symbol-map'; | ||
import SessionGateway from '../../gateways/Session.gateway'; | ||
import { CypressFields, getElementByField } from '../../utils/Cypress'; | ||
|
||
describe('Home Page', () => { | ||
beforeEach(() => { | ||
cy.visit('/'); | ||
}); | ||
|
||
it('should validate the home page', () => { | ||
getElementByField(CypressFields.HomePage).should('exist'); | ||
getElementByField(CypressFields.ProductCard, getElementByField(CypressFields.ProductList)).should('have.length', 9); | ||
|
||
getElementByField(CypressFields.SessionId).should('contain', SessionGateway.getSession().userId); | ||
}); | ||
|
||
it('should change currency', () => { | ||
getElementByField(CypressFields.CurrencySwitcher).select('EUR'); | ||
getElementByField(CypressFields.ProductCard, getElementByField(CypressFields.ProductList)).should('have.length', 9); | ||
|
||
getElementByField(CypressFields.CurrencySwitcher).should('have.value', 'EUR'); | ||
|
||
getElementByField(CypressFields.ProductCard).should('contain', getSymbolFromCurrency('EUR')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { CypressFields, getElementByField } from '../../utils/Cypress'; | ||
|
||
describe('Product Detail Page', () => { | ||
beforeEach(() => { | ||
cy.visit('/'); | ||
}); | ||
|
||
it('should validate the product detail page', () => { | ||
getElementByField(CypressFields.ProductCard).first().click(); | ||
|
||
getElementByField(CypressFields.ProductDetail).should('exist'); | ||
getElementByField(CypressFields.ProductPicture).should('exist'); | ||
getElementByField(CypressFields.ProductName).should('exist'); | ||
getElementByField(CypressFields.ProductDescription).should('exist'); | ||
getElementByField(CypressFields.ProductAddToCart).should('exist'); | ||
|
||
getElementByField(CypressFields.ProductCard, getElementByField(CypressFields.RecommendationList)).should( | ||
'have.length', | ||
4 | ||
); | ||
getElementByField(CypressFields.Ad).should('exist'); | ||
}); | ||
|
||
it('should add item to cart', () => { | ||
getElementByField(CypressFields.ProductCard).first().click(); | ||
getElementByField(CypressFields.ProductAddToCart).click(); | ||
|
||
getElementByField(CypressFields.CartItemCount).should('contain', '1'); | ||
getElementByField(CypressFields.CartIcon).click(); | ||
|
||
getElementByField(CypressFields.CartDropdownItem).should('have.length', 1); | ||
}); | ||
}); | ||
|
||
export {}; |
Oops, something went wrong.