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

[ENGINEERS-1070] - Verifying Reviews are sorted By DateTime using Xls doc #240

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Improved selectors and sorting
- In xls doc, verifying reviews are returned in sorted order

### Added

- For verifiedPurchaser testcase, added HasShopperReviewed intercept
Expand Down
28 changes: 22 additions & 6 deletions cy-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ workspace:
wipe:
enabled: true
stopOnFail: false
specs:
- cypress/integration/wipe.spec.js
specs:
- cypress/integration/wipe.spec.js
teardown:
enabled: true

Expand Down Expand Up @@ -161,6 +161,22 @@ strategy:
- cypress/integration/2.4.2-signed_in_user.spec.js
dependency:
- cypress/integration/2.4.1-anonymous_user.spec.js
# Verify reviews are sorted in dateTime format
Reviews_sorting:
enabled: true
sendDashboard: true
hardTries: 1
stopOnFail: false
parallel: true
specs:
- cypress/integration/2.4.3-verify_date_search_sorting.spec.js
dependency:
- cypress/integration/2.1.1-anonymous_user.spec.js
- cypress/integration/2.1.2-signed_in_user.spec.js
- cypress/integration/2.2.3-signed_in_user.spec.js
- cypress/integration/2.3.1-anonymous_user.spec.js
- cypress/integration/2.3.2-signed_in_user.spec.js
- cypress/integration/2.4.2-signed_in_user.spec.js
rest_api_testcase:
enabled: true
sendDashboard: true
Expand All @@ -170,9 +186,9 @@ strategy:
specs:
- cypress/integration/2.5-rest_apis.spec.js
dependency:
- cypress/integration/2.1.2-signed_in_user.spec.js
- cypress/integration/2.1.3-verify_review_with_signed_user.spec.js
- cypress/integration/2.4.2-signed_in_user.spec.js
- cypress/integration/2.1.2-signed_in_user.spec.js
- cypress/integration/2.1.3-verify_review_with_signed_user.spec.js
- cypress/integration/2.4.2-signed_in_user.spec.js
graphql_api_testcase:
enabled: true
sendDashboard: true
Expand Down Expand Up @@ -232,4 +248,4 @@ strategy:
- cypress/integration/2.7.4-disable_display_settings_&_verify_with_signed_in_user.spec.js
dependency:
- cypress/integration/2.6-graphql.spec.js
- cypress/integration/2.5-rest_apis.spec.js
- cypress/integration/2.5-rest_apis.spec.js
23 changes: 23 additions & 0 deletions cypress/integration/2.4.3-verify_date_search_sorting.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { loginViaCookies, updateRetry } from '../support/common/support.js'
import { selectDate, verifyExcelFile } from '../support/testcase.js'
// import rrselectors from '../support/selectors'

const fileName = 'cypress/downloads/reviews.xls'
const date = new Date()
const currentDate = date.getUTCDate()

describe('verify sorting for reviews', () => {
loginViaCookies({ storeFrontCookie: false })

it('Download reviews for some dates', updateRetry(2), () => {
cy.getVtexItems().then(vtex => {
cy.visit(`${vtex.baseUrl}/admin/app/reviews-ratings/download`)
cy.contains('Reviews')
selectDate({ day: currentDate, position: 1 })
cy.contains('Apply').click()
cy.get('.pa1 > .vtex-button').click()
})
})

verifyExcelFile(fileName)
})
24 changes: 5 additions & 19 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
const readXlsx = require('./read-xlsx')

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (_on, _config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
module.exports = on => {
on('task', {
readXlsx: readXlsx.read,
})
}
14 changes: 14 additions & 0 deletions cypress/plugins/read-xlsx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs')

const XLSX = require('xlsx')

const read = ({ file, sheet }) => {
const buf = fs.readFileSync(file)
const workbook = XLSX.read(buf, { type: 'buffer' })

return XLSX.utils.sheet_to_json(workbook.Sheets[sheet])
}

module.exports = {
read,
}
7 changes: 7 additions & 0 deletions cypress/support/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ export default {
GetReviewByIndex: index => {
return `div[class*=reviewCommentsContainer] div[class*=reviewComment]:nth-child(${index}) div[class*=reviewCommentRating] span[class*=filled]`
},
Download: 'div[class*=pal] > .vtex-button',
FromDate: position => {
return `:nth-child(${position}) > div[class*=wrapper] > div[class*=input-container] > label[class*=input] > div[class*=input-prefix__group] > input[class*=input]`
},
SelectDate: day => {
return `div[class*=datepicker__day--0${day}]`
},
}
26 changes: 26 additions & 0 deletions cypress/support/testcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,29 @@ export function verifyAverageRatings(product, user) {
cy.getAverageRating(user, product)
})
}

export function selectDate({ day, position }) {
cy.get(rrselectors.FromDate(position)).click()
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(1000)
cy.get(rrselectors.SelectDate(day)).click()
}

export function verifyExcelFile(fileName) {
it('verify the data and extension', updateRetry(3), () => {
cy.task('readXlsx', {
file: fileName,
sheet: 'Sheet1',
}).then(rows => {
expect(rows.length).to.be.equal(6)
const sheetData = rows.slice()
const sortedData = rows.sort(
(a, b) => new Date(a.Time) - new Date(b.Time)
)

sheetData.forEach((_, index) => {
expect(sheetData[index].Time).to.be.equal(sortedData[index].Time)
})
})
})
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
"dependencies": {
"xlsx": "^0.17.3"
}
}
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ acorn@^7.1.1:
adler-32@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/adler-32/-/adler-32-1.2.0.tgz#6a3e6bf0a63900ba15652808cb15c6813d1a5f25"
integrity sha1-aj5r8KY5ALoVZSgIyxXGgT0aXyU=
integrity sha512-/vUqU/UY4MVeFsg+SsK6c+/05RZXIHZMGJA+PX5JyWI0ZRcBpupnRuPLU/NXXoFwMYCPCoxIfElM2eS+DUXCqQ==
dependencies:
exit-on-epipe "~1.0.1"
printj "~1.1.0"
Expand Down