Skip to content

Commit

Permalink
chore: restore
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferarnesen committed Jul 25, 2024
1 parent ee14f75 commit ce49842
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,61 @@ import './commands.js'

enableAutoLogin()

// // const LOGIN_ENDPOINT = 'dhis-web-commons-security/login.action'
// const SESSION_COOKIE_NAME = 'JSESSIONID'
// const LOCAL_STORAGE_KEY = 'DHIS2_BASE_URL'
// const LOGIN_ENDPOINT = 'dhis-web-commons-security/login.action'
const SESSION_COOKIE_NAME = 'JSESSIONID'
const LOCAL_STORAGE_KEY = 'DHIS2_BASE_URL'

// // '2.39' or 39?
// const computeEnvVariableName = (instanceVersion) =>
// typeof instanceVersion === 'number'
// ? `${SESSION_COOKIE_NAME}_${instanceVersion}`
// : `${SESSION_COOKIE_NAME}_${instanceVersion.split('.').pop()}`
// '2.39' or 39?
const computeEnvVariableName = (instanceVersion) =>
typeof instanceVersion === 'number'
? `${SESSION_COOKIE_NAME}_${instanceVersion}`
: `${SESSION_COOKIE_NAME}_${instanceVersion.split('.').pop()}`

// const findSessionCookieForBaseUrl = (baseUrl, cookies) =>
// cookies.find(
// (cookie) =>
// cookie.name === SESSION_COOKIE_NAME && baseUrl.includes(cookie.path)
// )
const findSessionCookieForBaseUrl = (baseUrl, cookies) =>
cookies.find(
(cookie) =>
cookie.name === SESSION_COOKIE_NAME && baseUrl.includes(cookie.path)
)

// const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/
// Cypress.on('uncaught:exception', (err) => {
// /* returning false here prevents Cypress from failing the test */
// if (resizeObserverLoopErrRe.test(err.message)) {
// return false
// }
// })
const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/
Cypress.on('uncaught:exception', (err) => {
/* returning false here prevents Cypress from failing the test */
if (resizeObserverLoopErrRe.test(err.message)) {
return false
}
})

// before(() => {
// const baseUrl = Cypress.env('dhis2BaseUrl')
// const instanceVersion = Cypress.env('dhis2InstanceVersion')
before(() => {
const baseUrl = Cypress.env('dhis2BaseUrl')
const instanceVersion = Cypress.env('dhis2InstanceVersion')

// cy.getAllCookies()
// .should((cookies) => {
// expect(cookies.length).to.be.at.least(1)
// })
// .then((cookies) => {
// const sessionCookieForBaseUrl = findSessionCookieForBaseUrl(
// baseUrl,
// cookies
// )
// Cypress.env(
// computeEnvVariableName(instanceVersion),
// JSON.stringify(sessionCookieForBaseUrl)
// )
// })
// })
cy.getAllCookies()
.should((cookies) => {
expect(cookies.length).to.be.at.least(1)
})
.then((cookies) => {
const sessionCookieForBaseUrl = findSessionCookieForBaseUrl(
baseUrl,
cookies
)
Cypress.env(
computeEnvVariableName(instanceVersion),
JSON.stringify(sessionCookieForBaseUrl)
)
})
})

// beforeEach(() => {
// const baseUrl = Cypress.env('dhis2BaseUrl')
// const instanceVersion = Cypress.env('dhis2InstanceVersion')
// const envVariableName = computeEnvVariableName(instanceVersion)
// const { name, value, ...options } = JSON.parse(Cypress.env(envVariableName))
beforeEach(() => {
const baseUrl = Cypress.env('dhis2BaseUrl')
const instanceVersion = Cypress.env('dhis2InstanceVersion')
const envVariableName = computeEnvVariableName(instanceVersion)
const { name, value, ...options } = JSON.parse(Cypress.env(envVariableName))

// localStorage.setItem(LOCAL_STORAGE_KEY, baseUrl)
// cy.setCookie(name, value, options)
localStorage.setItem(LOCAL_STORAGE_KEY, baseUrl)
cy.setCookie(name, value, options)

// cy.getAllCookies().should((cookies) => {
// expect(findSessionCookieForBaseUrl(baseUrl, cookies)).to.exist
// expect(localStorage.getItem(LOCAL_STORAGE_KEY)).to.equal(baseUrl)
// })
// })
cy.getAllCookies().should((cookies) => {
expect(findSessionCookieForBaseUrl(baseUrl, cookies)).to.exist
expect(localStorage.getItem(LOCAL_STORAGE_KEY)).to.equal(baseUrl)
})
})

0 comments on commit ce49842

Please sign in to comment.