DEV: migrates webhook-status to gjs (#28407)

This commit also adds a test for this component.

---------

Co-authored-by: Jarek Radosz <jarek@cvx.dev>
This commit is contained in:
Joffrey JAFFEUX 2024-08-17 17:44:56 +02:00 committed by GitHub
parent ea8516b38d
commit 3e69f31e0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 82 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import Component from "@glimmer/component";
import icon from "discourse-common/helpers/d-icon";
import I18n from "discourse-i18n";
export default class WebhookStatus extends Component {
@ -6,7 +7,7 @@ export default class WebhookStatus extends Component {
iconClasses = ["text-muted", "text-danger", "text-successful", "text-muted"];
get status() {
const lastStatus = this.args.webhook.last_delivery_status;
const lastStatus = this.args.webhook.get("last_delivery_status");
return this.args.deliveryStatuses.find((s) => s.id === lastStatus);
}
@ -21,4 +22,9 @@ export default class WebhookStatus extends Component {
get iconClass() {
return this.iconClasses[this.status.id - 1];
}
<template>
{{icon this.iconName class=this.iconClass}}
{{this.deliveryStatus}}
</template>
}

View File

@ -1,2 +0,0 @@
{{d-icon this.iconName (hash class=this.iconClass)}}
{{this.deliveryStatus}}

View File

@ -77,6 +77,10 @@ export default class CoreFabricators {
});
}
webhook(args = {}) {
return this.store.createRecord("web-hook", args);
}
upload() {
return {
extension: "jpeg",

View File

@ -0,0 +1,71 @@
import { getOwner } from "@ember/owner";
import { render, rerender } from "@ember/test-helpers";
import { module, test } from "qunit";
import CoreFabricators from "discourse/lib/fabricators";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import WebhookStatus from "admin/components/webhook-status";
module("Integration | Component | webhook-status", function (hooks) {
setupRenderingTest(hooks);
const DELIVERY_STATUSES = [
{ id: 1, name: "inactive" },
{ id: 2, name: "failed" },
{ id: 3, name: "successful" },
{ id: 4, name: "disabled" },
];
test("deliveryStatus", async function (assert) {
const webhook = new CoreFabricators(getOwner(this)).webhook();
await render(<template>
<WebhookStatus
@deliveryStatuses={{DELIVERY_STATUSES}}
@webhook={{webhook}}
/>
</template>);
assert.dom().hasText("Inactive");
webhook.set("last_delivery_status", 2);
await rerender();
assert.dom().hasText("Failed");
});
test("iconName", async function (assert) {
const webhook = new CoreFabricators(getOwner(this)).webhook();
await render(<template>
<WebhookStatus
@deliveryStatuses={{DELIVERY_STATUSES}}
@webhook={{webhook}}
/>
</template>);
assert.dom(".d-icon-far-circle").exists();
webhook.set("last_delivery_status", 2);
await rerender();
assert.dom(".d-icon-times-circle").exists();
});
test("iconClass", async function (assert) {
const webhook = new CoreFabricators(getOwner(this)).webhook();
await render(<template>
<WebhookStatus
@deliveryStatuses={{DELIVERY_STATUSES}}
@webhook={{webhook}}
/>
</template>);
assert.dom(".d-icon").hasClass("text-muted");
webhook.set("last_delivery_status", 2);
await rerender();
assert.dom(".d-icon").hasClass("text-danger");
});
});