Skip to content

Commit

Permalink
bonus 54
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Nov 23, 2023
1 parent 52c1076 commit 6079ee2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 35 deletions.
34 changes: 0 additions & 34 deletions cypress/e2e/cart/add-to-cart.cy.ts

This file was deleted.

31 changes: 31 additions & 0 deletions cypress/e2e/inventory/sort-pom.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { LoginPage } from '@support/pages/login.page'
import { LoginInfo } from '..'

const SortingPOM = {
sortBy(order: 'az' | 'za' | 'lohi' | 'hilo') {
// select the sorting order using the <select> element
cy.get('select[data-test=product_sort_container]').select(order)
// once the sorting changes
// get the selected option text
// and save it as alias "sortName"
//
// alternative: get the .active_option element's text
// cy.get('.active_option').invoke('text').as('sortName')
},
}

describe('Products', { viewportHeight: 1600 }, () => {
const user: LoginInfo = Cypress.env('users').standard
beforeEach(() => {
LoginPage.login(user.username, user.password)

cy.visit('/inventory.html', { failOnStatusCode: false })
cy.location('pathname').should('equal', '/inventory.html')
})

it('sorts the items and shows the sorting order', () => {
SortingPOM.sortBy('lohi')
// confirm the sorting name shown below the products
// is the same as selected text in the alias "sortName"
})
})
18 changes: 17 additions & 1 deletion src/pages/Inventory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import { sortAsc, sortDesc, sortHiLo, sortLoHi } from '../utils/Sorting'
import Select from '../components/Select'
import './Inventory.css'

const sortingValues = {
az: 'Name (A to Z)',
za: 'Name (Z to A)',
lohi: 'Price (low to high)',
hilo: 'Price (high to low)',
}

const Inventory = () => {
const [inventoryList, setInventoryList] = useState(
sortAsc(InventoryData, 'name'),
Expand Down Expand Up @@ -75,7 +82,11 @@ const Inventory = () => {
/>
<div id="inventory_container">
<div>
<div id="inventory_container" className="inventory_container">
<div
id="inventory_container"
className="inventory_container"
data-test="InventoryPage"
>
<div className="inventory_list">
{inventoryList.map((item, i) => {
return (
Expand All @@ -86,6 +97,7 @@ const Inventory = () => {
name={item.name}
desc={item.desc}
price={item.price}
dataTestId="InventoryPageItem"
/>
)
})}
Expand All @@ -94,6 +106,10 @@ const Inventory = () => {
</div>
</div>
</div>
<center>
Items were sorted using{' '}
<span data-test="sorting-name">{sortingValues[activeOption]}</span> sort
</center>
<SwagLabsFooter />
</div>
)
Expand Down

0 comments on commit 6079ee2

Please sign in to comment.