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/integration/components/image-uploader-test.js
Robin Ward 435a9913a4 REFACTOR: Replace global find with queryAll
In newer Embers jQuery is removed. There is a `find` but it only returns
one element and not a jQuery selector. This patch migrates our code to a
new helper `queryAll` which allows us to remove the global.
2020-10-29 14:45:51 -04:00

94 lines
2.1 KiB
JavaScript

import { queryAll } from "discourse/tests/helpers/qunit-helpers";
import { moduleForComponent } from "ember-qunit";
import componentTest from "discourse/tests/helpers/component-test";
import { click } from "@ember/test-helpers";
moduleForComponent("image-uploader", { integration: true });
componentTest("with image", {
template:
"{{image-uploader imageUrl='/images/avatar.png' placeholderUrl='/not/used.png'}}",
async test(assert) {
assert.equal(
queryAll(".d-icon-far-image").length,
1,
"it displays the upload icon"
);
assert.equal(
queryAll(".d-icon-far-trash-alt").length,
1,
"it displays the trash icon"
);
assert.equal(
queryAll(".placeholder-overlay").length,
0,
"it does not display the placeholder image"
);
await click(".image-uploader-lightbox-btn");
assert.equal(
$(".mfp-container").length,
1,
"it displays the image lightbox"
);
},
});
componentTest("without image", {
template: "{{image-uploader}}",
test(assert) {
assert.equal(
queryAll(".d-icon-far-image").length,
1,
"it displays the upload icon"
);
assert.equal(
queryAll(".d-icon-far-trash-alt").length,
0,
"it does not display trash icon"
);
assert.equal(
queryAll(".image-uploader-lightbox-btn").length,
0,
"it does not display the button to open image lightbox"
);
},
});
componentTest("with placeholder", {
template: "{{image-uploader placeholderUrl='/images/avatar.png'}}",
test(assert) {
assert.equal(
queryAll(".d-icon-far-image").length,
1,
"it displays the upload icon"
);
assert.equal(
queryAll(".d-icon-far-trash-alt").length,
0,
"it does not display trash icon"
);
assert.equal(
queryAll(".image-uploader-lightbox-btn").length,
0,
"it does not display the button to open image lightbox"
);
assert.equal(
queryAll(".placeholder-overlay").length,
1,
"it displays the placeholder image"
);
},
});