0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-12-04 22:31:09 +01:00
discourse-custom-wizard/test/javascripts/acceptance/field-test.js

239 Zeilen
7,5 KiB
JavaScript

2022-06-15 08:59:09 +02:00
import { click, fillIn, 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,
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";
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));
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"
);
});
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"),
"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"
);
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");
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"
);
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");
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");
2022-07-27 15:50:49 +02:00
assert.ok(exists(".wizard-field.category-field .select-kit-collection li"));
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.
});
});