2020-05-14 22:04:08 +08:00
|
|
|
import I18n from "I18n";
|
2020-05-07 07:10:32 +08:00
|
|
|
import {
|
|
|
|
acceptance,
|
|
|
|
loggedInUser,
|
2020-05-13 13:16:07 +08:00
|
|
|
acceptanceUseFakeClock
|
2020-05-07 07:10:32 +08:00
|
|
|
} from "helpers/qunit-helpers";
|
2020-04-30 12:58:26 +08:00
|
|
|
import pretender from "helpers/create-pretender";
|
2020-05-05 00:35:04 +08:00
|
|
|
import { parsePostData } from "helpers/create-pretender";
|
2020-04-30 12:58:26 +08:00
|
|
|
|
2020-05-07 07:10:32 +08:00
|
|
|
acceptance("Bookmarking", {
|
|
|
|
loggedIn: true,
|
|
|
|
afterEach() {
|
|
|
|
sandbox.restore();
|
|
|
|
}
|
|
|
|
});
|
2020-04-30 12:58:26 +08:00
|
|
|
|
2020-05-02 16:31:44 +08:00
|
|
|
function handleRequest(assert, request) {
|
2020-05-05 00:35:04 +08:00
|
|
|
const data = parsePostData(request.requestBody);
|
|
|
|
assert.step(data.reminder_type || "none");
|
2020-04-30 12:58:26 +08:00
|
|
|
|
2020-05-02 16:31:44 +08:00
|
|
|
return [
|
2020-04-30 12:58:26 +08:00
|
|
|
200,
|
|
|
|
{
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 999,
|
|
|
|
success: "OK"
|
|
|
|
}
|
2020-05-02 16:31:44 +08:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
function mockSuccessfulBookmarkPost(assert) {
|
|
|
|
pretender.post("/bookmarks", request => handleRequest(assert, request));
|
|
|
|
pretender.put("/bookmarks/999", request => handleRequest(assert, request));
|
2020-04-30 12:58:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async function openBookmarkModal() {
|
2020-05-02 16:31:44 +08:00
|
|
|
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.bookmark");
|
2020-04-30 12:58:26 +08:00
|
|
|
}
|
2020-05-02 16:31:44 +08:00
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
async function openEditBookmarkModal() {
|
2020-05-02 16:31:44 +08:00
|
|
|
await click(".topic-post:first-child button.bookmarked");
|
2020-04-30 12:58:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
test("Bookmarks modal opening", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await openBookmarkModal();
|
|
|
|
assert.ok(exists("#bookmark-reminder-modal"), "it shows the bookmark modal");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Bookmarks modal selecting reminder type", async assert => {
|
2020-05-02 16:31:44 +08:00
|
|
|
mockSuccessfulBookmarkPost(assert);
|
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
await visit("/t/internationalization-localization/280");
|
2020-05-02 16:31:44 +08:00
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
await openBookmarkModal();
|
|
|
|
await click("#tap_tile_tomorrow");
|
2020-05-02 16:31:44 +08:00
|
|
|
|
|
|
|
await openBookmarkModal();
|
2020-04-30 12:58:26 +08:00
|
|
|
await click("#tap_tile_start_of_next_business_week");
|
2020-05-02 16:31:44 +08:00
|
|
|
|
|
|
|
await openBookmarkModal();
|
2020-04-30 12:58:26 +08:00
|
|
|
await click("#tap_tile_next_week");
|
2020-05-02 16:31:44 +08:00
|
|
|
|
|
|
|
await openBookmarkModal();
|
2020-04-30 12:58:26 +08:00
|
|
|
await click("#tap_tile_next_month");
|
2020-05-02 16:31:44 +08:00
|
|
|
|
|
|
|
await openBookmarkModal();
|
2020-04-30 12:58:26 +08:00
|
|
|
await click("#tap_tile_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-time-input"), "it shows the custom time input");
|
2020-05-02 16:31:44 +08:00
|
|
|
await click("#save-bookmark");
|
|
|
|
|
|
|
|
assert.verifySteps([
|
|
|
|
"tomorrow",
|
|
|
|
"start_of_next_business_week",
|
|
|
|
"next_week",
|
|
|
|
"next_month",
|
|
|
|
"custom"
|
|
|
|
]);
|
2020-04-30 12:58:26 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("Saving a bookmark with a reminder", async assert => {
|
2020-05-02 16:31:44 +08:00
|
|
|
mockSuccessfulBookmarkPost(assert);
|
2020-04-30 12:58:26 +08:00
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await openBookmarkModal();
|
|
|
|
await fillIn("input#bookmark-name", "Check this out later");
|
|
|
|
await click("#tap_tile_tomorrow");
|
2020-05-02 16:31:44 +08:00
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
assert.ok(
|
|
|
|
exists(".topic-post:first-child button.bookmark.bookmarked"),
|
|
|
|
"it shows the bookmarked icon on the post"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
exists(
|
|
|
|
".topic-post:first-child button.bookmark.bookmarked > .d-icon-discourse-bookmark-clock"
|
|
|
|
),
|
|
|
|
"it shows the bookmark clock icon because of the reminder"
|
|
|
|
);
|
2020-05-02 16:31:44 +08:00
|
|
|
assert.verifySteps(["tomorrow"]);
|
2020-04-30 12:58:26 +08:00
|
|
|
});
|
|
|
|
|
2020-05-07 11:37:39 +08:00
|
|
|
test("Opening the options panel and remembering the option", async assert => {
|
|
|
|
mockSuccessfulBookmarkPost(assert);
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await openBookmarkModal();
|
|
|
|
await click(".bookmark-options-button");
|
|
|
|
assert.ok(
|
|
|
|
exists(".bookmark-options-panel"),
|
|
|
|
"it should open the options panel"
|
|
|
|
);
|
|
|
|
await click("#delete_when_reminder_sent");
|
|
|
|
await click("#save-bookmark");
|
|
|
|
await openEditBookmarkModal();
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
exists(".bookmark-options-panel"),
|
|
|
|
"it should reopen the options panel"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
exists(".bookmark-options-panel #delete_when_reminder_sent:checked"),
|
|
|
|
"it should pre-check delete when reminder sent option"
|
|
|
|
);
|
|
|
|
assert.verifySteps(["none"]);
|
|
|
|
});
|
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
test("Saving a bookmark with no reminder or name", async assert => {
|
2020-05-02 16:31:44 +08:00
|
|
|
mockSuccessfulBookmarkPost(assert);
|
2020-04-30 12:58:26 +08:00
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await openBookmarkModal();
|
|
|
|
await click("#save-bookmark");
|
2020-05-02 16:31:44 +08:00
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
assert.ok(
|
|
|
|
exists(".topic-post:first-child button.bookmark.bookmarked"),
|
|
|
|
"it shows the bookmarked icon on the post"
|
|
|
|
);
|
|
|
|
assert.not(
|
|
|
|
exists(
|
|
|
|
".topic-post:first-child button.bookmark.bookmarked > .d-icon-discourse-bookmark-clock"
|
|
|
|
),
|
|
|
|
"it shows the regular bookmark active icon"
|
|
|
|
);
|
2020-05-02 16:31:44 +08:00
|
|
|
assert.verifySteps(["none"]);
|
2020-04-30 12:58:26 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
test("Deleting a bookmark with a reminder", async assert => {
|
|
|
|
pretender.delete("/bookmarks/999", () => [
|
|
|
|
200,
|
|
|
|
{
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
success: "OK",
|
|
|
|
topic_bookmarked: false
|
|
|
|
}
|
|
|
|
]);
|
2020-05-02 16:31:44 +08:00
|
|
|
|
|
|
|
mockSuccessfulBookmarkPost(assert);
|
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await openBookmarkModal();
|
|
|
|
await click("#tap_tile_tomorrow");
|
2020-05-02 16:31:44 +08:00
|
|
|
|
|
|
|
assert.verifySteps(["tomorrow"]);
|
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
await openEditBookmarkModal();
|
2020-05-02 16:31:44 +08:00
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
assert.ok(exists("#bookmark-reminder-modal"), "it shows the bookmark modal");
|
2020-05-02 16:31:44 +08:00
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
await click("#delete-bookmark");
|
2020-05-02 16:31:44 +08:00
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
assert.ok(exists(".bootbox.modal"), "it asks for delete confirmation");
|
|
|
|
assert.ok(
|
|
|
|
find(".bootbox.modal")
|
|
|
|
.text()
|
|
|
|
.includes(I18n.t("bookmarks.confirm_delete")),
|
|
|
|
"it shows delete confirmation message"
|
|
|
|
);
|
2020-05-02 16:31:44 +08:00
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
await click(".bootbox.modal .btn-primary");
|
2020-05-02 16:31:44 +08:00
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
assert.not(
|
|
|
|
exists(".topic-post:first-child button.bookmark.bookmarked"),
|
|
|
|
"it no longer shows the bookmarked icon on the post after bookmark is deleted"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Cancelling saving a bookmark", async assert => {
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await openBookmarkModal();
|
|
|
|
await click(".d-modal-cancel");
|
|
|
|
assert.not(
|
|
|
|
exists(".topic-post:first-child button.bookmark.bookmarked"),
|
|
|
|
"it does not show the bookmarked icon on the post because it is not saved"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Editing a bookmark", async assert => {
|
2020-05-02 16:31:44 +08:00
|
|
|
mockSuccessfulBookmarkPost(assert);
|
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
await visit("/t/internationalization-localization/280");
|
2020-05-11 09:01:47 +08:00
|
|
|
let now = moment.tz(loggedInUser().resolvedTimezone(loggedInUser()));
|
2020-04-30 12:58:26 +08:00
|
|
|
let tomorrow = now.add(1, "day").format("YYYY-MM-DD");
|
|
|
|
await openBookmarkModal();
|
|
|
|
await fillIn("input#bookmark-name", "Test name");
|
|
|
|
await click("#tap_tile_tomorrow");
|
2020-05-02 16:31:44 +08:00
|
|
|
|
2020-04-30 12:58:26 +08:00
|
|
|
await openEditBookmarkModal();
|
|
|
|
assert.equal(
|
|
|
|
find("#bookmark-name").val(),
|
|
|
|
"Test name",
|
|
|
|
"it should prefill the bookmark name"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
find("#bookmark-custom-date > input").val(),
|
|
|
|
tomorrow,
|
|
|
|
"it should prefill the bookmark date"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
find("#bookmark-custom-time").val(),
|
|
|
|
"08:00",
|
|
|
|
"it should prefill the bookmark time"
|
|
|
|
);
|
2020-05-02 16:31:44 +08:00
|
|
|
assert.verifySteps(["tomorrow"]);
|
2020-04-30 12:58:26 +08:00
|
|
|
});
|
2020-05-05 14:28:31 +08:00
|
|
|
|
2020-07-14 12:02:13 +08:00
|
|
|
acceptance("Bookmarking - Mobile", {
|
|
|
|
loggedIn: true,
|
|
|
|
mobileView: true,
|
|
|
|
afterEach() {
|
|
|
|
sandbox.restore();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-05-13 14:58:26 +08:00
|
|
|
QUnit.skip(
|
|
|
|
"Editing a bookmark that has a Later Today reminder, and it is before 6pm today",
|
|
|
|
async assert => {
|
|
|
|
await acceptanceUseFakeClock("2020-05-04T13:00:00", async () => {
|
|
|
|
mockSuccessfulBookmarkPost(assert);
|
|
|
|
await visit("/t/internationalization-localization/280");
|
|
|
|
await openBookmarkModal();
|
|
|
|
await fillIn("input#bookmark-name", "Test name");
|
|
|
|
await click("#tap_tile_later_today");
|
|
|
|
await openEditBookmarkModal();
|
|
|
|
assert.not(
|
|
|
|
exists("#bookmark-custom-date > input"),
|
|
|
|
"it does not show the custom date input"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
exists("#tap_tile_later_today.active"),
|
|
|
|
"it preselects Later Today"
|
|
|
|
);
|
|
|
|
assert.verifySteps(["later_today"]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|