ElggSessionTest.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. define(function(require) {
  2. var elgg = require('elgg');
  3. describe("elgg.session", function() {
  4. describe("#cookie()", function() {
  5. it("can get the cookie when called with no arguments", function() {
  6. expect(document.cookie).toEqual(elgg.session.cookie());
  7. });
  8. it("can get the value of a particular key", function() {
  9. document.cookie = "name=value";
  10. expect('value').toEqual(elgg.session.cookie('name'));
  11. document.cookie = "name=value2";
  12. expect('value2').toEqual(elgg.session.cookie('name'));
  13. document.cookie = "name=value";
  14. document.cookie = "name2=value2";
  15. expect('value').toEqual(elgg.session.cookie('name'));
  16. expect('value2').toEqual(elgg.session.cookie('name2'));
  17. });
  18. it("can set the value of a particular key", function() {
  19. elgg.session.cookie('name', 'value');
  20. expect('value').toEqual(elgg.session.cookie('name'));
  21. elgg.session.cookie('name', 'value2');
  22. expect('value2').toEqual(elgg.session.cookie('name'));
  23. elgg.session.cookie('name', 'value');
  24. elgg.session.cookie('name2', 'value2');
  25. expect('value').toEqual(elgg.session.cookie('name'));
  26. expect('value2').toEqual(elgg.session.cookie('name2'));
  27. elgg.session.cookie('name', null);
  28. elgg.session.cookie('name2', null);
  29. expect(elgg.session.cookie('name')).toBe(undefined);
  30. expect(elgg.session.cookie('name2')).toBe(undefined);
  31. });
  32. });
  33. });
  34. });