Skip to content

Commit

Permalink
Add test for path
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanKingston committed Jan 14, 2025
1 parent 5b0dc33 commit 9ea2f96
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@
"action": "delete"
}
},
{
"op": "add",
"path": "/modifyCookies/changes/-",
"value": {
"key": "pathCookie",
"action": "delete"
}
},
{
"op": "add",
"path": "/modifyCookies/changes/-",
"value": {
"key": "pathCookieWithPath",
"path": "/webcompat/pages/",
"action": "delete"
}
},
{
"op": "add",
"path": "/modifyCookies/changes/-",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
<title>Modify Cookies</title>
<link rel="stylesheet" href="../../shared/style.css">
<script>
// Current file path
let path = '/webcompat/pages/'
document.cookie = 'keyToBeDeleted="valueToBeDeleted"'
document.cookie = 'pathCookie="valueToBeDeleted"; path=' + path
document.cookie = 'pathCookieWithPath="valueToBeDeleted"; path=' + path
document.cookie = 'otherKey="valueToRemain"'
</script>
</head>
Expand All @@ -27,11 +31,16 @@
// eslint-disable-next-line no-undef
test('Only specified cookies should be removed', async () => {
const specifiedKey = hasCookie('keyToBeDeleted')
const pathKey = hasCookie('pathCookie')
const pathKey2 = hasCookie('pathCookie2')
const pathKey3 = hasCookie('pathCookieWithPath')
const nonexistentKey = hasCookie('nonexistentKey')
const otherKey = hasCookie('otherKey')

return [
{ name: 'specified cookie entry deleted', result: specifiedKey, expected: false },
{ name: 'specified cookie entry with path not deleted', result: pathKey, expected: true },
{ name: `specified cookie entry with correct path (${path}) deleted`, result: pathKey3, expected: false },
{ name: 'specified cookie entry that is not present on page load', result: nonexistentKey, expected: false },
{ name: 'other cookie entry untouched', result: otherKey, expected: true }
];
Expand Down

0 comments on commit 9ea2f96

Please sign in to comment.