import { Cookie } from 'ember-simple-auth/stores/cookie';
import { itBehavesLikeAStore } from './common/store_behavior';

describe('Stores.Cookie', function() {
  beforeEach(function() {
    this.store = Cookie.create();
    this.store.clear();
  });

  itBehavesLikeAStore();

  describe('the "ember-simple-auth:session-updated" event', function() {
    beforeEach(function() {
      var _this = this;
      _this.triggered = false;
      this.store.persist({ key: 'value' });
      _this.store.one('ember-simple-auth:session-updated', function() {
        _this.triggered = true;
      });
    });

    it('is not triggered when the store changes the cookie itself', function() {
      this.store.syncProperties();

      expect(this.triggered).to.be(false);
    });

    it('is not triggered when nothing actually changes in the cookie', function() {
      this.store.syncProperties();

      expect(this.triggered).to.be(false);
    });

    it('is triggered when the cookie is changed outside of the store', function() {
      document.cookie = 'ember_simple_auth:key=other value;';
      this.store.syncProperties();

      expect(this.triggered).to.be(true);
    });
  });
});

@@ -623,63 +623,84 @@
 red 
-when the store changes the cookie itself', function() %7B
+by #persist', function() %7B%0A      this.store.persist(%7B key: 'other value' %7D);
 %0A   
@@ -792,72 +792,199 @@
     
-it('is not triggered when nothing actually changes in the cookie
+describe('when the cookie does not actually change', function() %7B%0A      beforeEach(function() %7B%0A        document.cookie = 'ember_simple_auth:key=value;';%0A      %7D);%0A%0A      it('is not triggered
 ', f
@@ -993,32 +993,34 @@
 ction() %7B%0A      
+  
 this.store.syncP
@@ -1025,32 +1025,34 @@
 cProperties();%0A%0A
+  
       expect(thi
@@ -1070,32 +1070,42 @@
 ).to.be(false);%0A
+      %7D);%0A
     %7D);%0A%0A    it(
@@ -1105,25 +1105,18 @@
     
-it('is triggered 
+describe('
 when
@@ -1131,42 +1131,48 @@
 kie 
-is 
 change
-d outside of the store', 
+s', function() %7B%0A      beforeEach(
 func
@@ -1176,24 +1176,26 @@
 unction() %7B%0A
+  
       docume
@@ -1240,24 +1240,75 @@
 er value;';%0A
+      %7D);%0A%0A      it('is triggered', function() %7B%0A  
       this.s
@@ -1323,32 +1323,34 @@
 cProperties();%0A%0A
+  
       expect(thi
@@ -1371,24 +1371,34 @@
 o.be(true);%0A
+      %7D);%0A
     %7D);%0A  %7D)

test cleanup