-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pr fixes infinite rerendering issue (it was from the parsing error of cookie value - so I added a unit test to make sure this works. - I used the solution from this post, feel free to edit if you see any improvement https://stackoverflow.com/questions/5142337/read-a-javascript-cookie-by-name) - also feel free to edit the test, I mainly put it for my dev purpose. I removed currenwindowurl logic, replaced it with pathname passed from the layout root. I started making this change and then realized that this is not the cause of infinite rendering problem, but I think it is probably safer to depend on the pathname change than location.href since href can include so many things like query parameters?
- Loading branch information
Showing
4 changed files
with
49 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/scripts/components/common/cookie-consent/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { readCookie, COOKIE_CONSENT_KEY } from './utils'; | ||
|
||
describe('onCookie', () => { | ||
let cookieValue; | ||
beforeEach(() => { | ||
cookieValue = { responded: false, answer: false }; | ||
// Mutating docmument cookie property for test | ||
// eslint-disable-next-line fp/no-mutating-methods | ||
Object.defineProperty(window.document, 'cookie', { | ||
writable: true, | ||
value: `CookieConsent={"responded":true,"answer":false}; _somethingelse=GS1.1.17303800; ${COOKIE_CONSENT_KEY}=${JSON.stringify( | ||
cookieValue | ||
)}` | ||
}); | ||
}); | ||
|
||
it('should parse cookie value correctly', () => { | ||
const cookieJsonVal = readCookie(COOKIE_CONSENT_KEY); | ||
expect(JSON.parse(cookieJsonVal)).toMatchObject(cookieValue); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters