discourse/test/javascripts/acceptance/emoji-picker-test.js.es6

188 lines
4.7 KiB
Plaintext
Raw Normal View History

2017-07-11 11:51:53 -04:00
import { acceptance } from "helpers/qunit-helpers";
2018-06-15 11:03:24 -04:00
import { IMAGE_VERSION as v } from "pretty-text/emoji";
import { resetCache } from "discourse/components/emoji-picker";
2017-07-11 11:51:53 -04:00
acceptance("EmojiPicker", {
loggedIn: true,
2018-06-15 11:03:24 -04:00
beforeEach() {
resetCache();
}
2017-07-11 11:51:53 -04:00
});
2017-07-21 07:35:29 -04:00
QUnit.test("emoji picker can be opened/closed", assert => {
2017-07-11 11:51:53 -04:00
visit("/t/internationalization-localization/280");
click("#topic-footer-buttons .btn.create");
click("button.emoji.btn");
andThen(() => {
assert.notEqual(
2018-06-15 11:03:24 -04:00
find(".emoji-picker")
.html()
.trim(),
2017-07-11 11:51:53 -04:00
"",
"it opens the picker"
);
});
click("button.emoji.btn");
andThen(() => {
assert.equal(
2018-06-15 11:03:24 -04:00
find(".emoji-picker")
.html()
.trim(),
2017-07-11 11:51:53 -04:00
"",
"it closes the picker"
2018-06-15 11:03:24 -04:00
);
2017-07-11 11:51:53 -04:00
});
});
2017-07-21 07:35:29 -04:00
QUnit.test("emojis can be hovered to display info", assert => {
2017-07-11 11:51:53 -04:00
visit("/t/internationalization-localization/280");
click("#topic-footer-buttons .btn.create");
click("button.emoji.btn");
andThen(() => {
2018-06-15 11:03:24 -04:00
$(".emoji-picker button[title='grinning']").trigger("mouseover");
2017-07-11 11:51:53 -04:00
andThen(() => {
assert.equal(
2018-06-15 11:03:24 -04:00
find(".emoji-picker .info")
.html()
.trim(),
2017-07-11 11:51:53 -04:00
`<img src=\"/images/emoji/emoji_one/grinning.png?v=${v}\" class=\"emoji\"> <span>:grinning:<span></span></span>`,
"it displays emoji info when hovering emoji"
);
});
});
});
QUnit.test("emoji picker triggers event when picking emoji", assert => {
2017-07-11 11:51:53 -04:00
visit("/t/internationalization-localization/280");
click("#topic-footer-buttons .btn.create");
click("button.emoji.btn");
click(".emoji-picker button[title='grinning']");
2017-07-11 11:51:53 -04:00
andThen(() => {
assert.equal(
2018-06-15 11:03:24 -04:00
find(".d-editor-input").val(),
2017-07-11 11:51:53 -04:00
":grinning:",
"it adds the emoji code in the editor when selected"
);
});
});
2017-07-21 07:35:29 -04:00
QUnit.test("emoji picker has a list of recently used emojis", assert => {
2017-07-11 11:51:53 -04:00
visit("/t/internationalization-localization/280");
click("#topic-footer-buttons .btn.create");
click("button.emoji.btn");
2018-06-15 11:03:24 -04:00
click(
".emoji-picker .section[data-section='people'] button.emoji[title='grinning']"
);
2017-07-11 11:51:53 -04:00
andThen(() => {
assert.equal(
find('.emoji-picker .section[data-section="recent"]').css("display"),
2017-07-11 11:51:53 -04:00
"block",
"it shows recent section"
);
assert.equal(
2018-06-15 11:03:24 -04:00
find(
'.emoji-picker .section[data-section="recent"] .section-group button.emoji'
).length,
2017-07-11 11:51:53 -04:00
1,
"it adds the emoji code to the recently used emojis list"
);
});
2017-07-19 07:15:18 -04:00
click(".emoji-picker .clear-recent");
2017-07-11 11:51:53 -04:00
andThen(() => {
assert.equal(
2018-06-15 11:03:24 -04:00
find(
'.emoji-picker .section[data-section="recent"] .section-group button.emoji'
).length,
2017-07-19 07:15:18 -04:00
0,
"it has cleared recent emojis"
2017-07-11 11:51:53 -04:00
);
2017-07-19 07:15:18 -04:00
assert.equal(
find('.emoji-picker .section[data-section="recent"]').css("display"),
2017-07-19 07:15:18 -04:00
"none",
"it hides recent section"
);
2017-07-11 11:51:53 -04:00
2017-07-19 07:15:18 -04:00
assert.equal(
2018-06-15 11:03:24 -04:00
find('.emoji-picker .category-icon button.emoji[data-section="recent"]')
.parent()
.css("display"),
2017-07-19 07:15:18 -04:00
"none",
"it hides recent category icon"
);
2017-07-11 11:51:53 -04:00
});
});
QUnit.test("emoji picker correctly orders recently used emojis", assert => {
2017-07-11 11:51:53 -04:00
visit("/t/internationalization-localization/280");
click("#topic-footer-buttons .btn.create");
click("button.emoji.btn");
2017-07-11 11:51:53 -04:00
andThen(() => {
click(".emoji-picker button[title='sunglasses']");
click(".emoji-picker button[title='grinning']");
andThen(() => {
assert.equal(
2018-06-15 11:03:24 -04:00
find('.section[data-section="recent"] .section-group button.emoji')
.length,
2,
"it has multiple recent emojis"
);
2017-07-11 11:51:53 -04:00
assert.equal(
2018-06-15 11:03:24 -04:00
/grinning/.test(
find('.section[data-section="recent"] .section-group button.emoji')
.first()
.css("background-image")
),
true,
"it puts the last used emoji in first"
);
});
2017-07-11 11:51:53 -04:00
});
});
QUnit.test("emoji picker lazy loads emojis", assert => {
2017-07-11 11:51:53 -04:00
visit("/t/internationalization-localization/280");
click("#topic-footer-buttons .btn.create");
click("button.emoji.btn");
andThen(() => {
assert.equal(
2018-06-15 11:03:24 -04:00
find('.emoji-picker button[title="massage_woman"]').css(
"background-image"
),
"none",
2017-07-11 11:51:53 -04:00
"it doesn't load invisible emojis"
);
});
});
QUnit.test("emoji picker persists state", assert => {
2017-07-11 11:51:53 -04:00
visit("/t/internationalization-localization/280");
click("#topic-footer-buttons .btn.create");
click("button.emoji.btn");
andThen(() => {
2018-06-15 11:03:24 -04:00
click(".emoji-picker a.diversity-scale.medium-dark");
2017-07-11 11:51:53 -04:00
});
click("button.emoji.btn");
click("button.emoji.btn");
andThen(() => {
assert.equal(
2018-06-15 11:03:24 -04:00
find(".emoji-picker .diversity-scale.medium-dark").hasClass("selected"),
2017-07-11 11:51:53 -04:00
true,
"it stores diversity scale"
);
});
});