Skip to content

Commit

Permalink
cypress: Replace obsolete Cypress.Cookies.preserveOnce
Browse files Browse the repository at this point in the history
  • Loading branch information
mamedin committed Sep 28, 2023
1 parent ed01b64 commit c5a4a4e
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions cypress/e2e/finding_aid.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,30 @@ describe(
})
})


beforeEach(() => {
// Preserve authentication cookies between tests
cy.getCookies().then((cookies) => {
const cookiesToPreserve = ['atom_authenticated', 'symfony'];
const preservePromises = [];

cookiesToPreserve.forEach((cookieName) => {
const cookie = cookies.find((c) => c.name === cookieName);
if (cookie) {
preservePromises.push(
cy.setCookie(cookie.name, cookie.value, {
// Add any additional options if needed
// For example, { domain: 'example.com' }
})
);
}
// Define an array of cookies to preserve
const cookiesToPreserve = ['atom_authenticated', 'symfony'];

// Retrieve all cookies
cy.window().then((win) => {
const cookies = win.document.cookie;

// Filter out cookies based on the array
const filteredCookies = cookies
.split('; ')
.filter((cookie) => cookiesToPreserve.includes(cookie.split('=')[0]));

// Preserve cookies using cy.setCookie()
filteredCookies.forEach((cookie) => {
const [name, value] = cookie.split('=');
cy.setCookie(name, value, {
// Add any additional options if needed
// For example, { domain: 'example.com' }
});
});

// Wait for all setCookie promises to complete before proceeding
return Promise.all(preservePromises);
});
});


it('Disables finding aids', () => {
cy.visit('settings/findingAid')

Expand Down

0 comments on commit c5a4a4e

Please sign in to comment.