Skip to content

Commit

Permalink
Update cypress and add cypress-multi-reporters (forem#20085)
Browse files Browse the repository at this point in the history
Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com>
Co-authored-by: Mac Siri <[email protected]>
  • Loading branch information
depfu[bot] and Mac Siri authored Sep 12, 2023
1 parent 3f92292 commit 5793f71
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 91 deletions.
2 changes: 1 addition & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
config.cache_classes = false

# See https://github.com/rails/rails/issues/40613#issuecomment-727283155
config.action_view.cache_template_loading = true
config.action_view.cache_template_loading = false

# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
Expand Down
4 changes: 2 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ module.exports = defineConfig({
trashAssetsBeforeRuns: false,
video: false,
retries: 3,
reporter: 'junit',
reporter: 'cypress-multi-reporters',
reporterOptions: {
mochaFile: 'cypress/results/results-[hash].xml',
configFile: 'cypress/reporter-config.json',
},
},
});
101 changes: 32 additions & 69 deletions cypress/e2e/seededFlows/articleFlows/postModerationTools.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,14 @@ describe('Moderation Tools for Posts', () => {
});
});

it('should show Unfeature Post button on a featured post', () => {
it('should show Unfeature Post button and unpublish post button on a featured post', () => {
cy.get('@adminUser').then((user) => {
cy.loginAndVisit(user, '/admin_mcadmin/test-article-slug').then(() => {
cy.findByRole('button', { name: 'Moderation' }).click();

cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Unfeature Post' }).should('exist');
});
});
});
});

it('should show Unpublish Post button on a published post', () => {
cy.get('@adminUser').then((user) => {
cy.loginAndVisit(user, '/admin_mcadmin/test-article-slug').then(() => {
cy.findByRole('button', { name: 'Moderation' }).click();

cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Unpublish Post' }).should('exist');
Expand All @@ -102,10 +94,26 @@ describe('Moderation Tools for Posts', () => {
cy.fixture('users/moderatorUser.json').as('moderatorUser');
});

it('should load moderation tools on a post', () => {
it('show the correct things', () => {
cy.get('@moderatorUser').then((user) => {
cy.loginAndVisit(user, '/admin_mcadmin/test-article-slug').then(() => {
// should load moderation tools on a post
cy.findByRole('button', { name: 'Moderation' }).should('exist');

// should show Unpublish Post button on a published post
cy.findByRole('button', { name: 'Moderation' }).click();
cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Unpublish Post' }).should('exist');
});

// should show Adjust tags button on a published post
cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
// We use `pipe` here to retry the click, as the animation of the mod tools opening can sometimes cause the button to not be ready yet
cy.findByRole('button', { name: 'Open adjust tags section' })
.as('adjustTagsButton')
.pipe(click)
.should('have.attr', 'aria-expanded', 'true');
});
});
});
});
Expand All @@ -128,34 +136,6 @@ describe('Moderation Tools for Posts', () => {
});
});

it('should show Unpublish Post button on a published post', () => {
cy.get('@moderatorUser').then((user) => {
cy.loginAndVisit(user, '/admin_mcadmin/test-article-slug').then(() => {
cy.findByRole('button', { name: 'Moderation' }).click();

cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Unpublish Post' }).should('exist');
});
});
});
});

it('should show Adjust tags button on a published post', () => {
cy.get('@moderatorUser').then((user) => {
cy.loginAndVisit(user, '/admin_mcadmin/test-article-slug').then(() => {
cy.findByRole('button', { name: 'Moderation' }).click();

cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
// We use `pipe` here to retry the click, as the animation of the mod tools opening can sometimes cause the button to not be ready yet
cy.findByRole('button', { name: 'Open adjust tags section' })
.as('adjustTagsButton')
.pipe(click)
.should('have.attr', 'aria-expanded', 'true');
});
});
});
});

