summaryrefslogtreecommitdiffstats
path: root/browser/components/pocket/test/unit/browser_pocket_main.js
blob: c6955c09f7375a8453034d550602273ca61a61ff (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

function test_runner(test) {
  let testTask = async () => {
    // Before each
    pktUI.initPrefs();
    const sandbox = sinon.createSandbox();
    try {
      await test({ sandbox });
    } finally {
      // After each
      sandbox.restore();
    }
  };

  // Copy the name of the test function to identify the test
  Object.defineProperty(testTask, "name", { value: test.name });
  add_task(testTask);
}

test_runner(async function test_main_getAndShowRecsForItem_on({ sandbox }) {
  await SpecialPowers.pushPrefEnv({
    set: [["extensions.pocket.onSaveRecs", true]],
  });
  pktUI.initPrefs();
  const getRecsForItemStub = sandbox.stub(pktApi, "getRecsForItem");

  pktUI.getAndShowRecsForItem(
    {
      resolved_id: "1234",
    },
    {
      success() {},
    }
  );

  Assert.ok(getRecsForItemStub.calledOnce);
  Assert.equal(getRecsForItemStub.getCall(0).args[0], "1234");
});

test_runner(async function test_main_getAndShowRecsForItem_off({ sandbox }) {
  await SpecialPowers.pushPrefEnv({
    set: [["extensions.pocket.onSaveRecs", false]],
  });
  pktUI.initPrefs();
  const getRecsForItemStub = sandbox.stub(pktApi, "getRecsForItem");

  pktUI.getAndShowRecsForItem(
    {
      resolved_id: "1234",
    },
    {
      success() {},
    }
  );

  Assert.ok(getRecsForItemStub.notCalled);
});

test_runner(async function test_main_getAndShowRecsForItem_locale({ sandbox }) {
  await SpecialPowers.pushPrefEnv({
    set: [
      ["extensions.pocket.onSaveRecs", true],
      ["extensions.pocket.onSaveRecs.locales", "de"],
    ],
  });
  pktUI.initPrefs();
  const getRecsForItemStub = sandbox.stub(pktApi, "getRecsForItem");

  pktUI.getAndShowRecsForItem(
    {
      resolved_id: "1234",
    },
    {
      success() {},
    }
  );

  Assert.ok(getRecsForItemStub.notCalled);
});