0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-23 09:50:28 +01:00
discourse-custom-wizard/test/javascripts/acceptance/admin-wizards-api-test.js

132 Zeilen
4,2 KiB
JavaScript

2024-01-26 16:18:11 +01:00
import {
acceptance,
query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
2022-12-30 22:26:32 +01:00
import { test } from "qunit";
2023-07-10 08:52:32 +02:00
import { click, currentURL, fillIn, visit } from "@ember/test-helpers";
2023-01-16 05:46:12 +01:00
import selectKit from "discourse/tests/helpers/select-kit-helper";
2022-12-30 22:26:32 +01:00
import {
getBusinessAdminWizard,
getCustomFields,
2023-03-21 09:48:24 +01:00
getNewApi,
2023-09-25 17:07:41 +02:00
getSuppliers,
2022-12-30 22:26:32 +01:00
getWizard,
2023-03-21 09:56:48 +01:00
putNewApi,
2022-12-30 22:26:32 +01:00
} from "../helpers/admin-wizard";
acceptance("Admin | API tab", function (needs) {
needs.user();
needs.settings({
custom_wizard_enabled: true,
available_locales: JSON.stringify([{ name: "English", value: "en" }]),
});
needs.pretender((server, helper) => {
server.get("/admin/wizards/wizard", () => {
return helper.response(getWizard);
});
2023-09-24 18:35:20 +02:00
server.get("/admin/wizards/subscription", () => {
2022-12-30 22:26:32 +01:00
return helper.response(getBusinessAdminWizard);
});
server.get("/admin/wizards/custom-fields", () => {
return helper.response(getCustomFields);
});
server.get("/admin/wizards/api", () => {
2023-03-21 09:48:24 +01:00
return helper.response([
{
name: "new_api",
title: "new API",
endpoints: [{ id: "59e3b6", name: "ag" }],
},
]);
2022-12-30 22:26:32 +01:00
});
server.get("/admin/customize/user_fields", () => {
return helper.response({ user_fields: [] });
});
2023-01-16 05:46:12 +01:00
server.put("/admin/wizards/api/new_api", () => {
2023-03-21 09:56:48 +01:00
return helper.response(putNewApi);
2023-03-21 09:48:24 +01:00
});
server.get("/admin/wizards/api/new_api", () => {
2023-03-21 09:56:48 +01:00
return helper.response(getNewApi);
2022-12-30 22:26:32 +01:00
});
2023-09-25 16:41:01 +02:00
server.get("/admin/plugins/subscription-client/suppliers", () => {
return helper.response(getSuppliers);
});
2022-12-30 22:26:32 +01:00
});
test("Visit API tab and fill data", async function (assert) {
2022-12-30 22:26:32 +01:00
await visit("/admin/wizards/api");
2024-01-26 16:18:11 +01:00
const list = queryAll(".admin-controls li");
2022-12-30 22:26:32 +01:00
const count = list.length;
assert.equal(count, 6, "There should be 6 admin tabs");
2023-03-21 09:48:24 +01:00
2023-01-16 05:46:12 +01:00
// create new api
2023-03-21 09:48:24 +01:00
await click(".admin-wizard-controls button");
2023-01-16 05:46:12 +01:00
assert.ok(
query(".wizard-header.large").innerText.includes("New API"),
"it displays API creation message"
);
2023-03-21 09:48:24 +01:00
assert.equal(
currentURL(),
"/admin/wizards/api/create",
"clicking the button navigates to the correct URL"
);
2023-01-16 05:46:12 +01:00
// fill data
await fillIn('.metadata input[placeholder="Display name"]', "new API");
await fillIn('.metadata input[placeholder="Underscored"]', "new_api");
const fieldTypeDropdown = selectKit(
".wizard-api-authentication .settings .control-group.auth-type .select-kit"
);
await fieldTypeDropdown.expand();
await fieldTypeDropdown.selectRowByValue("basic");
await fillIn(
2023-07-10 22:31:47 +02:00
".wizard-api-authentication .settings .control-group:nth-child(3) .controls input",
2023-01-16 05:46:12 +01:00
"some_username"
);
await fillIn(
2023-07-10 22:31:47 +02:00
".wizard-api-authentication .settings .control-group:nth-child(4) .controls input",
2023-01-16 05:46:12 +01:00
"some_password"
);
2023-03-21 09:48:24 +01:00
await click(".wizard-api-endpoints button");
2023-01-16 05:46:12 +01:00
await fillIn(
'.wizard-api-endpoints .endpoint .top input[placeholder="Endpoint name"]',
"endpoint_name"
);
await fillIn(
'.wizard-api-endpoints .endpoint .top input[placeholder="Enter a url"]',
"https://test.api.com"
);
2023-03-21 09:48:24 +01:00
const endpointMethodDropdown = await selectKit(
2023-01-16 05:46:12 +01:00
'.wizard-api-endpoints .endpoint .bottom details:has(summary[name="Filter by: Select a method"])'
);
await endpointMethodDropdown.expand();
await endpointMethodDropdown.selectRowByValue("POST");
2023-03-21 09:48:24 +01:00
const contentTypeDropdown = await selectKit(
'.wizard-api-endpoints .endpoint .bottom details:has(summary[name="Filter by: Select a content type"])'
);
await contentTypeDropdown.expand();
await contentTypeDropdown.selectRowByValue("application/json");
const successCodesDropdown = await selectKit(
".wizard-api-endpoints .endpoint .bottom details.multi-select"
);
await successCodesDropdown.expand();
await successCodesDropdown.selectRowByValue(200);
await successCodesDropdown.selectRowByValue(100);
2023-01-16 05:46:12 +01:00
2023-03-21 09:48:24 +01:00
assert.strictEqual(
successCodesDropdown.header().value(),
"200,100",
"group should be set"
);
await click(".wizard-api-header.page button.btn-primary");
assert.equal(
currentURL(),
"/admin/wizards/api/new_api",
"clicking the button navigates to the correct URL"
);
2022-12-30 22:26:32 +01:00
});
});