docbrown/cypress/util/networkUtils.js
Suzanne Aitchison 75b6c8ed96
Use a single listener for all follow buttons on a page (#14246)
* create new pack, handle user follow buttons, use pack on article page, remove initializeUserFollowButts

* init all follow button types, add pack to tag index and podcast episode pages

* add pack to all relevant pages, listen for newly inserted follow buttons

* change to searchParams to remove follow button initializer calls

* fix bug with tag page, add pack to notifications page

* fix issue with follow back inner text

* update cypress specs

* run the followbuttons code on sponsors page

* remove extra foreach

* add test for follow from article sidebar

* add test for follow and unfollow tag

* add test for the tag index page

* add spec for organisation profile follow

* add tests for follow buttons in search results

* add tests for notification follows

* commit missed file - woops

* show login modal if user is logged out when they click

* add cypress tests for logged out state

* change tag button initialization

* remove data-button-initialized

* init follow buttons from base pack

* handle the case where multiple follow buttons exist on a page for the same user

* account for instantclick and userdata not being defined, lower coverage for jest

* use getInstantClick

* fix issue with set initialisation

* only listen for mutations in areas we know follow buttons may be added dynamically

* small refactors
2021-07-27 10:45:50 +01:00

36 lines
1.2 KiB
JavaScript

/**
* Helper function to intercept any network requests which may interfere with user state between user log in/out.
* Any intercepts which should be awaited are aliased and returned in an array.
*
* @param {Boolean} userLoggedIn Whether or not the user state is transitioning to logged in - defaults to false
* @returns {Array} Array of aliased Cypress intercepts which may be awaited to ensure they run to completion
*/
export const getInterceptsForLingeringUserRequests = (
url,
userLoggedIn = false,
) => {
// Stub these as response not needed to test app functionality
cy.intercept('/api/analytics/historical**', {});
cy.intercept('/api/analytics/referrers**', {});
// Await these requests as response may affect app behavior
cy.intercept('/async_info/base_data').as('baseDataRequest');
if (!userLoggedIn) {
return ['@baseDataRequest'];
}
cy.intercept('/chat_channels**').as('chatRequest');
const intercepts = ['@baseDataRequest', '@chatRequest'];
if (!url.includes('/notifications')) {
cy.intercept('/notifications?i=i').as('notificationsRequest');
cy.intercept('/notifications/counts').as('countsRequest');
intercepts.push('@notificationsRequest');
intercepts.push('@countsRequest');
}
return intercepts;
};