Skip to content

Commit

Permalink
DEV: Update tests (#451)
Browse files Browse the repository at this point in the history
Mostly qunit-dom usage.
  • Loading branch information
CvX authored Oct 10, 2023
1 parent acba52f commit e4d1e22
Show file tree
Hide file tree
Showing 11 changed files with 406 additions and 491 deletions.
54 changes: 27 additions & 27 deletions test/javascripts/acceptance/admin-holidays-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { click, visit } from "@ember/test-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
Expand Down Expand Up @@ -36,23 +36,19 @@ acceptance("Admin - Discourse Calendar - Holidays", function (needs) {
await regions.expand();
await regions.selectRowByValue("ca");

assert.ok(
query(".holidays-list").innerText.includes("New Year's Day"),
"it displays holiday names"
);
assert.ok(
query(".holidays-list").innerText.includes("Good Friday"),
"it displays holiday names"
);
assert
.dom(".holidays-list")
.includesText("New Year's Day", "it displays holiday names");
assert
.dom(".holidays-list")
.includesText("Good Friday", "it displays holiday names");

assert.ok(
query(".holidays-list").innerText.includes("2022-01-01"),
"it displays holiday dates"
);
assert.ok(
query(".holidays-list").innerText.includes("2022-04-15"),
"it displays holiday dates"
);
assert
.dom(".holidays-list")
.includesText("2022-01-01", "it displays holiday dates");
assert
.dom(".holidays-list")
.includesText("2022-04-15", "it displays holiday dates");
});

test("disabling and enabling a holiday", async (assert) => {
Expand All @@ -62,16 +58,20 @@ acceptance("Admin - Discourse Calendar - Holidays", function (needs) {
await regions.expand();
await regions.selectRowByValue("ca");

await click("table tr:first-child button");
assert.ok(
query("table tr.disabled:first-child"),
"after clicking the disable button, it adds a .disabled CSS class"
);
await click("table tbody tr button");
assert
.dom("table tbody tr")
.hasClass(
"disabled",
"after clicking the disable button, it adds a .disabled CSS class"
);

await click("table tr.disabled:first-child button");
assert.ok(
query("table tr:first-child"),
"after clicking the enable button, it removes the .disabled CSS class"
);
await click("table tr.disabled button");
assert
.dom("table tbody tr")
.doesNotHaveClass(
"disabled",
"after clicking the enable button, it removes the .disabled CSS class"
);
});
});
11 changes: 5 additions & 6 deletions test/javascripts/acceptance/category-events-calendar-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { visit } from "@ember/test-helpers";

Expand Down Expand Up @@ -70,10 +70,9 @@ acceptance("Discourse Calendar - Category Events Calendar", function (needs) {
test("shows event calendar on category page", async (assert) => {
await visit("/c/bug/1");

assert.ok(
exists("#category-events-calendar"),
"Events calendar div exists."
);
assert.ok(exists(".fc-view-container"), "FullCalendar is loaded.");
assert
.dom("#category-events-calendar")
.exists("Events calendar div exists.");
assert.dom(".fc-view-container").exists("FullCalendar is loaded.");
});
});
47 changes: 22 additions & 25 deletions test/javascripts/acceptance/notifications-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,13 @@ acceptance("Discourse Calendar - Notifications", function (needs) {
)} Monthly Hangout #3`,
"before event reminder notification has the right content"
);
assert.ok(
assert.true(
notifications[0].href.endsWith("/t/monthly-hangout-3/993"),
"before event reminder notification links to the event topic"
);
assert.ok(
notifications[0].querySelector(".d-icon-calendar-day"),
"before event reminder notification has the right icon"
);
assert
.dom(".d-icon-calendar-day", notifications[0])
.exists("before event reminder notification has the right icon");

assert.strictEqual(
notifications[1].textContent.replaceAll(/\s+/g, " ").trim(),
Expand All @@ -138,14 +137,13 @@ acceptance("Discourse Calendar - Notifications", function (needs) {
)} Fancy title and pants`,
"ongoing event reminder notification has the right content"
);
assert.ok(
assert.true(
notifications[1].href.endsWith("/t/fancy-title-and-pants/339"),
"ongoing event reminder notification links to the event topic"
);
assert.ok(
notifications[1].querySelector(".d-icon-calendar-day"),
"ongoing event reminder notification has the right icon"
);
assert
.dom(".d-icon-calendar-day", notifications[1])
.exists("ongoing event reminder notification has the right icon");

assert.strictEqual(
notifications[2].textContent.replaceAll(/\s+/g, " ").trim(),
Expand All @@ -154,30 +152,28 @@ acceptance("Discourse Calendar - Notifications", function (needs) {
)} Topic with event and after_event reminder`,
"after event reminder notification has the right content"
);
assert.ok(
assert.true(
notifications[2].href.endsWith(
"/t/topic-with-event-and-after_event-reminder/834"
),
"after event reminder notification links to the event topic"
);
assert.ok(
notifications[2].querySelector(".d-icon-calendar-day"),
"after event reminder notification has the right icon"
);
assert
.dom(".d-icon-calendar-day", notifications[2])
.exists("after event reminder notification has the right icon");

assert.strictEqual(
notifications[3].textContent.replaceAll(/\s+/g, " ").trim(),
"imposter Tuesdays are for Among Us",
"event invitation notification has the right content"
);
assert.ok(
assert.true(
notifications[3].href.endsWith("/t/tuesdays-are-for-among-us/195"),
"event invitation notification links to the event topic"
);
assert.ok(
notifications[3].querySelector(".d-icon-calendar-day"),
"event invitation notification has the right icon"
);
assert
.dom(".d-icon-calendar-day", notifications[3])
.exists("event invitation notification has the right icon");

assert.strictEqual(
notifications[4].textContent.replaceAll(/\s+/g, " ").trim(),
Expand All @@ -187,13 +183,14 @@ acceptance("Discourse Calendar - Notifications", function (needs) {
)} Asia Pacific team call`,
"event invitation with predefined attendance notification has the right content"
);
assert.ok(
assert.true(
notifications[4].href.endsWith("/t/asia-pacific-team-call/348"),
"event invitation with predefined attendance notification links to the event topic"
);
assert.ok(
notifications[4].querySelector(".d-icon-calendar-day"),
"event invitation with predefined attendance notification has the right icon"
);
assert
.dom(".d-icon-calendar-day", notifications[4])
.exists(
"event invitation with predefined attendance notification has the right icon"
);
});
});
24 changes: 10 additions & 14 deletions test/javascripts/acceptance/post-event-builder-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { acceptance, query } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { click, fillIn, visit } from "@ember/test-helpers";
import selectKit from "discourse/tests/helpers/select-kit-helper";
Expand Down Expand Up @@ -36,15 +36,13 @@ acceptance("Post event - composer", function (needs) {
"Timezone can be changed"
);

const fromDate = query(`${modal} .from input[type=date]`);
await fillIn(fromDate, "2022-07-01");
await fillIn(`${modal} .from input[type=date]`, "2022-07-01");

const fromTime = selectKit(`${modal} .from .d-time-input .select-kit`);
await fromTime.expand();
await fromTime.selectRowByName("12:00");

const toDate = query(`${modal} .to input[type=date]`);
await fillIn(toDate, "2022-07-01");
await fillIn(`${modal} .to input[type=date]`, "2022-07-01");
const toTime = selectKit(`${modal} .to .d-time-input .select-kit`);
await toTime.expand();
await toTime.selectRowByName("13:00");
Expand All @@ -57,11 +55,12 @@ acceptance("Post event - composer", function (needs) {

await click(`${modal} .modal-footer .btn-primary`);

assert.strictEqual(
query(".d-editor-input").value,
`[event start="2022-07-01 12:00" status="public" timezone="Europe/Paris" end="2022-07-01 13:00" allowedGroups="trust_level_0"]\n[/event]`,
"bbcode is correct"
);
assert
.dom(".d-editor-input")
.hasValue(
`[event start="2022-07-01 12:00" status="public" timezone="Europe/Paris" end="2022-07-01 13:00" allowedGroups="trust_level_0"]\n[/event]`,
"bbcode is correct"
);
});

test("composer event builder - the timezone case", async function (assert) {
Expand Down Expand Up @@ -103,10 +102,7 @@ acceptance("Post event - composer", function (needs) {
await timezoneInput.selectRowByValue("Europe/London");

// The date should be still the same?
assert.strictEqual(
query(`${modal} .from input[type=date]`).value,
"2022-07-01"
);
assert.dom(`${modal} .from input[type=date]`).hasValue("2022-07-01");
} finally {
// Unfreeze time
moment.tz.guess.returns(previousZone);
Expand Down
16 changes: 8 additions & 8 deletions test/javascripts/acceptance/sidebar-upcoming-events-item-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { click, visit } from "@ember/test-helpers";
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";

acceptance("Discourse Calendar - hamburger action shown", function (needs) {
needs.user();
Expand Down Expand Up @@ -38,7 +38,7 @@ acceptance("Discourse Calendar - hamburger action hidden", function (needs) {
test("upcoming events hamburger action hidden", async function (assert) {
await visit("/");
await click(".hamburger-dropdown");
assert.notOk(exists(".widget-link[title='Upcoming events']"));
assert.dom(".widget-link[title='Upcoming events']").doesNotExist();
});
});

Expand All @@ -54,9 +54,9 @@ acceptance("Discourse Calendar - sidebar link shown", function (needs) {
test("upcoming events sidebar section link shown", async function (assert) {
await visit("/");
await click(".sidebar-more-section-links-details-summary");
assert.ok(
exists(".sidebar-section-link[data-link-name='upcoming-events']")
);
assert
.dom(".sidebar-section-link[data-link-name='upcoming-events']")
.exists();
});
});

Expand All @@ -72,8 +72,8 @@ acceptance("Discourse Calendar - sidebar link hidden", function (needs) {
test("upcoming events sidebar section link hidden", async function (assert) {
await visit("/");
await click(".sidebar-more-section-links-details-summary");
assert.notOk(
exists(".sidebar-section-link[data-link-name='upcoming-events']")
);
assert
.dom(".sidebar-section-link[data-link-name='upcoming-events']")
.doesNotExist();
});
});
15 changes: 8 additions & 7 deletions test/javascripts/acceptance/sort-event-topics-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { test } from "qunit";
import { visit } from "@ember/test-helpers";
import Site from "discourse/models/site";
Expand All @@ -16,11 +16,12 @@ acceptance("Calendar - Disable sorting headers", function (needs) {
site.categories[15].custom_fields = { disable_topic_resorting: true };

await visit("/c/bug");
assert.ok(exists(".topic-list"), "The list of topics was rendered");
assert.ok(
exists(".topic-list .topic-list-data"),
"The headers were rendered"
);
assert.ok(!exists(".topic-list .sortable"), "The headers are not sortable");
assert.dom(".topic-list").exists("The list of topics was rendered");
assert
.dom(".topic-list .topic-list-data")
.exists("The headers were rendered");
assert
.dom(".topic-list")
.doesNotHaveClass("sortable", "The headers are not sortable");
});
});
Loading

0 comments on commit e4d1e22

Please sign in to comment.