Skip to content

Commit 62cb293

Browse files
committed
Merge remote-tracking branch 'origin/testtypos'
2 parents ebf909c + 86503f1 commit 62cb293

File tree

3 files changed

+78
-9
lines changed

3 files changed

+78
-9
lines changed

RandomTips.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
/**
22
* Shows random tips to the user, if wanted.
33
*
4-
* @module /common/modules/RandomTips
5-
* @requires /common/modules/lib/lodash/debounce
6-
* @requires /common/modules/Logger
7-
* @requires /common/modules/AddonSettings
8-
* @requires /common/modules/MessageHandler/CustomMessages
4+
* @module RandomTips
5+
* @requires ../lib/lodash/debounce
6+
* @requires ../AddonSettings
7+
* @requires ../MessageHandler/CustomMessages
98
*/
109

1110
// lodash
1211
import debounce from "../lodash/debounce.js";
1312

14-
1513
import * as AddonSettings from "../AddonSettings/AddonSettings.js";
1614
import * as CustomMessages from "../MessageHandler/CustomMessages.js";
1715

example/Tips.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* The settings/constraints for a tip, represented in an object.
3+
*
4+
* @typedef {Object} TipObject
5+
* @property {string} id just some ID
6+
* @property {integer|null} requiredShowCount shows the message x times; set
7+
* to "null" to show infinitively
8+
* @property {bool} [allowDismiss=true] set to false to disallow dismissing
9+
* the message. This likely makes no sense for any tip, so the default is true.
10+
* @property {bool|integer} [requireDismiss=false] show the message, if it is
11+
* not, at least, dismissed for x times. Alternatively set to true to require
12+
* that message is dismissed the exact same number as requiredShowCount states,
13+
* i.e. only dismissed count as "tip shown".
14+
* @property {integer|null} [maximumDismiss=null] hides the message, if it
15+
* has been dismissed x times.
16+
* @property {integer} [requiredTriggers=10] require some displays ("triggers")
17+
* of (any) add-on page before showing tip. This is effectively just a minimum
18+
* limit, so it is not shown too "early".
19+
* @property {Object.<string: integer>} [showInContext] a key-value object with
20+
* context -> num to require the tip to be shown in a specific context for the
21+
* given number of times. See {@link RandomTips.setContext}.
22+
* @property {Object.<string: integer>} [maximumInContest] a key-value object with
23+
* context -> num to only show the tip in a specific context at most for the
24+
* given number of times. See {@link RandomTips.setContext}.
25+
* @property {bool|integer} [randomizeDisplay] Randomizes the display with a
26+
* chance of 50% by default (when set to "true"). You can override that percentage
27+
* (as an integer, e.g. 0.2 instead of 20%).
28+
* Note that the tip message display in general is already randomized
29+
* with a chance of 20%, see {@link RandomTips.GLOBAL_RANDOMIZE}.
30+
* @property {string} text The text to actually show. It is passed to the
31+
* {@link MessageHandler}, so you can (& should) use a translatable string here.
32+
* @property {Object} [actionButton] adds an action button to the message // TODO: document action button
33+
*/
34+
35+
/**
36+
* An array of all tips.
37+
*
38+
* @private
39+
* @const
40+
* @type {Array.<TipObject>}
41+
*/
42+
const tipArray = [
43+
{
44+
id: "likeAddon",
45+
requiredShowCount: 3,
46+
requireDismiss: 1,
47+
maximumDismiss: 2,
48+
requiredTriggers: 10,
49+
showInContext: {
50+
"popup": 1
51+
},
52+
randomizeDisplay: false,
53+
text: "tipYouLikeAddon",
54+
actionButton: {
55+
text: "tipYouLikeAddonButton",
56+
action: "https://addons.mozilla.org/firefox/addon/.../reviews/"
57+
}
58+
}
59+
];
60+
61+
// freeze the inner tib objects, this is strongly recommend
62+
tipArray.forEach((object) => Object.freeze(object));
63+
64+
/**
65+
* The list of all tips. (now exported)
66+
*
67+
* @public
68+
* @const
69+
* @type {Array.<TipObject>}
70+
*/
71+
export const tips = Object.freeze(tipArray);

tests/dataTest/tips.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import "https://unpkg.com/chai@4.1.2/chai.js"; /* globals chai */
33

44
import { tips } from "../../../data/Tips.js";
55

6-
// TODO: only checks two levels deep. Currently, we do not require/test the third-level 8to be frozen)
6+
// TODO: only checks two levels deep. Currently, we do not require/test the third-level to be frozen)
77

88
describe("data: tips", function () {
9-
describe("tips", function () {
9+
describe("tip list", function () {
1010
it("is there", function () {
1111
chai.assert.exists(tips);
1212
chai.assert.isNotEmpty(tips);
@@ -21,7 +21,7 @@ describe("data: tips", function () {
2121
});
2222
});
2323

24-
describe("tips – inner objects", function () {
24+
describe("tips – inner objects, i.e. actual tips", function () {
2525
it("are there", function () {
2626
for (const tipObject of tips) {
2727
chai.assert.exists(tipObject);

0 commit comments

Comments
 (0)