diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e296fa3..dee427e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cy-runner.yml b/cy-runner.yml index dcea653c..0e93a4ee 100644 --- a/cy-runner.yml +++ b/cy-runner.yml @@ -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 @@ -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 @@ -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 @@ -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 \ No newline at end of file + - cypress/integration/2.5-rest_apis.spec.js diff --git a/cypress/integration/2.4.3-verify_date_search_sorting.spec.js b/cypress/integration/2.4.3-verify_date_search_sorting.spec.js new file mode 100644 index 00000000..8f6c1254 --- /dev/null +++ b/cypress/integration/2.4.3-verify_date_search_sorting.spec.js @@ -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) +}) diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index 9f8a21ec..96baa098 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -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, + }) } diff --git a/cypress/plugins/read-xlsx.js b/cypress/plugins/read-xlsx.js new file mode 100644 index 00000000..49dcf6ee --- /dev/null +++ b/cypress/plugins/read-xlsx.js @@ -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, +} diff --git a/cypress/support/selectors.js b/cypress/support/selectors.js index db7531e5..cca298a6 100644 --- a/cypress/support/selectors.js +++ b/cypress/support/selectors.js @@ -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}]` + }, } diff --git a/cypress/support/testcase.js b/cypress/support/testcase.js index 3b6b86e4..77168f03 100644 --- a/cypress/support/testcase.js +++ b/cypress/support/testcase.js @@ -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) + }) + }) + }) +} diff --git a/package.json b/package.json index de225b71..6891c28b 100644 --- a/package.json +++ b/package.json @@ -38,4 +38,4 @@ "dependencies": { "xlsx": "^0.17.3" } -} \ No newline at end of file +} diff --git a/yarn.lock b/yarn.lock index b9a39f80..9b00f14b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"