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

hours validation #57

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Binary file modified cypress/fixtures/pickups.xls
Binary file not shown.
3 changes: 2 additions & 1 deletion cypress/support/api_testcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ export function setIntialPickupPoints(response) {

export function listallPickupPointsAPI() {
it('List all pickup points via API', updateRetry(2), () => {
cy.addDelayBetweenRetries(2000)
cy.addDelayBetweenRetries(10000)
cy.getVtexItems().then((vtex) => {
cy.getAPI(getPickupPoints(vtex.baseUrl)).then((response) => {
expect(response.status).to.equal(200)
cy.savePickupPoints(response.body)
setIntialPickupPoints(response)
})
})
Expand Down
6 changes: 6 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'cypress-file-upload'
import selectors from './common/selectors'
import storelocatorSelectors, { getAddressLink } from './selectors.js'
import { pickuppointsJsonFile } from './constants'

const storelocatorJson = '.storelocator.json'
const fileName = 'pickups.xls'
Expand All @@ -16,6 +17,11 @@ Cypress.Commands.add(
}
)

// Save pickupPoint
Cypress.Commands.add('savePickupPoints', (pickuppoints) => {
cy.writeFile(pickuppointsJsonFile, pickuppoints)
})

// Get pickupPoint
Cypress.Commands.add('getPickupPointItem', () => {
cy.readFile(storelocatorJson).then((items) => {
Expand Down
88 changes: 70 additions & 18 deletions cypress/support/common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { updateRetry } from './common/support'
import storeLocatorSelectors, { findPickupPoint } from './selectors.js'
import { INTIAL_PICKUP_POINTS_ENV } from './api_testcase'
import { pickuppointsJsonFile } from './constants'

export function addPickUpPoint(pickPointName) {
cy.visit('/admin/app/pickup-points')
Expand All @@ -27,6 +28,17 @@ export function addPickUpPoint(pickPointName) {
.contains('Changes saved')
}

function tConvert(timeString) {
const hourEnd = timeString.indexOf(':')
const H = +timeString.substr(0, hourEnd)
const h = H % 12 || 12
const ampm = H < 12 ? 'am' : 'pm'

timeString = h + timeString.substr(hourEnd, 3) + ampm

return timeString
}

export function clickLoadAllStores() {
cy.get('body').then(($body) => {
if ($body.find(storeLocatorSelectors.LoadStores).length) {
Expand All @@ -47,24 +59,64 @@ export function verifyAllPickUpPoint() {
'have.length',
pickupCount[INTIAL_PICKUP_POINTS_ENV] + 4
)
cy.get(storeLocatorSelectors.MoreItems)
.its('length')
.then((itemLen) => {
for (let i = 0; i < itemLen; i++) {
clickLoadAllStores()
cy.get(storeLocatorSelectors.MoreItems)
.eq(i)
.should('be.visible')
.click()
cy.get(storeLocatorSelectors.AddressContainer, {
timeout: 20000,
}).should('be.visible')
cy.get(storeLocatorSelectors.HoursContainer).should('be.visible')
cy.get(storeLocatorSelectors.BackToPickUpPoint)
.should('be.visible')
.click()
cy.get(storeLocatorSelectors.MoreItems).should('be.visible')
}
cy.contains('li', 'pickup example 1')
.invoke('index')
.then((i) => {
cy.get(storeLocatorSelectors.MoreItems)
.eq(i)
.scrollIntoView()
.should('be.visible')
.click()
cy.get(storeLocatorSelectors.HourRow).then(($els) => {
const pickupPoins = [...$els].map((el) => el.innerText)
const pickupPointsHours = pickupPoins.map((name) => name.split(':\n'))

cy.readFile(pickuppointsJsonFile).then((pp) => {
const filterPickupPoint = pp.filter(
(p) => p.name === 'pickup example 1'
)

const [{ businessHours }] = filterPickupPoint

// eslint-disable-next-line array-callback-return
businessHours.map((ba) => {
if (ba.dayOfWeek === 1) {
const dayOfWeek = pickupPointsHours.filter(
(day) => day[0] === 'Monday'
)

const startTime = tConvert(ba.openingTime)
const endTime = tConvert(ba.closingTime)

expect(dayOfWeek[0][1]).to.be.equal(
`0${startTime} - ${endTime}`
)
} else if (ba.dayOfWeek === 2) {
const dayOfWeek = pickupPointsHours.filter(
(day) => day[0] === 'Tuesday'
)

const startTime = tConvert(ba.openingTime)
const endTime = tConvert(ba.closingTime)

expect(dayOfWeek[0][1]).to.be.equal(
`0${startTime} - ${endTime}`
)
} else if (ba.dayOfWeek === 5) {
const dayOfWeek = pickupPointsHours.filter(
(day) => day[0] === 'Friday'
)

const startTime = tConvert(ba.openingTime)
const endTime = tConvert(ba.closingTime)

expect(dayOfWeek[0][1]).to.be.equal(
`0${startTime} - ${endTime}`
)
}
})
})
})
})
})
}
Expand Down
3 changes: 3 additions & 0 deletions cypress/support/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
pickuppointsJsonFile: '.pickuppoints.json',
}
3 changes: 3 additions & 0 deletions cypress/support/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default {
LoadStores: 'span[class*=loadAll]',
MoreItems: 'span[class*=addressListLink]',
AddressContainer: 'div[class*=addressContainer]',
Hours: '.vtex-store-locator-0-x-hoursContainer',
shashidhar85 marked this conversation as resolved.
Show resolved Hide resolved
StoreName: 'div[class*=store-storedetail] div[class*=storeName]',
HourRow: 'div[class*=hourRow]',
BackToPickUpPoint: 'span[class*=backlink]',
VtexButton: '.vtex-button',
UploadInput: 'input[type=file]',
Expand Down