aboutsummaryrefslogtreecommitdiff
path: root/test/shared/versions/index.test.js
blob: 3bb307abd47b04cffec6a597a6af564a2855cccc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as versions from 'shared/versions';
import manifest from '../../../manifest.json';

describe("shared/versions/storage", () => {
  describe('#checkUpdated', () => {
    beforeEach(() => {
      return browser.storage.local.remove('version');
    });

    it('return true if no previous versions', () => {
      return Promise.resolve().then(() => {
        return versions.checkUpdated();
      }).then((updated) => {
        expect(updated).to.be.true;
      });
    });

    it('return true if updated', () => {
      return Promise.resolve().then(() => {
        return browser.storage.local.set({ version: '0.001' });
      }).then(() => {
        return versions.checkUpdated();
      }).then((updated) => {
        expect(updated).to.be.true;
      });
    });

    it('return false if not updated', () => {
      return Promise.resolve().then(() => {
        return browser.storage.local.set({ version: manifest.version });
      }).then(() => {
        return versions.checkUpdated();
      }).then((updated) => {
        expect(updated).to.be.false;
      });
    });
  });

  describe('#commit', () => {
    beforeEach(() => {
      return browser.storage.local.remove('version');
    });

    it('saves current version from manifest.json', () => {
      return Promise.resolve().then(() => {
        return versions.commit();
      }).then(() => {
        return browser.storage.local.get('version');
      }).then(({version}) => {
        expect(version).to.be.a('string');
        expect(version).to.equal(manifest.version);
      });
    });
  });
});