Skip to content

Commit 8b92727

Browse files
authored
Merge pull request #72 from OneNoteDev/bug/ratings-prompt-ut-fix
[Bug] Ratings prompt UT fix
2 parents e386c01 + 2b53ff4 commit 8b92727

File tree

3 files changed

+42
-118
lines changed

3 files changed

+42
-118
lines changed

src/settings/default.json

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"^(http(s)?)://(paleoleap.com)/([^/]*-[^/]*)/$",
6464
"^(http(s)?)://(pinchofyum.com)/([^/]*-[^/]*)$",
6565
"^(http(s)?)://(recipe\\.rakuten\\.co\\.jp)()/recipe/[0-9]+/$",
66-
"^(http(s)?)://()(thepioneerwoman\\.com)()/(cooking/.+/)$",
66+
"^(http(s)?)://()(thepioneerwoman\\.com)()/(cooking/.+/)$",
6767
"^(http(s)?)://((www\\.)?)(allrecipes\\.com)()/([r|R]ecipe/[^/]+/(Detail\\.aspx)?)$",
6868
"^(http(s)?)://((www\\.)?)(allrecipes\\.com)()/([R|r]ecipe/.*)$",
6969
"^(http(s)?)://(www\\.)(bbc\\.co\\.uk/food/recipes/[^/]*_\\d+)$",
@@ -83,17 +83,17 @@
8383
"^(http(s)?)://(www\\.)(foodnetwork\\.com)()/(recipe-collections/.*)$",
8484
"^(http(s)?)://(www\\.)(foodnetwork\\.com)()/(recipes.*)$",
8585
"^(http(s)?)://(www\\.)(foodnetwork\\.com)()/(recipes/.*)$",
86-
"^(http(s)?)://(www\\.)(marthastewart\\.com)()/(([0-9]+|recipe)/.*)$",
87-
"^(http(s)?)://(www\\.)(marthastewart\\.com)()/([0-9]+/[^/]+)$",
86+
"^(http(s)?)://(www\\.)(marthastewart\\.com)()/(([0-9]+|recipe)/.*)$",
87+
"^(http(s)?)://(www\\.)(marthastewart\\.com)()/([0-9]+/[^/]+)$",
8888
"^(http(s)?)://(www\\.)(myrecipes\\.com)()/(recipe/.*)$",
89-
"^(http(s)?)://(www\\.)(myrecipes\\.com)()/(recipe/.*-[0-9]*/)$",
89+
"^(http(s)?)://(www\\.)(myrecipes\\.com)()/(recipe/.*-[0-9]*/)$",
9090
"^(http(s)?)://(www\\.)(myrecipes\\.com)()/(recipe/.*)$",
9191
"^(http(s)?)://(www\\.)(myrecipes\\.com)()/(recipe/[^/]+.*)$",
92-
"^(http(s)?)://(www\\.)(realsimple\\.com)()/(food-recipes/browse-all-recipes/[^\\/]+/index\\.html)$",
93-
"^(http(s)?)://((www)?\\.)(seriouseats\\.com)()/([Rr]ecipes\\/.*\\.(html|HTML)(.*)?)$",
94-
"^(http(s)?)://(www\\.)(simplyrecipes\\.com)()/(recipes/[^/]*/)$",
92+
"^(http(s)?)://(www\\.)(realsimple\\.com)()/(food-recipes/browse-all-recipes/[^\\/]+/index\\.html)$",
93+
"^(http(s)?)://((www)?\\.)(seriouseats\\.com)()/([Rr]ecipes\\/.*\\.(html|HTML)(.*)?)$",
94+
"^(http(s)?)://(www\\.)(simplyrecipes\\.com)()/(recipes/[^/]*/)$",
9595
"^(http(s)?)://((www\\.)?)(simplyrecipes\\.com)()/(recipes/[^/]*/)$",
96-
"^(http(s)?)://((www\\.)?)(simplyrecipes\\.com)()/(recipes/.*)$",
96+
"^(http(s)?)://((www\\.)?)(simplyrecipes\\.com)()/(recipes/.*)$",
9797
"^(http(s)?)://(www\\.)(tasteofhome\\.com)()/([R|r]ecipes/[^/]+$)$",
9898
"^(http(s)?)://(www\\.)(tasteofhome\\.com)()/(recipes/[^/]*/?)$",
9999
"^(http(s)?)://(www\\.)(tasteofhome\\.com)()/(recipes/[^\\/]+/?)$",
@@ -125,41 +125,5 @@
125125
"App_Id": {
126126
"Description": "For identifying the Clipper during interaction with external services",
127127
"Value": "OneNote Clipper OSS"
128-
},
129-
"LogCategory_RatingsPrompt": {
130-
"Description": "OFeedback log category for the ratings prompt feature",
131-
"Value": "OneNoteClipperRatingsPrompt"
132-
},
133-
"Bookmarklet_RatingsEnabled": {
134-
"Description": "If true, ratings prompt will be enabled for the bookmarklet",
135-
"Value": "false"
136-
},
137-
"ChromeExtension_RatingsEnabled": {
138-
"Description": "If true, ratings prompt will be enabled for the Chrome extension",
139-
"Value": "false"
140-
},
141-
"EdgeExtension_RatingsEnabled": {
142-
"Description": "If true, ratings prompt will be enabled for the Edge extension",
143-
"Value": "false"
144-
},
145-
"FirefoxExtension_RatingsEnabled": {
146-
"Description": "If true, ratings prompt will be enabled for the Firefox extension",
147-
"Value": "false"
148-
},
149-
"SafariExtension_RatingsEnabled": {
150-
"Description": "If true, ratings prompt will be enabled for the Safari extension",
151-
"Value": "false"
152-
},
153-
"ChromeExtension_RatingUrl": {
154-
"Description": "URL for the Web Clipper in the Chrome Web Store; used to direct users to leave ratings and reviews",
155-
"Value": "https://chrome.google.com/webstore/detail/onenote-web-clipper/gojbdfnpnhogfdgjbigejoaolejmgdhk/reviews"
156-
},
157-
"EdgeExtension_RatingUrl": {
158-
"Description": "URL for the Web Clipper in the Windows Store; used to direct users to leave ratings and reviews",
159-
"Value": "https://www.microsoft.com/en-us/store/p/onenote-web-clipper/9nblggh4r01n#ratings-reviews"
160-
},
161-
"FirefoxExtension_RatingUrl": {
162-
"Description": "URL for the Web Clipper in Firefox Add-ons; used to direct users to leave ratings and reviews",
163-
"Value": ""
164128
}
165129
}