context('when unpublishing all posts', () => {
beforeEach(() => {
cy.get('@moderatorUser').then((user) => {
Expand Down Expand Up @@ -345,65 +325,48 @@ describe('Moderation Tools for Posts', () => {
cy.fixture('users/trustedUser.json').as('trustedUser');
});

it('should load moderation tools on a post', () => {
it('should load appropriate moderation tools on a post', () => {
cy.get('@trustedUser').then((user) => {
cy.loginAndVisit(user, '/admin_mcadmin/test-article-slug').then(() => {
cy.findByRole('button', { name: 'Moderation' }).should('exist');
});
});
});

it('should not show Feature Post button on a post', () => {
cy.get('@trustedUser').then((user) => {
cy.loginAndVisit(user, '/admin_mcadmin/unfeatured-article-slug').then(
() => {
cy.findByRole('button', { name: 'Moderation' }).click();
cy.findByRole('button', { name: 'Moderation' }).click();

cy.getIframeBody('[title="Moderation panel actions"]').within(
() => {
cy.findByRole('button', { name: 'Feature Post' }).should(
'not.exist',
);
},
);
},
);
// should not show Feature Post button on a post
cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Feature Post' }).should('not.exist');
});
});
});

describe('flag-user flow', () => {
beforeEach(() => {
cy.get('@trustedUser').then((user) => {
cy.loginAndVisit(user, '/admin_mcadmin/test-article-slug');
cy.findByRole('heading', { level: 1, name: 'Test article' });
cy.findByRole('button', { name: 'Moderation' }).click();
cy.loginAndVisit(user, '/admin_mcadmin/test-article-slug').then(
() => {
cy.findByRole('heading', { level: 1, name: 'Test article' });
cy.findByRole('button', { name: 'Moderation' }).click();
},
);
});
});

it('should show error message if flag-user radio is unchecked', () => {
it('should flag the user', () => {
cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Open admin actions' })
.as('moderatingActionsButton')
.pipe(click)
.should('have.attr', 'aria-expanded', 'true');
cy.findByRole('button', { name: 'Flag admin_mcadmin' }).click();
});
// should show error message if flag-user radio is unchecked
cy.getModal().within(() => {
cy.findByRole('button', { name: 'Confirm Flag' }).click();
cy.findByTestId('unselected-radio-error')
.contains('You must check the radio button first.')
.should('exist');
});
});

it('should flag the user if flag-user radio is checked', () => {
cy.getIframeBody('[title="Moderation panel actions"]').within(() => {
cy.findByRole('button', { name: 'Open admin actions' })
.as('moderatingActionsButton')
.pipe(click)
.should('have.attr', 'aria-expanded', 'true');
cy.findByRole('button', { name: 'Flag admin_mcadmin' }).click();
});

cy.getModal().within(() => {
const flagUserRadioName =
Expand Down
6 changes: 6 additions & 0 deletions cypress/reporter-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"reporterEnabled": "spec, mocha-junit-reporter",
"mochaJunitReporterReporterOptions": {
"mochaFile": "cypress/results/results-[hash].xml"
}
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@
"babel-loader": "^8.2.5",
"css-loader": "^5.2.7",
"cssom": "^0.5.0",
"cypress": "^12.17.4",
"cypress": "^13.1.0",
"cypress-failed-log": "^2.10.0",
"cypress-file-upload": "^5.0.8",
"cypress-multi-reporters": "^1.6.3",
"cypress-pipe": "^2.0.0",
"eslint": "^8.48.0",
"eslint-config-preact": "^1.3.0",
Expand All @@ -95,6 +96,7 @@
"jsdom": "^20.0.1",
"lint-staged": "^13.3.0",
"markdown-loader": "^7.0.0",
"mocha-junit-reporter": "^2.2.1",
"prettier": "^2.8.8",
"sass": "1.54.0",
"sass-loader": "^13.3.2",
Expand Down
79 changes: 61 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2500,10 +2500,10 @@
js-yaml "4.1.0"
nyc "15.1.0"

"@cypress/request@2.88.12":
version "2.88.12"
resolved "https://registry.yarnpkg.com/@cypress/request/-/request-2.88.12.tgz#ba4911431738494a85e93fb04498cb38bc55d590"
integrity sha512-tOn+0mDZxASFM+cuAP9szGUGPI1HwWVSvdzm7V4cCsPdFTx6qMj29CwaQmRAMIEhORIUBFBsYROYJcveK4uOjA==
"@cypress/request@^3.0.0":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@cypress/request/-/request-3.0.1.tgz#72d7d5425236a2413bd3d8bb66d02d9dc3168960"
integrity sha512-TWivJlJi8ZDx2wGOw1dbLuHJKUYX7bWySw377nlnGOW3hP9/MUKIsEdXT/YngWxVdgNCHRBmFlBipE+5/2ZZlQ==
dependencies:
aws-sign2 "~0.7.0"
aws4 "^1.8.0"
Expand All @@ -2518,7 +2518,7 @@
json-stringify-safe "~5.0.1"
mime-types "~2.1.19"
performance-now "^2.1.0"
qs "~6.10.3"
qs "6.10.4"
safe-buffer "^5.1.2"
tough-cookie "^4.1.3"
tunnel-agent "^0.6.0"
Expand Down Expand Up @@ -6692,6 +6692,11 @@ character-reference-invalid@^1.0.0:
resolved "https://registry.yarnpkg.com/character-reference-invalid/-/character-reference-invalid-1.1.4.tgz#083329cda0eae272ab3dbbf37e9a382c13af1560"
integrity sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==

[email protected]:
version "0.0.2"
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"
integrity sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==

chart.js@^3.9.1:
version "3.9.1"
resolved "https://registry.yarnpkg.com/chart.js/-/chart.js-3.9.1.tgz#3abf2c775169c4c71217a107163ac708515924b8"
Expand Down Expand Up @@ -7329,6 +7334,11 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
shebang-command "^2.0.0"
which "^2.0.1"

[email protected]:
version "0.0.2"
resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"
integrity sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==

crypto-browserify@^3.11.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.12.0.tgz#396cf9f3137f03e4b8e532c58f698254e00f80ec"
Expand Down Expand Up @@ -7639,17 +7649,25 @@ cypress-file-upload@^5.0.8:
resolved "https://registry.yarnpkg.com/cypress-file-upload/-/cypress-file-upload-5.0.8.tgz#d8824cbeaab798e44be8009769f9a6c9daa1b4a1"
integrity sha512-+8VzNabRk3zG6x8f8BWArF/xA/W0VK4IZNx3MV0jFWrJS/qKn8eHfa5nU73P9fOQAgwHFJx7zjg4lwOnljMO8g==

cypress-multi-reporters@^1.6.3:
version "1.6.3"
resolved "https://registry.yarnpkg.com/cypress-multi-reporters/-/cypress-multi-reporters-1.6.3.tgz#0f0da8db4caf8d7a21f94e5209148348416d7c71"
integrity sha512-klb9pf6oAF4WCLHotu9gdB8ukYBdeTzbEMuESKB3KT54HhrZj65vQxubAgrULV5H2NWqxHdUhlntPbKZChNvEw==
dependencies:
debug "^4.3.4"
lodash "^4.17.21"

cypress-pipe@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/cypress-pipe/-/cypress-pipe-2.0.0.tgz#577df7a70a8603d89a96dfe4092a605962181af8"
integrity sha512-KW9s+bz4tFLucH3rBGfjW+Q12n7S4QpUSSyxiGrgPOfoHlbYWzAGB3H26MO0VTojqf9NVvfd5Kt0MH5XMgbfyg==

cypress@^12.17.4:
version "12.17.4"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-12.17.4.tgz#b4dadf41673058493fa0d2362faa3da1f6ae2e6c"
integrity sha512-gAN8Pmns9MA5eCDFSDJXWKUpaL3IDd89N9TtIupjYnzLSmlpVr+ZR+vb4U/qaMp+lB6tBvAmt7504c3Z4RU5KQ==
cypress@^13.1.0:
version "13.1.0"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-13.1.0.tgz#18f268e66662cd91b1766db18bd1f63a66592205"
integrity sha512-LUKxCYlB973QBFls1Up4FAE9QIYobT+2I8NvvAwMfQS2YwsWbr6yx7y9hmsk97iqbHkKwZW3MRjoK1RToBFVdQ==
dependencies:
"@cypress/request" "2.88.12"
"@cypress/request" "^3.0.0"
"@cypress/xvfb" "^1.2.4"
"@types/node" "^16.18.39"
"@types/sinonjs__fake-timers" "8.1.1"
Expand Down Expand Up @@ -10655,7 +10673,7 @@ is-boolean-object@^1.1.0:
call-bind "^1.0.2"
has-tostringtag "^1.0.0"

is-buffer@^1.1.5:
is-buffer@^1.1.5, is-buffer@~1.1.6:
version "1.1.6"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==
Expand Down Expand Up @@ -12485,6 +12503,15 @@ md5.js@^1.3.4:
inherits "^2.0.1"
safe-buffer "^5.1.2"

md5@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/md5/-/md5-2.3.0.tgz#c3da9a6aae3a30b46b7b0c349b87b110dc3bda4f"
integrity sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==
dependencies:
charenc "0.0.2"
crypt "0.0.2"
is-buffer "~1.1.6"

mdast-squeeze-paragraphs@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/mdast-squeeze-paragraphs/-/mdast-squeeze-paragraphs-4.0.0.tgz#7c4c114679c3bee27ef10b58e2e015be79f1ef97"
Expand Down Expand Up @@ -12839,6 +12866,22 @@ mkdirp@^1.0.3, mkdirp@^1.0.4:
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

mkdirp@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-3.0.1.tgz#e44e4c5607fb279c168241713cc6e0fea9adcb50"
integrity sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==

mocha-junit-reporter@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/mocha-junit-reporter/-/mocha-junit-reporter-2.2.1.tgz#739f5595d0f051d07af9d74e32c416e13a41cde5"
integrity sha512-iDn2tlKHn8Vh8o4nCzcUVW4q7iXp7cC4EB78N0cDHIobLymyHNwe0XG8HEHHjc3hJlXm0Vy6zcrxaIhnI2fWmw==
dependencies:
debug "^4.3.4"
md5 "^2.3.0"
mkdirp "^3.0.0"
strip-ansi "^6.0.1"
xml "^1.0.1"

moment@>=1.6.0, moment@^2.29.4:
version "2.29.4"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108"
Expand Down Expand Up @@ -15098,20 +15141,20 @@ q@^1.1.2:
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
integrity sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==

[email protected]:
version "6.10.4"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.4.tgz#6a3003755add91c0ec9eacdc5f878b034e73f9e7"
integrity sha512-OQiU+C+Ds5qiH91qh/mg0w+8nwQuLjM4F4M/PbmhDOoYehPh+Fb0bDjtR1sOvy7YKxvj28Y/M0PhP5uVX0kB+g==
dependencies:
side-channel "^1.0.4"

[email protected], qs@^6.10.0:
version "6.11.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.0.tgz#fd0d963446f7a65e1367e01abd85429453f0c37a"
integrity sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==
dependencies:
side-channel "^1.0.4"

qs@~6.10.3:
version "6.10.5"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.5.tgz#974715920a80ff6a262264acd2c7e6c2a53282b4"
integrity sha512-O5RlPh0VFtR78y79rgcgKK4wbAI0C5zGVLztOIdpWX6ep368q5Hv6XRxDvXuZ9q3C6v+e3n8UfZZJw7IIG27eQ==
dependencies:
side-channel "^1.0.4"

query-string@^4.1.0:
version "4.3.4"
resolved "https://registry.yarnpkg.com/query-string/-/query-string-4.3.4.tgz#bbb693b9ca915c232515b228b1a02b609043dbeb"
Expand Down

0 comments on commit 5793f71

Please sign in to comment.