Skip to content

Commit

Permalink
Move intercept to traverseRoutes
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbay-bluetiger committed Dec 9, 2024
1 parent fe3cbb0 commit 024f3e4
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions tests/cypress/e2e/mcpar/form.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,30 @@ function fillOutPartialMCPAR() {
cy.get('a[href*="review-and-submit"]').click();
}

const traverseRoutes = (routes) => {
//iterate over each route
routes.forEach((route) => {
traverseRoute(route);
});
const traverseRoutes = (routes, flags) => {
function continueTraversing(existingFlags) {
//iterate over each route
routes.forEach((route) => {
// Flag is defined in mcpar.json and doesn't exist in Launch Darkly response
if (route.flag && !existingFlags[route.flag]) return;
traverseRoute(route, existingFlags);
});
}

if (!flags) {
// Intercept Launch Darkly request first time only
cy.intercept(/launchdarkly/).as("ld");
cy.wait("@ld").then(({ request }) => {
continueTraversing(request.body[0].features);
});
} else {
// Reset intercept
cy.intercept(/launchdarkly/, (req) => req.continue());
continueTraversing(flags);
}
};

const continueTraversing = (route) => {
const traverseRoute = (route, flags) => {
//only perform checks on route if it contains some time of form fill
if (route.form || route.modalForm || route.drawerForm) {
//validate we are on the URL we expect to be
Expand All @@ -149,22 +165,7 @@ const continueTraversing = (route) => {
}

//If this route has children routes, traverse those as well
if (route.children) traverseRoutes(route.children);
};

const traverseRoute = (route) => {
if (route.flag) {
cy.intercept(/launchdarkly/).as("ld");
cy.wait("@ld").then(({ request }) => {
const flags = request.body[0].features;
if (!flags[route.flag]) {
return;
}
continueTraversing(route);
});
} else {
continueTraversing(route);
}
if (route.children) traverseRoutes(route.children, flags);
};

const completeDrawerForm = (drawerForm) => {
Expand Down

0 comments on commit 024f3e4

Please sign in to comment.