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.
6 changes: 6 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import storelocatorSelectors, {

const storelocatorJson = '.storelocator.json'
const fileName = 'pickups.xls'
const pickuppointsJson = '.pickuppoints.json'

// Save pickupPoint
Cypress.Commands.add(
Expand All @@ -20,6 +21,11 @@ Cypress.Commands.add(
}
)

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

// Get pickupPoint
Cypress.Commands.add('getPickupPointItem', () => {
cy.readFile(storelocatorJson).then((items) => {
Expand Down
1 change: 1 addition & 0 deletions cypress/support/store-locator.apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function listallPickupPointsAPI() {
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
70 changes: 70 additions & 0 deletions cypress/support/storelocator.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import storeLocatorSelectors, {
} from './storelocator.selectors'
import { INTIAL_PICKUP_POINTS_ENV } from './store-locator.apis'

const pickuppointsJson = '.pickuppoints.json'
shashidhar85 marked this conversation as resolved.
Show resolved Hide resolved

export function addPickUpPoint(pickPointName) {
cy.visit('/admin/app/pickup-points')

Expand All @@ -29,6 +31,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 verifyAllPickUpPoint() {
cy.visitStore()
cy.get(storeLocatorSelectors.ListOfStores).should('be.visible')
Expand All @@ -52,6 +65,63 @@ export function verifyAllPickUpPoint() {
timeout: 20000,
}).should('be.visible')
cy.get(storeLocatorSelectors.Hours).should('be.visible')
cy.get('div[class*=store-storedetail] div[class*=storeName]')
shashidhar85 marked this conversation as resolved.
Show resolved Hide resolved
.invoke('text')
.then((text) => {
if (text === 'pickup example 1') {
cy.get('div[class*=hourRow]').then(($els) => {
const pickupPoins = [...$els].map((el) => el.innerText)
const pickupPointsHours = pickupPoins.map((name) =>
name.split(':\n')
)

cy.log(pickupPointsHours)
shashidhar85 marked this conversation as resolved.
Show resolved Hide resolved
cy.readFile(pickuppointsJson).then((pp) => {
const filterPickupPoint = pp.filter((p) => p.name === text)
// eslint-disable-next-line prefer-destructuring
const { businessHours } = filterPickupPoint[0]
shashidhar85 marked this conversation as resolved.
Show resolved Hide resolved

// 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}`
)
}
})
})
})
}
})
cy.get(storeLocatorSelectors.BackToPickUpPoint)
.should('be.visible')
.click()
Expand Down