0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/plugins/discourse-lazy-videos/test/javascripts/components/lazy-video-test.gjs
Martin Brennan 79d1c792eb
DEV: Update test module name conventions (#40389)
Currently, most of the JS test modules follow this
convention:

```
module("Integration | Component | topic-dismiss-buttons"
```

Which is a legacy from when ember components etc were
rendered in templates like this:

```
{{d-button title="foo"}}
```

Instead, this commit updates all of them to follow this
PascalCase convention:

```
module("Integration | Component | TopicDismissButtons", function (hooks) {
```

No linting is added to enforce this, we suspect that it's
mostly a result of cargo culting, and people will add new
tests following PascalCase convention.

Also adds an initial AI skill for writing JS tests.
2026-05-29 15:19:55 +10:00

80 lines
2.4 KiB
Text
Vendored

import { click, render } from "@ember/test-helpers";
import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import LazyVideo from "../discourse/components/lazy-video";
module("Component | LazyVideo", function (hooks) {
setupRenderingTest(hooks);
this.attributes = {
url: "https://www.youtube.com/watch?v=kPRA0W1kECg",
thumbnail: "thumbnail.jpeg",
title: "15 Sorting Algorithms in 6 Minutes",
providerName: "youtube",
id: "kPRA0W1kECg",
dominantColor: "00ffff",
startTime: 234,
};
test("displays the correct video title", async function (assert) {
await render(
<template><LazyVideo @videoAttributes={{this.attributes}} /></template>
);
assert.dom(".title-link").hasText(this.attributes.title);
});
test("uses the correct video start time", async function (assert) {
await render(
<template><LazyVideo @videoAttributes={{this.attributes}} /></template>
);
assert.dom(".youtube-onebox").hasAttribute("data-video-start-time", "234");
});
test("displays the correct provider icon", async function (assert) {
await render(
<template><LazyVideo @videoAttributes={{this.attributes}} /></template>
);
assert.dom(".icon.youtube-icon").exists();
});
test("uses the dominant color from the dom", async function (assert) {
await render(
<template><LazyVideo @videoAttributes={{this.attributes}} /></template>
);
assert
.dom(".video-thumbnail")
.hasAttribute("style", "background-color: #00ffff;");
});
test("loads the iframe when clicked", async function (assert) {
await render(
<template><LazyVideo @videoAttributes={{this.attributes}} /></template>
);
assert.dom(".lazy-video-container.video-loaded").doesNotExist();
await click(".video-thumbnail.youtube");
assert.dom(".lazy-video-container.video-loaded iframe").exists();
});
test("accepts an optional onLoadedVideo callback function", async function (assert) {
this.set("foo", 1);
this.set("onLoadedVideo", () => this.set("foo", 2));
await render(
<template>
<LazyVideo
@videoAttributes={{this.attributes}}
@onLoadedVideo={{this.onLoadedVideo}}
/>
</template>
);
assert.strictEqual(this.foo, 1);
await click(".video-thumbnail.youtube");
assert.strictEqual(this.foo, 2);
});
});