This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31906 from arcturus/bug-1202916
Bug 1202916 - [Contacts] Contacts app not functioning on dogfood-late…
- Loading branch information
Showing
2 changed files
with
91 additions
and
2 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
76 changes: 76 additions & 0 deletions
76
apps/communications/contacts/test/unit/utilities/cookie_test.js
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,76 @@ | ||
'use strict'; | ||
|
||
requireApp('communications/contacts/js/utilities/cookie.js'); | ||
|
||
suite('Contacts Cookies', function() { | ||
var COOKIE_NAME = 'preferences'; | ||
var COOKIE_PROPS = null; | ||
var subject = null; | ||
|
||
suiteSetup(function() { | ||
COOKIE_PROPS = Object.keys(window.utils.cookie.COOKIE_DEFAULTS); | ||
subject = window.utils.cookie; | ||
}); | ||
|
||
function deleteCookie() { | ||
document.cookie = COOKIE_NAME + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;'; | ||
} | ||
|
||
function saveCookie(value) { | ||
document.cookie = COOKIE_NAME + '= ' + value; | ||
} | ||
|
||
function checkDefaultCookie(cookie) { | ||
assert.equal(cookie.version, subject.COOKIE_VERSION); | ||
COOKIE_PROPS.forEach(function(prop) { | ||
assert.equal(cookie[prop], subject.getDefault(prop)); | ||
}); | ||
} | ||
|
||
setup(function() { | ||
deleteCookie(); | ||
}); | ||
|
||
suite('Bad cookie', function() { | ||
test('No cookie returns null;', function() { | ||
var cookie = subject.load(); | ||
|
||
assert.isNull(cookie); | ||
}); | ||
|
||
test('Invalid cookie should return default cookie value', function() { | ||
saveCookie('invalid value'); | ||
|
||
var cookie = subject.load(); | ||
assert.isNotNull(cookie); | ||
checkDefaultCookie(cookie); | ||
}); | ||
}); | ||
|
||
suite('Update cookie', function() { | ||
test('Updating empty cookie with invalid property', function() { | ||
subject.update({test: 1}); | ||
var cookie = subject.load(); | ||
assert.isNotNull(cookie); | ||
assert.equal(cookie.version, subject.COOKIE_VERSION); | ||
assert.equal(cookie.test, null); | ||
}); | ||
|
||
test('Updating empty cookie', function() { | ||
subject.update({order: true}); | ||
var cookie = subject.load(); | ||
assert.isNotNull(cookie); | ||
assert.equal(cookie.version, subject.COOKIE_VERSION); | ||
assert.isTrue(cookie.order); | ||
}); | ||
|
||
test('Update invalid cookie', function() { | ||
saveCookie('invalid value'); | ||
subject.update({order: true}); | ||
var cookie = subject.load(); | ||
assert.isNotNull(cookie); | ||
assert.equal(cookie.version, subject.COOKIE_VERSION); | ||
assert.isTrue(cookie.order); | ||
}); | ||
}); | ||
}); |