This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/acceptance/user-drafts-stream-test.js
David Taylor 7edc941843
FIX: Ensure images do not change height when loading is complete (#16368)
Browsers automatically calculate an aspect ratio based on the width/height attributes of an `<img`. HOWEVER that aspect ratio only applies while the image is loading. Once loaded, it'll use the image's actual dimensions. This can cause things to jump around after loading. For example:
 - if a user deliberately inserts false width/height
 - the image fails to load (404)
 - an optimised image is a few pixels different, due to a rounding when resizing

This decorator explicitly sets the `aspect-ratio` property so that things are consistent throughout the lifetime of all `<img` elements.
2022-04-05 13:43:17 +01:00

68 lines
2.0 KiB
JavaScript

import {
acceptance,
count,
exists,
normalizeHtml,
query,
queryAll,
visible,
} from "discourse/tests/helpers/qunit-helpers";
import { click, visit } from "@ember/test-helpers";
import { test } from "qunit";
import { IMAGE_VERSION } from "pretty-text/emoji/version";
acceptance("User Drafts", function (needs) {
needs.user();
test("Stream", async function (assert) {
await visit("/u/eviltrout/activity/drafts");
assert.strictEqual(count(".user-stream-item"), 3, "has drafts");
await click(".user-stream-item:first-child .remove-draft");
assert.ok(visible(".bootbox"));
await click(".bootbox .btn-primary");
assert.strictEqual(
count(".user-stream-item"),
2,
"draft removed, list length diminished by one"
);
await visit("/");
assert.ok(visible("#create-topic"));
assert.ok(
!exists("#create-topic.open-draft"),
"Open Draft button is not present"
);
});
test("Stream - resume draft", async function (assert) {
await visit("/u/eviltrout/activity/drafts");
assert.ok(exists(".user-stream-item"), "has drafts");
await click(".user-stream-item .resume-draft");
assert.strictEqual(
queryAll(".d-editor-input").val().trim(),
"A fun new topic for testing drafts."
);
});
test("Stream - has excerpt", async function (assert) {
await visit("/u/eviltrout/activity/drafts");
assert.ok(exists(".user-stream-item"), "has drafts");
assert.strictEqual(
query(".user-stream-item:nth-child(3) .category").textContent,
"meta"
);
assert.strictEqual(
normalizeHtml(
query(".user-stream-item:nth-child(3) .excerpt").innerHTML.trim()
),
normalizeHtml(
`here goes a reply to a PM <img src="/images/emoji/google_classic/slight_smile.png?v=${IMAGE_VERSION}" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20" style="aspect-ratio: 20 / 20;">`
),
"shows the excerpt"
);
});
});