DEV: Use the block form of `module()` (#17151)

This commit is contained in:
Jarek Radosz 2022-06-20 15:42:10 +02:00 committed by GitHub
parent 321118f384
commit ba2c7b8f35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 713 additions and 709 deletions

View File

@ -1,22 +1,26 @@
import { module, test } from "qunit"; import { module, test } from "qunit";
import Theme from "admin/models/theme"; import Theme from "admin/models/theme";
module("Unit | Model | theme"); module("Unit | Model | theme", function () {
test("can add an upload correctly", function (assert) {
let theme = Theme.create();
test("can add an upload correctly", function (assert) { assert.strictEqual(
let theme = Theme.create(); theme.get("uploads.length"),
0,
"uploads should be an empty array"
);
assert.strictEqual( theme.setField("common", "bob", "", 999, 2);
theme.get("uploads.length"), let fields = theme.get("theme_fields");
0, assert.strictEqual(fields.length, 1, "expecting 1 theme field");
"uploads should be an empty array" assert.strictEqual(
); fields[0].upload_id,
999,
"expecting upload id to be set"
);
assert.strictEqual(fields[0].type_id, 2, "expecting type id to be set");
theme.setField("common", "bob", "", 999, 2); assert.strictEqual(theme.get("uploads.length"), 1, "expecting an upload");
let fields = theme.get("theme_fields"); });
assert.strictEqual(fields.length, 1, "expecting 1 theme field");
assert.strictEqual(fields[0].upload_id, 999, "expecting upload id to be set");
assert.strictEqual(fields[0].type_id, 2, "expecting type id to be set");
assert.strictEqual(theme.get("uploads.length"), 1, "expecting an upload");
}); });

View File

@ -1,8 +1,6 @@
import PrettyText, { buildOptions } from "pretty-text/pretty-text"; import PrettyText, { buildOptions } from "pretty-text/pretty-text";
import { module, test } from "qunit"; import { module, test } from "qunit";
module("lib:details-cooked-test");
const defaultOpts = buildOptions({ const defaultOpts = buildOptions({
siteSettings: { siteSettings: {
enable_emoji: true, enable_emoji: true,
@ -14,26 +12,28 @@ const defaultOpts = buildOptions({
getURL: (url) => url, getURL: (url) => url,
}); });
test("details", function (assert) { module("lib:details-cooked-test", function () {
const cooked = (input, expected, text) => { test("details", function (assert) {
assert.strictEqual( const cooked = (input, expected, text) => {
new PrettyText(defaultOpts).cook(input), assert.strictEqual(
expected.replace(/\/>/g, ">"), new PrettyText(defaultOpts).cook(input),
text expected.replace(/\/>/g, ">"),
text
);
};
cooked(
`<details><summary>Info</summary>coucou</details>`,
`<details><summary>Info</summary>coucou</details>`,
"manual HTML for details"
); );
};
cooked(
`<details><summary>Info</summary>coucou</details>`,
`<details><summary>Info</summary>coucou</details>`,
"manual HTML for details"
);
cooked( cooked(
"[details=testing]\ntest\n[/details]", "[details=testing]\ntest\n[/details]",
`<details> `<details>
<summary> <summary>
testing</summary> testing</summary>
<p>test</p> <p>test</p>
</details>` </details>`
); );
});
}); });

View File

@ -4,8 +4,6 @@ import { module, test } from "qunit";
const PARIS = "Europe/Paris"; const PARIS = "Europe/Paris";
const SYDNEY = "Australia/Sydney"; const SYDNEY = "Australia/Sydney";
module("lib:date-with-zone-helper");
function buildDateHelper(params = {}) { function buildDateHelper(params = {}) {
return new DateWithZoneHelper({ return new DateWithZoneHelper({
year: params.year || 2020, year: params.year || 2020,
@ -18,152 +16,154 @@ function buildDateHelper(params = {}) {
}); });
} }
test("#format", function (assert) { module("lib:date-with-zone-helper", function () {
let date = buildDateHelper({ test("#format", function (assert) {
day: 15, let date = buildDateHelper({
month: 2, day: 15,
hour: 15, month: 2,
minute: 36, hour: 15,
timezone: PARIS, minute: 36,
timezone: PARIS,
});
assert.strictEqual(date.format(), "2020-03-15T15:36:00.000+01:00");
});
test("#unitRepetitionsBetweenDates", function (assert) {
let date;
date = buildDateHelper({
day: 15,
month: 1,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.strictEqual(
date.unitRepetitionsBetweenDates(
"1.hour",
moment.tz("2020-02-15 15:36", SYDNEY)
),
10,
"it correctly finds difference between timezones"
);
date = buildDateHelper({
day: 15,
month: 1,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.strictEqual(
date.unitRepetitionsBetweenDates(
"1.minute",
moment.tz("2020-02-15 15:36", PARIS)
),
0,
"it correctly finds no difference"
);
date = buildDateHelper({
day: 15,
month: 1,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.strictEqual(
date.unitRepetitionsBetweenDates(
"1.minute",
moment.tz("2020-02-15 15:37", PARIS)
),
1,
"it correctly finds no difference"
);
date = buildDateHelper({
day: 15,
month: 1,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.strictEqual(
date.unitRepetitionsBetweenDates(
"2.minutes",
moment.tz("2020-02-15 15:41", PARIS)
),
6,
"it correctly finds difference with a multiplicator"
);
});
test("#add", function (assert) {
let date;
let futureLocalDate;
date = buildDateHelper({
day: 19,
month: 2,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.notOk(date.isDST());
futureLocalDate = date.add(8, "months");
assert.notOk(futureLocalDate.isDST());
assert.strictEqual(
futureLocalDate.format(),
"2020-11-19T15:36:00.000+01:00",
"it correctly adds from a !isDST date to a !isDST date"
);
date = buildDateHelper({
day: 25,
month: 3,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.ok(date.isDST());
futureLocalDate = date.add(1, "year");
assert.ok(futureLocalDate.isDST());
assert.strictEqual(
futureLocalDate.format(),
"2021-04-25T15:36:00.000+02:00",
"it correctly adds from a isDST date to a isDST date"
);
date = buildDateHelper({
day: 25,
month: 2,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.notOk(date.isDST());
futureLocalDate = date.add(1, "week");
assert.ok(futureLocalDate.isDST());
assert.strictEqual(
futureLocalDate.format(),
"2020-04-01T15:36:00.000+02:00",
"it correctly adds from a !isDST date to a isDST date"
);
date = buildDateHelper({
day: 1,
month: 3,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.ok(date.isDST());
futureLocalDate = date.add(8, "months");
assert.notOk(futureLocalDate.isDST());
assert.strictEqual(
futureLocalDate.format(),
"2020-12-01T15:36:00.000+01:00",
"it correctly adds from a isDST date to a !isDST date"
);
}); });
assert.strictEqual(date.format(), "2020-03-15T15:36:00.000+01:00");
});
test("#unitRepetitionsBetweenDates", function (assert) {
let date;
date = buildDateHelper({
day: 15,
month: 1,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.strictEqual(
date.unitRepetitionsBetweenDates(
"1.hour",
moment.tz("2020-02-15 15:36", SYDNEY)
),
10,
"it correctly finds difference between timezones"
);
date = buildDateHelper({
day: 15,
month: 1,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.strictEqual(
date.unitRepetitionsBetweenDates(
"1.minute",
moment.tz("2020-02-15 15:36", PARIS)
),
0,
"it correctly finds no difference"
);
date = buildDateHelper({
day: 15,
month: 1,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.strictEqual(
date.unitRepetitionsBetweenDates(
"1.minute",
moment.tz("2020-02-15 15:37", PARIS)
),
1,
"it correctly finds no difference"
);
date = buildDateHelper({
day: 15,
month: 1,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.strictEqual(
date.unitRepetitionsBetweenDates(
"2.minutes",
moment.tz("2020-02-15 15:41", PARIS)
),
6,
"it correctly finds difference with a multiplicator"
);
});
test("#add", function (assert) {
let date;
let futureLocalDate;
date = buildDateHelper({
day: 19,
month: 2,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.notOk(date.isDST());
futureLocalDate = date.add(8, "months");
assert.notOk(futureLocalDate.isDST());
assert.strictEqual(
futureLocalDate.format(),
"2020-11-19T15:36:00.000+01:00",
"it correctly adds from a !isDST date to a !isDST date"
);
date = buildDateHelper({
day: 25,
month: 3,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.ok(date.isDST());
futureLocalDate = date.add(1, "year");
assert.ok(futureLocalDate.isDST());
assert.strictEqual(
futureLocalDate.format(),
"2021-04-25T15:36:00.000+02:00",
"it correctly adds from a isDST date to a isDST date"
);
date = buildDateHelper({
day: 25,
month: 2,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.notOk(date.isDST());
futureLocalDate = date.add(1, "week");
assert.ok(futureLocalDate.isDST());
assert.strictEqual(
futureLocalDate.format(),
"2020-04-01T15:36:00.000+02:00",
"it correctly adds from a !isDST date to a isDST date"
);
date = buildDateHelper({
day: 1,
month: 3,
hour: 15,
minute: 36,
timezone: PARIS,
});
assert.ok(date.isDST());
futureLocalDate = date.add(8, "months");
assert.notOk(futureLocalDate.isDST());
assert.strictEqual(
futureLocalDate.format(),
"2020-12-01T15:36:00.000+01:00",
"it correctly adds from a isDST date to a !isDST date"
);
}); });