FIX: improvements for download local dates (#14588)

* FIX: do not display add to calendar for past dates

There is no value in saving past dates into calendar

* FIX: remove postId and move ICS to frontend

PostId is not necessary and will make the solution more generic for dates which doesn't belong to a specific post.

Also, ICS file can be generated in JavaScript to avoid calling backend.
This commit is contained in:
Krzysztof Kotlarek
2021-10-14 09:22:44 +11:00
committed by GitHub
parent ae0ca39bd1
commit 9062fd9b7a
9 changed files with 134 additions and 161 deletions

View File

@ -16,6 +16,12 @@ acceptance(
needs.settings({ discourse_local_dates_enabled: true });
needs.pretender((server, helper) => {
const response = { ...fixturesByUrl["/t/281.json"] };
const startDate = moment
.tz("Africa/Cairo")
.add(1, "days")
.format("YYYY-MM-DD");
response.post_stream.posts[0].cooked = `<p><span data-date=\"${startDate}\" data-time=\"13:00:00\" class=\"discourse-local-date\" data-timezone=\"Africa/Cairo\" data-email-preview=\"${startDate}T11:00:00Z UTC\">${startDate}T11:00:00Z</span></p>`;
server.get("/t/281.json", () => helper.response(response));
});
@ -33,6 +39,32 @@ acceptance(
}
);
acceptance(
"Local Dates - Download calendar is not available for dates in the past",
function (needs) {
needs.user({ default_calendar: "none_selected" });
needs.settings({ discourse_local_dates_enabled: true });
needs.pretender((server, helper) => {
const response = { ...fixturesByUrl["/t/281.json"] };
const startDate = moment
.tz("Africa/Cairo")
.subtract(1, "days")
.format("YYYY-MM-DD");
response.post_stream.posts[0].cooked = `<p><span data-date=\"${startDate}\" data-time=\"13:00:00\" class=\"discourse-local-date\" data-timezone=\"Africa/Cairo\" data-email-preview=\"${startDate}T11:00:00Z UTC\">${startDate}T11:00:00Z</span></p>`;
server.get("/t/281.json", () => helper.response(response));
});
test("Does not show add to calendar button", async function (assert) {
await visit("/t/local-dates/281");
await click(".discourse-local-date");
assert.ok(!exists(document.querySelector(".download-calendar")));
});
}
);
acceptance(
"Local Dates - Download calendar with default calendar option set",
function (needs) {
@ -40,6 +72,12 @@ acceptance(
needs.settings({ discourse_local_dates_enabled: true });
needs.pretender((server, helper) => {
const response = { ...fixturesByUrl["/t/281.json"] };
const startDate = moment
.tz("Africa/Cairo")
.add(1, "days")
.format("YYYY-MM-DD");
response.post_stream.posts[0].cooked = `<p><span data-date=\"${startDate}\" data-time=\"13:00:00\" class=\"discourse-local-date\" data-timezone=\"Africa/Cairo\" data-email-preview=\"${startDate}T11:00:00Z UTC\">${startDate}T11:00:00Z</span></p>`;
response.title = " title to trim ";
server.get("/t/281.json", () => helper.response(response));
});
@ -50,6 +88,10 @@ acceptance(
});
test("saves into default calendar", async function (assert) {
const startDate = moment
.tz("Africa/Cairo")
.add(1, "days")
.format("YYYYMMDD");
await visit("/t/local-dates/281");
await click(".discourse-local-date");
@ -57,7 +99,7 @@ acceptance(
assert.ok(!exists(document.querySelector("#discourse-modal-title")));
assert.ok(
window.open.calledWith(
"https://www.google.com/calendar/event?action=TEMPLATE&text=Local%20dates&dates=20210930T110000Z/20210930T120000Z",
`https://www.google.com/calendar/event?action=TEMPLATE&text=title%20to%20trim&dates=${startDate}T110000Z/${startDate}T120000Z`,
"_blank",
"noopener",
"noreferrer"