test_SmartShortcutsFeed.js (1732B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 ChromeUtils.defineESModuleGetters(this, { 7 actionTypes: "resource://newtab/common/Actions.mjs", 8 SmartShortcutsFeed: "resource://newtab/lib/SmartShortcutsFeed.sys.mjs", 9 }); 10 11 const PREF_SYSTEM_SHORTCUTS_PERSONALIZATION = 12 "discoverystream.shortcuts.personalization.enabled"; 13 14 add_task(async function test_construction() { 15 let feed = new SmartShortcutsFeed(); 16 17 feed.store = { 18 getState() { 19 return this.state; 20 }, 21 state: { 22 Prefs: { 23 values: { 24 [PREF_SYSTEM_SHORTCUTS_PERSONALIZATION]: false, 25 }, 26 }, 27 }, 28 }; 29 30 info("SmartShortcutsFeed constructor should create initial values"); 31 32 Assert.ok(feed, "Could construct a SmartShortcutsFeed"); 33 Assert.ok(!feed.loaded, "SmartShortcutsFeed is not loaded"); 34 Assert.ok(!feed.isEnabled()); 35 }); 36 37 add_task(async function test_onAction_INIT() { 38 let feed = new SmartShortcutsFeed(); 39 40 feed.store = { 41 getState() { 42 return this.state; 43 }, 44 state: { 45 Prefs: { 46 values: { 47 [PREF_SYSTEM_SHORTCUTS_PERSONALIZATION]: true, 48 }, 49 }, 50 }, 51 }; 52 53 info("SmartShortcutsFeed.onAction INIT should set loaded"); 54 55 await feed.onAction({ 56 type: actionTypes.INIT, 57 }); 58 59 Assert.ok(feed.loaded); 60 }); 61 62 add_task(async function test_isEnabled() { 63 let feed = new SmartShortcutsFeed(); 64 65 feed.store = { 66 getState() { 67 return this.state; 68 }, 69 state: { 70 Prefs: { 71 values: { 72 [PREF_SYSTEM_SHORTCUTS_PERSONALIZATION]: true, 73 }, 74 }, 75 }, 76 }; 77 78 info("SmartShortcutsFeed should be enabled"); 79 Assert.ok(feed.isEnabled()); 80 });