generated from Arquisoft/dede_0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from Arquisoft/develop
Cambios finales
- Loading branch information
Showing
18 changed files
with
527 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Feature: User consults distribution centers | ||
|
||
Scenario: User goes distribution centers page | ||
Given A user who founds the site | ||
When selects the distribution centers button | ||
Then is redirected to the distribution centers page |
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,6 @@ | ||
Feature: User log in | ||
|
||
Scenario: User goes to sign in page | ||
Given A user who founds the site | ||
When selects the Signin button on the top menu | ||
Then is redirected to the sign in page |
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 |
---|---|---|
@@ -1,52 +1,64 @@ | ||
import { defineFeature, loadFeature } from 'jest-cucumber'; | ||
import puppeteer from "puppeteer"; | ||
import { defineFeature, loadFeature } from 'jest-cucumber' | ||
import puppeteer from 'puppeteer' | ||
|
||
const feature = loadFeature('./features/add-to-cart.feature'); | ||
const feature = loadFeature('./features/add-to-cart.feature') | ||
|
||
let page: puppeteer.Page; | ||
let browser: puppeteer.Browser; | ||
jest.setTimeout(400000); | ||
let page: puppeteer.Page | ||
let browser: puppeteer.Browser | ||
jest.setTimeout(400000) | ||
|
||
defineFeature(feature, test => { | ||
|
||
defineFeature(feature, (test) => { | ||
beforeAll(async () => { | ||
browser = process.env.GITHUB_ACTIONS | ||
? await puppeteer.launch() | ||
: await puppeteer.launch({ headless: true }); | ||
page = await browser.newPage(); | ||
: await puppeteer.launch({ headless: true }) | ||
page = await browser.newPage() | ||
|
||
await page | ||
.goto("https://dede-es5a.herokuapp.com/", { | ||
waitUntil: "networkidle0", | ||
.goto('https://dede-es5a.herokuapp.com/', { | ||
waitUntil: 'networkidle0', | ||
timeout: 0, | ||
}) | ||
.catch(() => {console.log("Error while testing")}); | ||
}); | ||
|
||
test('User adds a product to the cart', ({given,when,then}) => { | ||
.catch(() => { | ||
console.log('Error while testing') | ||
}) | ||
}) | ||
|
||
test('User adds a product to the cart', ({ given, when, then }) => { | ||
given('A user who founds the site', () => { | ||
console.log('Checking product added...') | ||
}); | ||
|
||
when('He selects the product\'s size, he decides to add it to the cart', async () => { | ||
//Se selecciona la talla en el combobox | ||
await expect(page).toClick('div.MuiGrid-grid-xs-4:nth-child(1) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1)') | ||
await expect(page).toClick('#menu- > div:nth-child(3) > ul:nth-child(1) > li:nth-child(1)') | ||
|
||
//Se hace click para añadir al carrito | ||
await expect(page).toClick('div.MuiGrid-grid-xs-4:nth-child(1) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > button:nth-child(2)') | ||
}); | ||
|
||
then('A confirmation message should be shown in the screen and the product is added', async () => { | ||
//Se muestra añadido | ||
await expect(page).toClick('.MuiBadge-root > button:nth-child(1)') | ||
await expect(page).toMatch('British') | ||
}); | ||
}) | ||
|
||
when( | ||
"He selects the product's size, he decides to add it to the cart", | ||
async () => { | ||
await Promise.all([ | ||
//Se selecciona la talla en el combobox | ||
await expect(page).toClick( | ||
'div.MuiGrid-grid-xs-4:nth-child(1) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div:nth-child(1)', | ||
), | ||
await expect(page).toClick( | ||
'#menu- > div:nth-child(3) > ul:nth-child(1) > li:nth-child(1)', | ||
), | ||
//Se hace click para añadir al carrito | ||
await expect(page).toClick( | ||
'div.MuiGrid-grid-xs-4:nth-child(1) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > button:nth-child(2)', | ||
), | ||
]) | ||
}, | ||
) | ||
|
||
then( | ||
'A confirmation message should be shown in the screen and the product is added', | ||
async () => { | ||
//Se muestra añadido | ||
await expect(page).toClick('.MuiBadge-root > button:nth-child(1)') | ||
await expect(page).toMatch('British') | ||
}, | ||
) | ||
}) | ||
|
||
afterAll(async ()=>{ | ||
afterAll(async () => { | ||
browser.close() | ||
}) | ||
|
||
}); | ||
|
||
}) |
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,46 @@ | ||
import { defineFeature, loadFeature } from 'jest-cucumber'; | ||
import puppeteer from "puppeteer"; | ||
|
||
const feature = loadFeature('./features/distribution-centers.feature'); | ||
|
||
let page: puppeteer.Page; | ||
let browser: puppeteer.Browser; | ||
|
||
defineFeature(feature, test => { | ||
|
||
beforeAll(async () => { | ||
browser = process.env.GITHUB_ACTIONS | ||
? await puppeteer.launch() | ||
: await puppeteer.launch({ headless: true }); | ||
page = await browser.newPage(); | ||
|
||
await page | ||
.goto("https://dede-es5a.herokuapp.com", { | ||
waitUntil: "networkidle0", | ||
}) | ||
.catch(() => { | ||
// This is intentional | ||
}); | ||
}); | ||
|
||
test('User goes distribution centers page', ({given,when,then}) => { | ||
jest.setTimeout(40000); | ||
|
||
given('A user who founds the site', () => { | ||
// This is intentional | ||
}); | ||
|
||
when('selects the distribution centers button', async () => { | ||
await page.goto("https://dede-es5a.herokuapp.com/distributionCenters") //There is a problem with the button click, I have to do it this way | ||
}); | ||
|
||
then('is redirected to the distribution centers page', async () => { | ||
await expect(page).toMatch('Oviedo') | ||
}); | ||
}) | ||
|
||
afterAll(async ()=>{ | ||
browser.close() | ||
}) | ||
}); | ||
|
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,50 @@ | ||
import { defineFeature, loadFeature } from 'jest-cucumber' | ||
import puppeteer from 'puppeteer' | ||
|
||
const feature = loadFeature('./features/signin.feature') | ||
|
||
let page: puppeteer.Page | ||
let browser: puppeteer.Browser | ||
jest.setTimeout(400000) | ||
|
||
defineFeature(feature, (test) => { | ||
beforeAll(async () => { | ||
browser = process.env.GITHUB_ACTIONS | ||
? await puppeteer.launch() | ||
: await puppeteer.launch({ headless: true }) | ||
page = await browser.newPage() | ||
|
||
await page | ||
.goto('https://dede-es5a.herokuapp.com/', { | ||
waitUntil: 'networkidle0', | ||
timeout: 0 | ||
}) | ||
.catch(() => { | ||
// This is intentional | ||
}) | ||
}) | ||
|
||
test('User goes to sign in page', ({ given, when, then }) => { | ||
given('A user who founds the site', () => { | ||
// This is intentional | ||
}) | ||
|
||
when('selects the Signin button on the top menu', async () => { | ||
await Promise.all([ | ||
(await page.$x('/html/body/div[1]/div/header/div/div/div[5]/button')) | ||
.at(0) | ||
?.click(), | ||
(await page.$x('/html/body/div[2]/div[3]/ul')).at(0)?.click(), | ||
page.waitForNavigation() | ||
]) | ||
}) | ||
|
||
then('is redirected to the sign in page', async () => { | ||
await expect(page).toMatch('WELCOME') | ||
}) | ||
}) | ||
|
||
afterAll(async () => { | ||
browser.close() | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,24 +1,79 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import { fireEvent, render, screen, waitFor } from '@testing-library/react' | ||
import { CartProvider } from '../../contexts/CartContext'; | ||
import { CartProduct } from '../../shared/shareddtypes' | ||
import CartItem from './CartItem' | ||
|
||
test('check order renders propertly', async () => { | ||
// Arrange | ||
const product: CartProduct = { | ||
_id: '1234', | ||
name: 'Blue', | ||
price: 5, | ||
size: '40', | ||
quantity: 45, | ||
image: '' | ||
} | ||
// Arrange | ||
const product: CartProduct = { | ||
_id: '1234', | ||
name: 'Blue', | ||
price: 5, | ||
size: '40', | ||
quantity: 45, | ||
image: '' | ||
} | ||
|
||
test('check cart item renders propertly', async () => { | ||
// Act | ||
render(<CartItem key={product._id} product={product} />) | ||
render(<CartProvider><CartItem key={product._id} product={product} /></CartProvider>) | ||
|
||
// Assert | ||
expect(screen.getByText(product.name)).toBeInTheDocument() | ||
expect(screen.getByText("Size " + product.size)).toBeInTheDocument() | ||
expect(screen.getByText(product.price + " €")).toBeInTheDocument() | ||
expect(screen.getByText(product.quantity)).toBeInTheDocument() | ||
}) | ||
|
||
test('add a unit of product while inside the cart', async () => { | ||
// Act | ||
render(<CartProvider><CartItem key={product._id} product={product} /></CartProvider>) | ||
|
||
// add | ||
let addButton = screen.getByRole('button', { | ||
name: 'add' | ||
}) | ||
fireEvent.click(addButton); | ||
|
||
// Assert | ||
expect(screen.getByText(product.name)).toBeInTheDocument() | ||
expect(screen.getByText("Size " + product.size)).toBeInTheDocument() | ||
expect(screen.getByText(product.price + " €")).toBeInTheDocument() | ||
waitFor(() => { | ||
expect(product.price + 1).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
test('remove a unit of product while inside the cart', async () => { | ||
// Act | ||
render(<CartProvider><CartItem key={product._id} product={product} /></CartProvider>) | ||
|
||
// remove | ||
let removeButton = screen.getByRole('button', { | ||
name: 'remove' | ||
}) | ||
fireEvent.click(removeButton); | ||
|
||
// Assert | ||
expect(screen.getByText(product.name)).toBeInTheDocument() | ||
expect(screen.getByText("Size " + product.size)).toBeInTheDocument() | ||
expect(screen.getByText(product.price + " €")).toBeInTheDocument() | ||
waitFor(() => { | ||
expect(product.price - 1).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
test('remove all units of a product while inside the cart', async () => { | ||
// Act | ||
render(<CartProvider><CartItem key={product._id} product={product} /></CartProvider>) | ||
|
||
// remove all | ||
let removeAllButton = screen.getByRole('button', { | ||
name: 'removeAll' | ||
}) | ||
fireEvent.click(removeAllButton); | ||
|
||
// Assert | ||
waitFor(() => { | ||
expect(screen.getByText(product.name)).not.toBeInTheDocument() | ||
}); | ||
}) |
Oops, something went wrong.