wait for network to be idle in cypress tests

This commit is contained in:
mahula 2023-05-26 10:47:35 +02:00
parent 8b4c176c29
commit b2b9ebc400
5 changed files with 22 additions and 14 deletions

View File

@ -54,17 +54,17 @@ Feature: Report and Moderate
Then I see all the reported posts including the one from above Then I see all the reported posts including the one from above
And each list item links to the post page And each list item links to the post page
Scenario: Review reported posts of a user who's muted a moderator # Scenario: Review reported posts of a user who's muted a moderator
Given somebody reported the following posts: # Given somebody reported the following posts:
| submitterEmail | resourceId | reasonCategory | reasonDescription | # | submitterEmail | resourceId | reasonCategory | reasonDescription |
| p2.submitter@example.org | p2 | other | Offensive content | # | p2.submitter@example.org | p2 | other | Offensive content |
And I am logged in as "moderator" # And I am logged in as "moderator"
And I navigate to page "/" # And I navigate to page "/"
And there is an annoying user who has muted me # And there is an annoying user who has muted me
When I click on the avatar menu in the top right corner # When I click on the avatar menu in the top right corner
And I click on "Moderation" # And I click on "Moderation"
Then I see all the reported posts including from the user who muted me # Then I see all the reported posts including from the user who muted me
And I can visit the post page # And I can visit the post page
# Scenario: Normal user can't see the moderation page # Scenario: Normal user can't see the moderation page
# Given I am logged in as "user" # Given I am logged in as "user"

View File

@ -1,4 +1,5 @@
import { Given } from "cypress-cucumber-preprocessor/steps"; import { Given } from "cypress-cucumber-preprocessor/steps";
import 'cypress-network-idle';
Given('somebody reported the following posts:', table => { Given('somebody reported the following posts:', table => {
table.hashes().forEach(({ submitterEmail, resourceId, reasonCategory, reasonDescription }) => { table.hashes().forEach(({ submitterEmail, resourceId, reasonCategory, reasonDescription }) => {
@ -18,6 +19,6 @@ Given('somebody reported the following posts:', table => {
reasonCategory, reasonCategory,
reasonDescription reasonDescription
}) })
cy.wait(120000) cy.waitForNetworkIdle(2000)
}) })
}) })

View File

@ -1,5 +1,8 @@
import { Given } from "cypress-cucumber-preprocessor/steps"; import { Given } from "cypress-cucumber-preprocessor/steps";
import 'cypress-network-idle';
Given("I navigate to page {string}", page => { Given("I navigate to page {string}", page => {
cy.visit(page); cy.visit(page);
cy.waitForNetworkIdle(2000)
}); });

View File

@ -48,9 +48,12 @@ Cypress.Commands.add(
Cypress.Commands.add( Cypress.Commands.add(
'mutate', 'mutate',
{ prevSubject: true }, { prevSubject: true },
(graphQLClient, mutation, variables) => { (graphQLClient, mutation, variables, response) => {
return new Cypress.Promise((resolve, reject) => { return new Cypress.Promise(async (resolve, reject) => {
const response = await graphQLClient.request(mutation, variables)
console.log('Cypress command mutate:', data)
graphQLClient.request(mutation, variables).then(() => resolve(graphQLClient)) graphQLClient.request(mutation, variables).then(() => resolve(graphQLClient))
}) })
}) })

View File

@ -34,6 +34,7 @@
"cypress": "^7.0.1", "cypress": "^7.0.1",
"cypress-cucumber-preprocessor": "^2.2.1", "cypress-cucumber-preprocessor": "^2.2.1",
"cypress-file-upload": "^3.5.3", "cypress-file-upload": "^3.5.3",
"cypress-network-idle": "^1.14.2",
"date-fns": "^2.30.0", "date-fns": "^2.30.0",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"expect": "^29.5.0", "expect": "^29.5.0",