mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 21:24:45 +08:00
FIX: save bookmark reminder on tap unless custom (#9611)
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import { and } from "@ember/object/computed";
|
import { and } from "@ember/object/computed";
|
||||||
|
import { action } from "@ember/object";
|
||||||
import { isPresent } from "@ember/utils";
|
import { isPresent } from "@ember/utils";
|
||||||
import Controller from "@ember/controller";
|
import Controller from "@ember/controller";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
@ -424,7 +425,7 @@ export default Controller.extend(ModalFunctionality, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
@action
|
||||||
saveAndClose() {
|
saveAndClose() {
|
||||||
if (this._saving || this._deleting) {
|
if (this._saving || this._deleting) {
|
||||||
return;
|
return;
|
||||||
@ -432,12 +433,13 @@ export default Controller.extend(ModalFunctionality, {
|
|||||||
|
|
||||||
this._saving = true;
|
this._saving = true;
|
||||||
this._savingBookmarkManually = true;
|
this._savingBookmarkManually = true;
|
||||||
this._saveBookmark()
|
return this._saveBookmark()
|
||||||
.then(() => this.send("closeModal"))
|
.then(() => this.send("closeModal"))
|
||||||
.catch(e => this._handleSaveError(e))
|
.catch(e => this._handleSaveError(e))
|
||||||
.finally(() => (this._saving = false));
|
.finally(() => (this._saving = false));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@action
|
||||||
delete() {
|
delete() {
|
||||||
this._deleting = true;
|
this._deleting = true;
|
||||||
let deleteAction = () => {
|
let deleteAction = () => {
|
||||||
@ -461,16 +463,22 @@ export default Controller.extend(ModalFunctionality, {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@action
|
||||||
closeWithoutSavingBookmark() {
|
closeWithoutSavingBookmark() {
|
||||||
this._closeWithoutSaving = true;
|
this._closeWithoutSaving = true;
|
||||||
this.send("closeModal");
|
this.send("closeModal");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@action
|
||||||
selectReminderType(type) {
|
selectReminderType(type) {
|
||||||
if (type === REMINDER_TYPES.LATER_TODAY && !this.showLaterToday) {
|
if (type === REMINDER_TYPES.LATER_TODAY && !this.showLaterToday) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.set("selectedReminderType", type);
|
this.set("selectedReminderType", type);
|
||||||
|
|
||||||
|
if (type !== REMINDER_TYPES.CUSTOM) {
|
||||||
|
return this.saveAndClose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
import { acceptance, loggedInUser } from "helpers/qunit-helpers";
|
import { acceptance, loggedInUser } from "helpers/qunit-helpers";
|
||||||
import pretender from "helpers/create-pretender";
|
import pretender from "helpers/create-pretender";
|
||||||
|
|
||||||
acceptance("Bookmarking", {
|
acceptance("Bookmarking", { loggedIn: true });
|
||||||
loggedIn: true,
|
|
||||||
|
|
||||||
beforeEach() {}
|
function handleRequest(assert, request) {
|
||||||
});
|
const body = request.requestBody;
|
||||||
|
const reminderType = body
|
||||||
|
.substr(0, body.indexOf("&"))
|
||||||
|
.replace("reminder_type=", "");
|
||||||
|
|
||||||
function mockSuccessfulBookmarkPost() {
|
assert.step(reminderType || "none");
|
||||||
pretender.post("/bookmarks", () => [
|
|
||||||
|
return [
|
||||||
200,
|
200,
|
||||||
{
|
{
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
@ -17,15 +20,24 @@ function mockSuccessfulBookmarkPost() {
|
|||||||
id: 999,
|
id: 999,
|
||||||
success: "OK"
|
success: "OK"
|
||||||
}
|
}
|
||||||
]);
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
function mockSuccessfulBookmarkPost(assert) {
|
||||||
|
pretender.post("/bookmarks", request => handleRequest(assert, request));
|
||||||
|
pretender.put("/bookmarks/999", request => handleRequest(assert, request));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function openBookmarkModal() {
|
async function openBookmarkModal() {
|
||||||
|
if (exists(".topic-post:first-child button.show-more-actions")) {
|
||||||
await click(".topic-post:first-child button.show-more-actions");
|
await click(".topic-post:first-child button.show-more-actions");
|
||||||
return await click(".topic-post:first-child button.bookmark");
|
}
|
||||||
|
|
||||||
|
await click(".topic-post:first-child button.bookmark");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function openEditBookmarkModal() {
|
async function openEditBookmarkModal() {
|
||||||
return await click(".topic-post:first-child button.bookmarked");
|
await click(".topic-post:first-child button.bookmarked");
|
||||||
}
|
}
|
||||||
|
|
||||||
test("Bookmarks modal opening", async assert => {
|
test("Bookmarks modal opening", async assert => {
|
||||||
@ -35,32 +47,45 @@ test("Bookmarks modal opening", async assert => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("Bookmarks modal selecting reminder type", async assert => {
|
test("Bookmarks modal selecting reminder type", async assert => {
|
||||||
|
mockSuccessfulBookmarkPost(assert);
|
||||||
|
|
||||||
await visit("/t/internationalization-localization/280");
|
await visit("/t/internationalization-localization/280");
|
||||||
|
|
||||||
await openBookmarkModal();
|
await openBookmarkModal();
|
||||||
await click("#tap_tile_tomorrow");
|
await click("#tap_tile_tomorrow");
|
||||||
assert.ok(exists("#tap_tile_tomorrow.active"), "it selects tomorrow");
|
|
||||||
|
await openBookmarkModal();
|
||||||
await click("#tap_tile_start_of_next_business_week");
|
await click("#tap_tile_start_of_next_business_week");
|
||||||
assert.ok(
|
|
||||||
exists("#tap_tile_start_of_next_business_week.active"),
|
await openBookmarkModal();
|
||||||
"it selects next monday"
|
|
||||||
);
|
|
||||||
await click("#tap_tile_next_week");
|
await click("#tap_tile_next_week");
|
||||||
assert.ok(exists("#tap_tile_next_week.active"), "it selects next week");
|
|
||||||
|
await openBookmarkModal();
|
||||||
await click("#tap_tile_next_month");
|
await click("#tap_tile_next_month");
|
||||||
assert.ok(exists("#tap_tile_next_month.active"), "it selects next month");
|
|
||||||
|
await openBookmarkModal();
|
||||||
await click("#tap_tile_custom");
|
await click("#tap_tile_custom");
|
||||||
assert.ok(exists("#tap_tile_custom.active"), "it selects custom");
|
assert.ok(exists("#tap_tile_custom.active"), "it selects custom");
|
||||||
assert.ok(exists(".tap-tile-date-input"), "it shows the custom date input");
|
assert.ok(exists(".tap-tile-date-input"), "it shows the custom date input");
|
||||||
assert.ok(exists(".tap-tile-time-input"), "it shows the custom time input");
|
assert.ok(exists(".tap-tile-time-input"), "it shows the custom time input");
|
||||||
|
await click("#save-bookmark");
|
||||||
|
|
||||||
|
assert.verifySteps([
|
||||||
|
"tomorrow",
|
||||||
|
"start_of_next_business_week",
|
||||||
|
"next_week",
|
||||||
|
"next_month",
|
||||||
|
"custom"
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Saving a bookmark with a reminder", async assert => {
|
test("Saving a bookmark with a reminder", async assert => {
|
||||||
mockSuccessfulBookmarkPost();
|
mockSuccessfulBookmarkPost(assert);
|
||||||
await visit("/t/internationalization-localization/280");
|
await visit("/t/internationalization-localization/280");
|
||||||
await openBookmarkModal();
|
await openBookmarkModal();
|
||||||
await fillIn("input#bookmark-name", "Check this out later");
|
await fillIn("input#bookmark-name", "Check this out later");
|
||||||
await click("#tap_tile_tomorrow");
|
await click("#tap_tile_tomorrow");
|
||||||
await click("#save-bookmark");
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
exists(".topic-post:first-child button.bookmark.bookmarked"),
|
exists(".topic-post:first-child button.bookmark.bookmarked"),
|
||||||
"it shows the bookmarked icon on the post"
|
"it shows the bookmarked icon on the post"
|
||||||
@ -71,13 +96,15 @@ test("Saving a bookmark with a reminder", async assert => {
|
|||||||
),
|
),
|
||||||
"it shows the bookmark clock icon because of the reminder"
|
"it shows the bookmark clock icon because of the reminder"
|
||||||
);
|
);
|
||||||
|
assert.verifySteps(["tomorrow"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Saving a bookmark with no reminder or name", async assert => {
|
test("Saving a bookmark with no reminder or name", async assert => {
|
||||||
mockSuccessfulBookmarkPost();
|
mockSuccessfulBookmarkPost(assert);
|
||||||
await visit("/t/internationalization-localization/280");
|
await visit("/t/internationalization-localization/280");
|
||||||
await openBookmarkModal();
|
await openBookmarkModal();
|
||||||
await click("#save-bookmark");
|
await click("#save-bookmark");
|
||||||
|
|
||||||
assert.ok(
|
assert.ok(
|
||||||
exists(".topic-post:first-child button.bookmark.bookmarked"),
|
exists(".topic-post:first-child button.bookmark.bookmarked"),
|
||||||
"it shows the bookmarked icon on the post"
|
"it shows the bookmarked icon on the post"
|
||||||
@ -88,6 +115,7 @@ test("Saving a bookmark with no reminder or name", async assert => {
|
|||||||
),
|
),
|
||||||
"it shows the regular bookmark active icon"
|
"it shows the regular bookmark active icon"
|
||||||
);
|
);
|
||||||
|
assert.verifySteps(["none"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Deleting a bookmark with a reminder", async assert => {
|
test("Deleting a bookmark with a reminder", async assert => {
|
||||||
@ -101,14 +129,21 @@ test("Deleting a bookmark with a reminder", async assert => {
|
|||||||
topic_bookmarked: false
|
topic_bookmarked: false
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
mockSuccessfulBookmarkPost();
|
|
||||||
|
mockSuccessfulBookmarkPost(assert);
|
||||||
|
|
||||||
await visit("/t/internationalization-localization/280");
|
await visit("/t/internationalization-localization/280");
|
||||||
await openBookmarkModal();
|
await openBookmarkModal();
|
||||||
await click("#tap_tile_tomorrow");
|
await click("#tap_tile_tomorrow");
|
||||||
await click("#save-bookmark");
|
|
||||||
|
assert.verifySteps(["tomorrow"]);
|
||||||
|
|
||||||
await openEditBookmarkModal();
|
await openEditBookmarkModal();
|
||||||
|
|
||||||
assert.ok(exists("#bookmark-reminder-modal"), "it shows the bookmark modal");
|
assert.ok(exists("#bookmark-reminder-modal"), "it shows the bookmark modal");
|
||||||
|
|
||||||
await click("#delete-bookmark");
|
await click("#delete-bookmark");
|
||||||
|
|
||||||
assert.ok(exists(".bootbox.modal"), "it asks for delete confirmation");
|
assert.ok(exists(".bootbox.modal"), "it asks for delete confirmation");
|
||||||
assert.ok(
|
assert.ok(
|
||||||
find(".bootbox.modal")
|
find(".bootbox.modal")
|
||||||
@ -116,7 +151,9 @@ test("Deleting a bookmark with a reminder", async assert => {
|
|||||||
.includes(I18n.t("bookmarks.confirm_delete")),
|
.includes(I18n.t("bookmarks.confirm_delete")),
|
||||||
"it shows delete confirmation message"
|
"it shows delete confirmation message"
|
||||||
);
|
);
|
||||||
|
|
||||||
await click(".bootbox.modal .btn-primary");
|
await click(".bootbox.modal .btn-primary");
|
||||||
|
|
||||||
assert.not(
|
assert.not(
|
||||||
exists(".topic-post:first-child button.bookmark.bookmarked"),
|
exists(".topic-post:first-child button.bookmark.bookmarked"),
|
||||||
"it no longer shows the bookmarked icon on the post after bookmark is deleted"
|
"it no longer shows the bookmarked icon on the post after bookmark is deleted"
|
||||||
@ -134,14 +171,15 @@ test("Cancelling saving a bookmark", async assert => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("Editing a bookmark", async assert => {
|
test("Editing a bookmark", async assert => {
|
||||||
mockSuccessfulBookmarkPost();
|
mockSuccessfulBookmarkPost(assert);
|
||||||
|
|
||||||
await visit("/t/internationalization-localization/280");
|
await visit("/t/internationalization-localization/280");
|
||||||
let now = moment.tz(loggedInUser().resolvedTimezone());
|
let now = moment.tz(loggedInUser().resolvedTimezone());
|
||||||
let tomorrow = now.add(1, "day").format("YYYY-MM-DD");
|
let tomorrow = now.add(1, "day").format("YYYY-MM-DD");
|
||||||
await openBookmarkModal();
|
await openBookmarkModal();
|
||||||
await fillIn("input#bookmark-name", "Test name");
|
await fillIn("input#bookmark-name", "Test name");
|
||||||
await click("#tap_tile_tomorrow");
|
await click("#tap_tile_tomorrow");
|
||||||
await click("#save-bookmark");
|
|
||||||
await openEditBookmarkModal();
|
await openEditBookmarkModal();
|
||||||
assert.equal(
|
assert.equal(
|
||||||
find("#bookmark-name").val(),
|
find("#bookmark-name").val(),
|
||||||
@ -158,4 +196,5 @@ test("Editing a bookmark", async assert => {
|
|||||||
"08:00",
|
"08:00",
|
||||||
"it should prefill the bookmark time"
|
"it should prefill the bookmark time"
|
||||||
);
|
);
|
||||||
|
assert.verifySteps(["tomorrow"]);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user