src/tests/clipperUI/panels/ratingsPanel_tests.tsx

Lines changed: 33 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Clipper.getCachedValue = (key: string) => {
4646
QUnit.module("ratingsPanel", {
4747
beforeEach: () => {
4848
Clipper.logger = new StubSessionLogger();
49-
Settings.setSettingsJsonForTesting();
49+
Settings.setSettingsJsonForTesting({});
5050

5151
mockStorage = {};
5252
mockStorageCache = {};
@@ -95,8 +95,6 @@ test("'Positive' click at RatingsPromptStage.Init goes to RatingsPromptStage.Rat
9595
test("'Positive' click at RatingsPromptStage.Init goes to RatingsPromptStage.End when rate url does not exist", (assert: QUnitAssert) => {
9696
let done = assert.async();
9797

98-
Settings.setSettingsJsonForTesting({});
99-
10098
let clipperState = HelperFunctions.getMockClipperState();
10199
clipperState.showRatingsPrompt = new SmartValue<boolean>(true);
102100

@@ -151,8 +149,6 @@ test("'Negative' click at RatingsPromptStage.Init without a prior bad rating goe
151149
test("'Negative' click at RatingsPromptStage.Init without a prior bad rating goes to RatingsPromptStage.End when feedback url does not exist (and doNotPromptRatings === undefined)", (assert: QUnitAssert) => {
152150
let done = assert.async();
153151

154-
Settings.setSettingsJsonForTesting({});
155-
156152
Clipper.storeValue(ClipperStorageKeys.lastSeenVersion, "3.1.0");
157153

158154
let clipperState = HelperFunctions.getMockClipperState();
@@ -210,8 +206,6 @@ test("'Negative' click at RatingsPromptStage.Init with a prior bad rating sets d
210206
test("'Negative' click at RatingsPromptStage.Init with a prior bad rating sets doNotPromptRatings to 'true' (feedback url does not exist)", (assert: QUnitAssert) => {
211207
let done = assert.async();
212208

213-
Settings.setSettingsJsonForTesting({});
214-
215209
Clipper.storeValue(ClipperStorageKeys.lastBadRatingDate, (Date.now() - Constants.Settings.minTimeBetweenBadRatings).toString());
216210
Clipper.storeValue(ClipperStorageKeys.lastSeenVersion, "3.1.0");
217211

@@ -249,11 +243,9 @@ test("'Rate' click at RatingsPromptStage.Rate goes to RatingsPromptStage.End whe
249243

250244
let controllerInstance = HelperFunctions.mountToFixture(ratingsPanel);
251245

252-
// go to RATE panel, then click 'Rate'
253-
let initPositive = document.getElementById(Constants.Ids.ratingsButtonInitYes);
254-
HelperFunctions.simulateAction(() => {
255-
initPositive.click();
256-
});
246+
// skip to RATE panel
247+
controllerInstance.setState({ userSelectedRatingsPromptStage: RatingsPromptStage.Rate });
248+
m.redraw(true);
257249

258250
let ratePositive = document.getElementById(Constants.Ids.ratingsButtonRateYes);
259251
HelperFunctions.simulateAction(() => {
@@ -263,26 +255,21 @@ test("'Rate' click at RatingsPromptStage.Rate goes to RatingsPromptStage.End whe
263255
strictEqual(RatingsPromptStage[controllerInstance.state.userSelectedRatingsPromptStage], RatingsPromptStage[RatingsPromptStage.End]);
264256
});
265257

266-
test("'Rate' click at RatingsPromptStage.Rate not available when rate url does not exist", () => {
258+
test("'Rate' click at RatingsPromptStage.Rate not available when rate url does not exist (unexpected scenario)", () => {
267259
let clipperState = HelperFunctions.getMockClipperState();
268260
clipperState.showRatingsPrompt = new SmartValue<boolean>(true);
269261

270262
let ratingsPanel = <RatingsPanel clipperState={clipperState} />;
271263

272264
let controllerInstance = HelperFunctions.mountToFixture(ratingsPanel);
273265

274-
// go to RATE panel
275-
let initPositive = document.getElementById(Constants.Ids.ratingsButtonInitYes);
276-
HelperFunctions.simulateAction(() => {
277-
initPositive.click();
278-
// clearing rate url before rendering RATE panel
279-
// to test the unexpected case that we got to it without a rate url
280-
Settings.setSettingsJsonForTesting({});
281-
});
266+
// skip to RATE panel
267+
controllerInstance.setState({ userSelectedRatingsPromptStage: RatingsPromptStage.Rate });
268+
m.redraw(true);
282269

283270
let ratePositive = document.getElementById(Constants.Ids.ratingsButtonRateYes);
284-
285271
ok(Utils.isNullOrUndefined(ratePositive), "'Rate' button should not exist");
272+
286273
strictEqual(RatingsPromptStage[controllerInstance.state.userSelectedRatingsPromptStage], RatingsPromptStage[RatingsPromptStage.None]);
287274
});
288275

@@ -300,11 +287,9 @@ test("'No Thanks' click at RatingsPromptStage.Rate goes to RatingsPromptStage.No
300287

301288
let controllerInstance = HelperFunctions.mountToFixture(ratingsPanel);
302289

303-
// go to RATE panel, then click 'No Thanks'
304-
let initPositive = document.getElementById(Constants.Ids.ratingsButtonInitYes);
305-
HelperFunctions.simulateAction(() => {
306-
initPositive.click();
307-
});
290+
// skip to RATE panel
291+
controllerInstance.setState({ userSelectedRatingsPromptStage: RatingsPromptStage.Rate });
292+
m.redraw(true);
308293

309294
let rateNegative = document.getElementById(Constants.Ids.ratingsButtonRateNo);
310295
HelperFunctions.simulateAction(() => {
@@ -314,26 +299,21 @@ test("'No Thanks' click at RatingsPromptStage.Rate goes to RatingsPromptStage.No
314299
strictEqual(RatingsPromptStage[controllerInstance.state.userSelectedRatingsPromptStage], RatingsPromptStage[RatingsPromptStage.None]);
315300
});
316301

317-
test("'No Thanks' click at RatingsPromptStage.Rate not available when rate url does not exist", () => {
302+
test("'No Thanks' click at RatingsPromptStage.Rate not available when rate url does not exist (unexpected scenario)", () => {
318303
let clipperState = HelperFunctions.getMockClipperState();
319304
clipperState.showRatingsPrompt = new SmartValue<boolean>(true);
320305

321306
let ratingsPanel = <RatingsPanel clipperState={clipperState} />;
322307

323308
let controllerInstance = HelperFunctions.mountToFixture(ratingsPanel);
324309

325-
// go to RATE panel
326-
let initPositive = document.getElementById(Constants.Ids.ratingsButtonInitYes);
327-
HelperFunctions.simulateAction(() => {
328-
initPositive.click();
329-
// clearing rate url before rendering RATE panel
330-
// to test the unexpected case that we got to it without a rate url
331-
Settings.setSettingsJsonForTesting({});
332-
});
310+
// skip to RATE panel
311+
controllerInstance.setState({ userSelectedRatingsPromptStage: RatingsPromptStage.Rate });
312+
m.redraw(true);
333313

334314
let rateNegative = document.getElementById(Constants.Ids.ratingsButtonRateNo);
335-
336315
ok(Utils.isNullOrUndefined(rateNegative), "'No Thanks' button should not exist");
316+
337317
strictEqual(RatingsPromptStage[controllerInstance.state.userSelectedRatingsPromptStage], RatingsPromptStage[RatingsPromptStage.None]);
338318
});
339319

@@ -353,11 +333,9 @@ test("'Feedback' click at RatingsPromptStage.Feedback goes to RatingsPromptStage
353333

354334
let controllerInstance = HelperFunctions.mountToFixture(ratingsPanel);
355335

356-
// go to FEEDBACK panel, then click 'Feedback'
357-
let initNegative = document.getElementById(Constants.Ids.ratingsButtonInitNo);
358-
HelperFunctions.simulateAction(() => {
359-
initNegative.click();
360-
});
336+
// skip to FEEDBACK panel
337+
controllerInstance.setState({ userSelectedRatingsPromptStage: RatingsPromptStage.Feedback });
338+
m.redraw(true);
361339

362340
let feedbackPositive = document.getElementById(Constants.Ids.ratingsButtonFeedbackYes);
363341
HelperFunctions.simulateAction(() => {
@@ -367,7 +345,7 @@ test("'Feedback' click at RatingsPromptStage.Feedback goes to RatingsPromptStage
367345
strictEqual(RatingsPromptStage[controllerInstance.state.userSelectedRatingsPromptStage], RatingsPromptStage[RatingsPromptStage.End]);
368346
});
369347

370-
test("'Feedback' click at RatingsPromptStage.Feedback not available when feedback url does not exist", () => {
348+
test("'Feedback' click at RatingsPromptStage.Feedback not available when feedback url does not exist (unexpected scenario)", () => {
371349
Clipper.storeValue(ClipperStorageKeys.lastSeenVersion, "3.1.0");
372350

373351
let clipperState = HelperFunctions.getMockClipperState();
@@ -377,18 +355,13 @@ test("'Feedback' click at RatingsPromptStage.Feedback not available when feedbac
377355

378356
let controllerInstance = HelperFunctions.mountToFixture(ratingsPanel);
379357

380-
// go to FEEDBACK panel
381-
let initNegative = document.getElementById(Constants.Ids.ratingsButtonInitNo);
382-
HelperFunctions.simulateAction(() => {
383-
initNegative.click();
384-
// clearing feedback url before rendering FEEDBACK panel
385-
// to test the unexpected case that we got to it without a feedback url
386-
Settings.setSettingsJsonForTesting({});
387-
});
358+
// skip to FEEDBACK panel
359+
controllerInstance.setState({ userSelectedRatingsPromptStage: RatingsPromptStage.Feedback });
360+
m.redraw(true);
388361

389362
let feedbackPositive = document.getElementById(Constants.Ids.ratingsButtonFeedbackYes);
390-
391363
ok(Utils.isNullOrUndefined(feedbackPositive), "'Feedback' button should not exist");
364+
392365
strictEqual(RatingsPromptStage[controllerInstance.state.userSelectedRatingsPromptStage], RatingsPromptStage[RatingsPromptStage.None]);
393366
});
394367

@@ -408,11 +381,9 @@ test("'No Thanks' click at RatingsPromptStage.Feedback goes to RatingsPromptStag
408381

409382
let controllerInstance = HelperFunctions.mountToFixture(ratingsPanel);
410383

411-
// go to FEEDBACK panel, then click 'No Thanks'
412-
let initNegative = document.getElementById(Constants.Ids.ratingsButtonInitNo);
413-
HelperFunctions.simulateAction(() => {
414-
initNegative.click();
415-
});
384+
// skip to FEEDBACK panel
385+
controllerInstance.setState({ userSelectedRatingsPromptStage: RatingsPromptStage.Feedback });
386+
m.redraw(true);
416387

417388
let feedbackNegative = document.getElementById(Constants.Ids.ratingsButtonFeedbackNo);
418389
HelperFunctions.simulateAction(() => {
@@ -422,7 +393,7 @@ test("'No Thanks' click at RatingsPromptStage.Feedback goes to RatingsPromptStag
422393
strictEqual(RatingsPromptStage[controllerInstance.state.userSelectedRatingsPromptStage], RatingsPromptStage[RatingsPromptStage.None]);
423394
});
424395

425-
test("'No Thanks' click at RatingsPromptStage.Feedback not available when feedback url does not exist", () => {
396+
test("'No Thanks' click at RatingsPromptStage.Feedback not available when feedback url does not exist (unexpected scenario)", () => {
426397
Clipper.storeValue(ClipperStorageKeys.lastSeenVersion, "3.1.0");
427398

428399
let clipperState = HelperFunctions.getMockClipperState();
@@ -432,17 +403,12 @@ test("'No Thanks' click at RatingsPromptStage.Feedback not available when feedba
432403

433404
let controllerInstance = HelperFunctions.mountToFixture(ratingsPanel);
434405

435-
// go to FEEDBACK panel
436-
let initNegative = document.getElementById(Constants.Ids.ratingsButtonInitNo);
437-
HelperFunctions.simulateAction(() => {
438-
initNegative.click();
439-
// clearing feedback url before rendering FEEDBACK panel
440-
// to test the unexpected case that we got to it without a feedback url
441-
Settings.setSettingsJsonForTesting({});
442-
});
406+
// skip to FEEDBACK panel
407+
controllerInstance.setState({ userSelectedRatingsPromptStage: RatingsPromptStage.Feedback });
408+
m.redraw(true);
443409

444410
let feedbackNegative = document.getElementById(Constants.Ids.ratingsButtonFeedbackNo);
445-
446411
ok(Utils.isNullOrUndefined(feedbackNegative), "'No Thanks' button should not exist");
412+
447413
strictEqual(RatingsPromptStage[controllerInstance.state.userSelectedRatingsPromptStage], RatingsPromptStage[RatingsPromptStage.None]);
448414
});

src/tests/clipperUI/ratingsHelper_tests.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Clipper.getCachedValue = (key: string) => {
4444
QUnit.module("ratingsHelper", {
4545
beforeEach: () => {
4646
Clipper.logger = new StubSessionLogger();
47-
Settings.setSettingsJsonForTesting();
47+
Settings.setSettingsJsonForTesting({});
4848

4949
mockStorage = {};
5050
mockStorageCache = {};
@@ -178,8 +178,6 @@ test("badRatingTimingDelayIsOver returns true when the time between bad rating a
178178
// getFeedbackUrlIfExists
179179

180180
test("getFeedbackUrlIfExists returns undefined if log category for ratings prompt does not exist", () => {
181-
Settings.setSettingsJsonForTesting({});
182-
183181
let url: string = RatingsHelper.getFeedbackUrlIfExists({});
184182
strictEqual(url, undefined, "setting for log category for ratings prompt does not exist");
185183

@@ -237,8 +235,6 @@ test("getRateUrlIfExists returns undefined if ClientType/ClipperType is invalid"
237235
});
238236

239237
test("getRateUrlIfExists returns undefined if a client's rate url does not exist", () => {
240-
Settings.setSettingsJsonForTesting({});
241-
242238
let clientType: ClientType = ClientType.ChromeExtension;
243239
let settingName: string = ClientType[clientType] + RatingsHelper.rateUrlSettingNameSuffix;
244240

@@ -291,8 +287,6 @@ test("ratingsPromptEnabledForClient returns false if ClientType/ClipperType is i
291287
});
292288

293289
test("ratingsPromptEnabledForClient returns false if a client's enable value does not exist", () => {
294-
Settings.setSettingsJsonForTesting({});
295-
296290
let clientType: ClientType = ClientType.ChromeExtension;
297291
let settingName: string = ClientType[clientType] + RatingsHelper.ratingsPromptEnabledSettingNameSuffix;
298292

0 commit comments

Comments
 (0)