summaryrefslogtreecommitdiffstats
path: root/comm/mail/components/unifiedtoolbar/test/unit/test_customizableItems.js
blob: 55d4f5ba9105e8ea95eadd20fd986567803388c4 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

const {
  getAvailableItemIdsForSpace,
  getDefaultItemIdsForSpace,
  MULTIPLE_ALLOWED_ITEM_IDS,
  SKIP_FOCUS_ITEM_IDS,
} = ChromeUtils.importESModule("resource:///modules/CustomizableItems.sys.mjs");

const { default: CUSTOMIZABLE_ITEMS } = ChromeUtils.importESModule(
  "resource:///modules/CustomizableItemsDetails.mjs"
);

add_task(function test_getAvailableItemIdsForSpace_anySpace() {
  const itemsForAnySpace = getAvailableItemIdsForSpace();
  Assert.ok(Array.isArray(itemsForAnySpace), "returns an array");
  for (const itemId of itemsForAnySpace) {
    Assert.equal(typeof itemId, "string", `item ID "${itemId}" is string`);
    Assert.greater(itemId.length, 0, `item ID is not empty`);
  }
});

add_task(function test_getAvailableItemIdsForSpace_emptySpace() {
  const itemsForEmptySpace = getAvailableItemIdsForSpace("test");
  Assert.deepEqual(itemsForEmptySpace, [], "Empty array for empty space");
});

add_task(function test_getAvailableItemIdsForSpace_includingAgnostic() {
  const items = getAvailableItemIdsForSpace("mail", true);
  const itemsForAnySpace = getAvailableItemIdsForSpace();
  const itemsForMailSpace = getAvailableItemIdsForSpace("mail");

  Assert.ok(
    itemsForAnySpace.every(itemId => items.includes(itemId)),
    "All space agnostic items are included"
  );

  Assert.ok(
    itemsForMailSpace.every(itemId => items.includes(itemId)),
    "All mail space items are included"
  );
});

add_task(function test_getDefaultItemIdsForSpace_default() {
  const items = getDefaultItemIdsForSpace("default");

  Assert.ok(Array.isArray(items), "Should return an array");
  Assert.deepEqual(
    items,
    ["spacer", "search-bar", "spacer"],
    "Default space should contain the default item set"
  );
});

add_task(function test_getDefaultItemIdsForSpace_cloningArray() {
  const items1 = getDefaultItemIdsForSpace("default");
  const items2 = getDefaultItemIdsForSpace("default");
  const items3 = getDefaultItemIdsForSpace("mail");

  Assert.notStrictEqual(
    items1,
    items2,
    "The default sets should be different array instances"
  );
  Assert.notStrictEqual(
    items2,
    items3,
    "The second default set an mail space should be different array instances"
  );
  Assert.notStrictEqual(
    items3,
    items1,
    "The mail space and first default set should be different array instances"
  );

  Assert.deepEqual(
    items1,
    items2,
    "The two default pseudospace sets should contain the same items"
  );
});

add_task(function test_multipleAllowedItemIds() {
  Assert.equal(
    typeof MULTIPLE_ALLOWED_ITEM_IDS.has,
    "function",
    "Multiple allowed item IDs should be set-like"
  );
  Assert.ok(
    Array.from(MULTIPLE_ALLOWED_ITEM_IDS).every(
      itemId => typeof itemId === "string"
    ),
    "Every item in the set should be a string"
  );
  for (const item of CUSTOMIZABLE_ITEMS) {
    Assert.equal(
      MULTIPLE_ALLOWED_ITEM_IDS.has(item.id),
      Boolean(item.allowMultiple),
      `Set's state should matche the allowMultiple value of ${item.allowMultiple} for ${item.id}`
    );
  }
});

add_task(function test_skipFocusItemIds() {
  Assert.equal(
    typeof SKIP_FOCUS_ITEM_IDS.has,
    "function",
    "Skip focus item IDs should be set-like"
  );
  Assert.ok(
    Array.from(SKIP_FOCUS_ITEM_IDS).every(itemId => typeof itemId === "string"),
    "Every item in the set should be a string"
  );
  for (const item of CUSTOMIZABLE_ITEMS) {
    Assert.equal(
      SKIP_FOCUS_ITEM_IDS.has(item.id),
      Boolean(item.skipFocus),
      `Set's state should match the skipFocus value of ${item.skipFocus} for ${item.id}`
    );
  }
});