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

166 lines
4.5 KiB
Plaintext
Raw Normal View History

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