2024-05-29 16:51:51 +02:00
|
|
|
import { getOwner } from "@ember/application";
|
2024-05-29 16:54:34 +02:00
|
|
|
import {
|
|
|
|
click,
|
|
|
|
fillIn,
|
|
|
|
settled,
|
|
|
|
triggerKeyEvent,
|
|
|
|
visit,
|
|
|
|
} from "@ember/test-helpers";
|
2022-03-16 12:33:34 +01:00
|
|
|
import { test } from "qunit";
|
2022-07-27 12:47:50 +02:00
|
|
|
import {
|
|
|
|
acceptance,
|
2022-03-16 12:33:34 +01:00
|
|
|
count,
|
2024-05-29 16:51:51 +02:00
|
|
|
createFile,
|
2022-07-27 12:47:50 +02:00
|
|
|
exists,
|
2022-07-27 16:30:45 +02:00
|
|
|
query,
|
2022-07-27 15:50:49 +02:00
|
|
|
visible,
|
2022-07-27 12:47:50 +02:00
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
|
|
|
import { allFieldsWizard } from "../helpers/wizard";
|
2022-03-16 12:33:34 +01:00
|
|
|
import tagsJson from "../fixtures/tags";
|
|
|
|
import usersJson from "../fixtures/users";
|
|
|
|
|
2024-05-29 16:51:51 +02:00
|
|
|
const wizardComposerEdtiorEventPrefix = "wizard-editor";
|
|
|
|
|
2022-07-27 12:47:50 +02:00
|
|
|
acceptance("Field | Fields", function (needs) {
|
|
|
|
needs.pretender((server, helper) => {
|
2022-07-27 16:30:45 +02:00
|
|
|
server.get("/w/wizard.json", () => helper.response(allFieldsWizard));
|
|
|
|
server.get("/tags/filter/search", () =>
|
2022-07-27 15:50:49 +02:00
|
|
|
helper.response({ results: tagsJson["tags"] })
|
|
|
|
);
|
2022-07-27 16:30:45 +02:00
|
|
|
server.get("/u/search/users", () => helper.response(usersJson));
|
2024-05-29 16:51:51 +02:00
|
|
|
|
2024-05-29 16:54:34 +02:00
|
|
|
server.post(
|
|
|
|
"/uploads.json",
|
|
|
|
() => {
|
|
|
|
return helper.response({
|
|
|
|
extension: "jpeg",
|
|
|
|
filesize: 126177,
|
|
|
|
height: 800,
|
|
|
|
human_filesize: "123 KB",
|
|
|
|
id: 202,
|
|
|
|
original_filename: "avatar.PNG.jpg",
|
|
|
|
retain_hours: null,
|
|
|
|
short_path: "/uploads/short-url/yoj8pf9DdIeHRRULyw7i57GAYdz.jpeg",
|
|
|
|
short_url: "upload://yoj8pf9DdIeHRRULyw7i57GAYdz.jpeg",
|
|
|
|
thumbnail_height: 320,
|
|
|
|
thumbnail_width: 690,
|
|
|
|
url: "/images/discourse-logo-sketch-small.png",
|
|
|
|
width: 1920,
|
|
|
|
});
|
2024-05-29 16:51:51 +02:00
|
|
|
},
|
|
|
|
500 // this delay is important to slow down the uploads a bit so we can let elements of the interface update
|
|
|
|
);
|
2022-07-27 12:47:50 +02:00
|
|
|
});
|
|
|
|
|
2022-06-15 08:59:09 +02:00
|
|
|
test("Text", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(exists(".wizard-field.text-field input.wizard-focusable"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Textarea", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(
|
|
|
|
visible(".wizard-field.textarea-field textarea.wizard-focusable")
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Composer", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(
|
|
|
|
visible(".wizard-field.composer-field .wizard-field-composer textarea")
|
|
|
|
);
|
2022-07-27 12:47:50 +02:00
|
|
|
assert.ok(
|
|
|
|
exists(".wizard-field.composer-field .d-editor-button-bar button")
|
2022-06-15 08:59:09 +02:00
|
|
|
);
|
|
|
|
assert.ok(visible(".wizard-btn.toggle-preview"));
|
|
|
|
|
|
|
|
await fillIn(
|
|
|
|
".wizard-field.composer-field .wizard-field-composer textarea",
|
|
|
|
"Input in composer"
|
|
|
|
);
|
|
|
|
await click(".wizard-btn.toggle-preview");
|
|
|
|
assert.strictEqual(
|
|
|
|
query(
|
|
|
|
".wizard-field.composer-field .wizard-field-composer .d-editor-preview-wrapper p"
|
|
|
|
).textContent.trim(),
|
|
|
|
"Input in composer"
|
|
|
|
);
|
|
|
|
});
|
2024-05-29 16:51:51 +02:00
|
|
|
|
|
|
|
test("Composer - Upload Disables Next Button", async function (assert) {
|
|
|
|
await visit("/w/wizard");
|
|
|
|
const appEvents = getOwner(this).lookup("service:app-events");
|
|
|
|
const done = assert.async();
|
|
|
|
|
2024-05-29 16:54:34 +02:00
|
|
|
appEvents.on(
|
|
|
|
`${wizardComposerEdtiorEventPrefix}:all-uploads-complete`,
|
|
|
|
async () => {
|
|
|
|
await settled();
|
|
|
|
assert.ok(!exists(".wizard-btn.next.primary:disabled"));
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
2024-05-29 16:51:51 +02:00
|
|
|
|
2024-05-29 16:54:34 +02:00
|
|
|
appEvents.on(
|
|
|
|
`${wizardComposerEdtiorEventPrefix}:upload-started`,
|
|
|
|
async () => {
|
|
|
|
await settled();
|
|
|
|
assert.ok(exists(".wizard-btn.next.primary:disabled"));
|
|
|
|
}
|
|
|
|
);
|
2024-05-29 16:51:51 +02:00
|
|
|
|
|
|
|
const image = createFile("avatar.png");
|
|
|
|
appEvents.trigger(`${wizardComposerEdtiorEventPrefix}:add-files`, image);
|
|
|
|
});
|
|
|
|
|
2023-03-10 15:39:40 +01:00
|
|
|
test("Composer - Hyperlink", async function (assert) {
|
|
|
|
await visit("/w/wizard");
|
|
|
|
assert.ok(
|
|
|
|
visible(".wizard-field.composer-field .wizard-field-composer textarea")
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
exists(".wizard-field.composer-field .d-editor-button-bar button")
|
|
|
|
);
|
|
|
|
assert.ok(visible(".wizard-btn.toggle-preview"));
|
|
|
|
await fillIn(
|
|
|
|
".wizard-field.composer-field .wizard-field-composer textarea",
|
|
|
|
"This is a link to "
|
|
|
|
);
|
|
|
|
assert.ok(
|
2023-11-16 18:57:07 +01:00
|
|
|
!exists(".d-modal.insert-hyperlink-modal"),
|
2023-03-10 15:39:40 +01:00
|
|
|
"no hyperlink modal by default"
|
|
|
|
);
|
|
|
|
await click(
|
|
|
|
".wizard-field.composer-field .wizard-field-composer .d-editor button.link"
|
|
|
|
);
|
2023-11-16 17:41:54 +01:00
|
|
|
assert.ok(
|
|
|
|
exists(".d-modal.insert-hyperlink-modal"),
|
|
|
|
"hyperlink modal visible"
|
|
|
|
);
|
2023-03-10 15:39:40 +01:00
|
|
|
|
2023-11-16 17:33:46 +01:00
|
|
|
await fillIn(".d-modal__body.insert-link .inputs .link-url", "google.com");
|
|
|
|
await fillIn(".d-modal__body.insert-link .inputs .link-text", "Google");
|
|
|
|
await click(".d-modal__footer button.btn-primary");
|
2023-03-10 15:39:40 +01:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
query(".wizard-field.composer-field .wizard-field-composer textarea")
|
|
|
|
.value,
|
|
|
|
"This is a link to [Google](https://google.com)",
|
|
|
|
"adds link with url and text, prepends 'https://'"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
!exists(
|
|
|
|
".wizard-field.composer-field .wizard-field-composer .insert-link.modal-body"
|
|
|
|
),
|
|
|
|
"modal dismissed after submitting link"
|
|
|
|
);
|
|
|
|
|
|
|
|
await fillIn(
|
|
|
|
".wizard-field.composer-field .wizard-field-composer textarea",
|
|
|
|
"Reset textarea contents."
|
|
|
|
);
|
|
|
|
|
|
|
|
await click(
|
|
|
|
".wizard-field.composer-field .wizard-field-composer .d-editor button.link"
|
|
|
|
);
|
2023-11-16 17:33:46 +01:00
|
|
|
await fillIn(".d-modal__body.insert-link .inputs .link-url", "google.com");
|
|
|
|
await fillIn(".d-modal__body.insert-link .inputs .link-text", "Google");
|
|
|
|
await click(".d-modal__footer button.btn-danger");
|
2023-03-10 15:39:40 +01:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
query(".wizard-field.composer-field .wizard-field-composer textarea")
|
|
|
|
.value,
|
|
|
|
"Reset textarea contents.",
|
|
|
|
"does not insert anything after cancelling"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
!exists(".insert-link.modal-body"),
|
|
|
|
"modal dismissed after cancelling"
|
|
|
|
);
|
|
|
|
});
|
2022-06-15 08:59:09 +02:00
|
|
|
|
|
|
|
test("Text Only", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(visible(".wizard-field.text-only-field label.field-label"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Date", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(visible(".wizard-field.date-field input.date-picker"));
|
|
|
|
await click(".wizard-field.date-field input.date-picker");
|
|
|
|
assert.ok(visible(".wizard-field.date-field .pika-single"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Time", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(visible(".wizard-field.time-field .d-time-input .select-kit"));
|
|
|
|
await click(
|
|
|
|
".wizard-field.time-field .d-time-input .select-kit .select-kit-header"
|
|
|
|
);
|
|
|
|
assert.ok(visible(".wizard-field.time-field .select-kit-collection"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Date Time", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(
|
|
|
|
visible(".wizard-field.date-time-field .d-date-time-input .select-kit")
|
|
|
|
);
|
|
|
|
await click(
|
|
|
|
".wizard-field.date-time-field .d-date-input input.date-picker"
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
visible(".wizard-field.date-time-field .d-date-input .pika-single")
|
|
|
|
);
|
|
|
|
await click(
|
|
|
|
".wizard-field.date-time-field .d-time-input .select-kit .select-kit-header"
|
|
|
|
);
|
|
|
|
assert.ok(visible(".wizard-field.date-time-field .select-kit-collection"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Number", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(visible(".wizard-field.number-field input[type='number']"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Checkbox", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(visible(".wizard-field.checkbox-field input[type='checkbox']"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Url", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(visible(".wizard-field.url-field input[type='text']"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Upload", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(
|
|
|
|
visible(".wizard-field.upload-field label.wizard-btn-upload-file")
|
|
|
|
);
|
|
|
|
assert.ok(exists(".wizard-field.upload-field input.hidden-upload-field"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Dropdown", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(visible(".wizard-field.dropdown-field .single-select-header"));
|
|
|
|
await click(".wizard-field.dropdown-field .select-kit-header");
|
|
|
|
assert.strictEqual(
|
|
|
|
count(".wizard-field.dropdown-field .select-kit-collection li"),
|
|
|
|
3
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Tag", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(visible(".wizard-field.tag-field .multi-select-header"));
|
|
|
|
await click(".wizard-field.tag-field .select-kit-header");
|
|
|
|
assert.strictEqual(
|
|
|
|
count(".wizard-field.tag-field .select-kit-collection li"),
|
|
|
|
2
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Category", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(visible(".wizard-field.category-field .multi-select-header"));
|
|
|
|
await click(".wizard-field.category-field .select-kit-header");
|
2024-01-26 16:18:11 +01:00
|
|
|
assert.ok(
|
|
|
|
exists(
|
|
|
|
".wizard-field.category-field .select-kit-collection .select-kit-row"
|
|
|
|
)
|
|
|
|
);
|
2022-06-15 08:59:09 +02:00
|
|
|
});
|
|
|
|
|
2024-06-28 15:08:57 +02:00
|
|
|
test("Topic", async function (assert) {
|
|
|
|
await visit("/w/wizard");
|
|
|
|
assert.ok(visible(".wizard-field.topic-field .multi-select-header"));
|
|
|
|
await click(".wizard-field.topic-field .select-kit-header");
|
|
|
|
assert.ok(
|
|
|
|
exists(".wizard-field.topic-field .topic-selector .select-kit-filter")
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-06-15 08:59:09 +02:00
|
|
|
test("Group", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
assert.ok(visible(".wizard-field.group-field .single-select-header"));
|
|
|
|
await click(".wizard-field.group-field .select-kit-header");
|
|
|
|
assert.strictEqual(
|
|
|
|
count(".wizard-field.group-field .select-kit-collection li"),
|
|
|
|
10
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("User", async function (assert) {
|
2022-07-27 12:47:50 +02:00
|
|
|
await visit("/w/wizard");
|
2022-06-15 08:59:09 +02:00
|
|
|
await fillIn(
|
|
|
|
".wizard-field.user-selector-field input.ember-text-field",
|
|
|
|
"a"
|
|
|
|
);
|
|
|
|
await triggerKeyEvent(
|
|
|
|
".wizard-field.user-selector-field input.ember-text-field",
|
|
|
|
"keyup",
|
|
|
|
"a".charCodeAt(0)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.ok(visible(".wizard-field.user-selector-field .ac-wrap"));
|
|
|
|
// TODO: add assertion for ac results. autocomplete does not appear in time.
|
|
|
|
});
|
|
|
|
});
|