mirror of
https://ghfast.top/https://github.com/discourse/discourse-translator.git
synced 2026-07-16 11:46:33 +08:00
Currently the 🌐 only appears in dual-text mode (not inline translation mode) when the `experimental_topic_translation` feature is disabled. This means we are unable to translate old posts when in `experimental_topic_translation`. This PR allows 🌐 to show up when `experimental_topic_translation` is enabled, and does not show the dual-text translation below (the old method) but replaces the content inline instead. In addition in this PR, when `experimental_topic_translation` is enabled, it takes the response from /translate and updates the post cooked and topic title for inline replacement. (in other scenarios, translation updates are done by messagebus) (also backfills many untested js files)
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
import { render } from "@ember/test-helpers";
|
|
import { hbs } from "ember-cli-htmlbars";
|
|
import { module, test } from "qunit";
|
|
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
|
|
module("Integration | Component | toggle-translation-button", function (hooks) {
|
|
setupRenderingTest(hooks);
|
|
|
|
test("doesn't render when post cannot be translated", async function (assert) {
|
|
this.set("post", { can_translate: false });
|
|
|
|
await render(hbs`
|
|
<PostMenu::ToggleTranslationButton @post={{this.post}} />
|
|
`);
|
|
|
|
assert.dom("button").doesNotExist();
|
|
});
|
|
|
|
test("renders translation button with correct states", async function (assert) {
|
|
const post = {
|
|
can_translate: true,
|
|
isTranslated: false,
|
|
isTranslating: false,
|
|
};
|
|
|
|
this.set("post", post);
|
|
|
|
await render(hbs`
|
|
<PostMenu::ToggleTranslationButton @post={{this.post}} @showLabel={{true}} />
|
|
`);
|
|
|
|
assert.dom("button").exists();
|
|
assert.dom("button").hasText("View translation");
|
|
assert.dom("button").doesNotHaveClass("translated");
|
|
|
|
post.isTranslating = true;
|
|
await render(hbs`
|
|
<PostMenu::ToggleTranslationButton @post={{this.post}} @showLabel={{true}} />
|
|
`);
|
|
assert.dom("button").hasAttribute("disabled");
|
|
assert.dom("button").hasText("Translating");
|
|
|
|
post.isTranslating = false;
|
|
post.isTranslated = true;
|
|
await render(hbs`
|
|
<PostMenu::ToggleTranslationButton @post={{this.post}} @showLabel={{true}} />
|
|
`);
|
|
assert.dom("button").hasClass("translated");
|
|
assert.dom("button").hasText("Hide translation");
|
|
});
|
|
});
|