tests: refactor some frontend tests (#4408)

* don't include sendkeys in index.html as it's included in helper.init
mocha opts: add default timeout and replace ignoreLeaks with checkLeaks,
as the former is deprecated

* introduce helper.edit to write to a pad

* add test to check if helper.edit() supports line numbers

* helper tests: waitFor/waitForPromise seem to be a little bit faster sometimes

* tests: refactor chat.js

* tests: refactor timeslider_numeric_padID

* tests: refactor timeslider_labels

* tests: refactor timeslider_follow

* ensure followContents is enabled, although it should be by default

* timeslider_follow: increase number of revision for Edge

* make textLines() depend on linesDiv()

Co-authored-by: Richard Hansen <rhansen@rhansen.org>

* make linesDiv return standard Array

* use `contain` instead of `indexOf`

* more fixes from the review

* review fixes

* align waitFor and waitForPromise behaviour

* timeslider_follow: check if it's following to the correct lines

* lower expected waitFor/waitForPromise interval check

* disable responsivness and regression test in timeslider_follow

* timeslider_follow: fix Range detection

* more explicit test for linesDiv

Co-authored-by: Richard Hansen <rhansen@rhansen.org>
This commit is contained in:
webzwo0i 2020-10-21 19:43:17 +02:00 committed by GitHub
parent 94cb000e8f
commit 69c7033a86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 685 additions and 252 deletions

View file

@ -2,134 +2,78 @@ describe("Chat messages and UI", function(){
//create a new pad before each test run
beforeEach(function(cb){
helper.newPad(cb);
this.timeout(60000);
});
it("opens chat, sends a message and makes sure it exists on the page", function(done) {
var inner$ = helper.padInner$;
var chrome$ = helper.padChrome$;
it("opens chat, sends a message, makes sure it exists on the page and hides chat", async function() {
var chatValue = "JohnMcLear";
//click on the chat button to make chat visible
var $chatButton = chrome$("#chaticon");
$chatButton.click();
var $chatInput = chrome$("#chatinput");
$chatInput.sendkeys('JohnMcLear'); // simulate a keypress of typing JohnMcLear
$chatInput.sendkeys('{enter}'); // simulate a keypress of enter actually does evt.which = 10 not 13
await helper.showChat();
await helper.sendChatMessage(`${chatValue}{enter}`);
//check if chat shows up
helper.waitFor(function(){
return chrome$("#chattext").children("p").length !== 0; // wait until the chat message shows up
}).done(function(){
var $firstChatMessage = chrome$("#chattext").children("p");
var containsMessage = $firstChatMessage.text().indexOf("JohnMcLear") !== -1; // does the string contain JohnMcLear?
expect(containsMessage).to.be(true); // expect the first chat message to contain JohnMcLear
expect(helper.chatTextParagraphs().length).to.be(1);
// do a slightly more thorough check
var username = $firstChatMessage.children("b");
var usernameValue = username.text();
var time = $firstChatMessage.children(".time");
var timeValue = time.text();
var discoveredValue = $firstChatMessage.text();
var chatMsgExists = (discoveredValue.indexOf("JohnMcLear") !== -1);
expect(chatMsgExists).to.be(true);
done();
});
// <p data-authorid="a.qjkwNs4z0pPROphS"
// class="author-a-qjkwz78zs4z122z0pz80zz82zz79zphz83z">
// <b>unnamed:</b>
// <span class="time author-a-qjkwz78zs4z122z0pz80zz82zz79zphz83z">12:38
// </span> JohnMcLear
// </p>
let username = helper.chatTextParagraphs().children("b").text();
let time = helper.chatTextParagraphs().children(".time").text();
expect(helper.chatTextParagraphs().text()).to.be(`${username}${time} ${chatValue}`);
await helper.hideChat();
});
it("makes sure that an empty message can't be sent", function(done) {
var inner$ = helper.padInner$;
var chrome$ = helper.padChrome$;
it("makes sure that an empty message can't be sent", async function() {
var chatValue = "mluto";
//click on the chat button to make chat visible
var $chatButton = chrome$("#chaticon");
$chatButton.click();
var $chatInput = chrome$("#chatinput");
$chatInput.sendkeys('{enter}'); // simulate a keypress of enter (to send an empty message)
$chatInput.sendkeys('mluto'); // simulate a keypress of typing mluto
$chatInput.sendkeys('{enter}'); // simulate a keypress of enter (to send 'mluto')
await helper.showChat();
//check if chat shows up
helper.waitFor(function(){
return chrome$("#chattext").children("p").length !== 0; // wait until the chat message shows up
}).done(function(){
// check that the empty message is not there
expect(chrome$("#chattext").children("p").length).to.be(1);
// check that the received message is not the empty one
var $firstChatMessage = chrome$("#chattext").children("p");
var containsMessage = $firstChatMessage.text().indexOf("mluto") !== -1;
expect(containsMessage).to.be(true);
done();
});
await helper.sendChatMessage(`{enter}${chatValue}{enter}`); // simulate a keypress of typing enter, mluto and enter (to send 'mluto')
let chat = helper.chatTextParagraphs();
expect(chat.length).to.be(1);
// check that the received message is not the empty one
let username = chat.children("b").text();
let time = chat.children(".time").text();
expect(chat.text()).to.be(`${username}${time} ${chatValue}`);
});
it("makes chat stick to right side of the screen", function(done) {
var inner$ = helper.padInner$;
var chrome$ = helper.padChrome$;
it("makes chat stick to right side of the screen via settings, remove sticky via settings, close it", async function() {
await helper.showSettings();
//click on the settings button to make settings visible
var $settingsButton = chrome$(".buttonicon-settings");
$settingsButton.click();
//get the chat selector
var $stickychatCheckbox = chrome$("#options-stickychat");
//select chat always on screen
if (!$stickychatCheckbox.is(':checked')) {
$stickychatCheckbox.click();
}
// due to animation, we need to make some timeout...
setTimeout(function() {
//check if chat changed to get the stickychat Class
var $chatbox = chrome$("#chatbox");
var hasStickyChatClass = $chatbox.hasClass("stickyChat");
expect(hasStickyChatClass).to.be(true);
// select chat always on screen and fire change event
$stickychatCheckbox.click();
setTimeout(function() {
//check if chat changed to remove the stickychat Class
var hasStickyChatClass = $chatbox.hasClass("stickyChat");
expect(hasStickyChatClass).to.be(false);
done();
}, 10)
}, 10)
await helper.enableStickyChatviaSettings();
expect(helper.isChatboxShown()).to.be(true);
expect(helper.isChatboxSticky()).to.be(true);
await helper.disableStickyChatviaSettings();
expect(helper.isChatboxSticky()).to.be(false);
expect(helper.isChatboxShown()).to.be(true);
await helper.hideChat();
expect(helper.isChatboxSticky()).to.be(false);
expect(helper.isChatboxShown()).to.be(false);
});
it("makes chat stick to right side of the screen then makes it one step smaller", function(done) {
var inner$ = helper.padInner$;
var chrome$ = helper.padChrome$;
it("makes chat stick to right side of the screen via icon on the top right, remove sticky via icon, close it", async function() {
await helper.showChat();
// open chat
chrome$('#chaticon').click();
await helper.enableStickyChatviaIcon();
expect(helper.isChatboxShown()).to.be(true);
expect(helper.isChatboxSticky()).to.be(true);
// select chat always on screen from chatbox
chrome$('.stick-to-screen-btn').click();
await helper.disableStickyChatviaIcon();
expect(helper.isChatboxShown()).to.be(true);
expect(helper.isChatboxSticky()).to.be(false);
// due to animation, we need to make some timeout...
setTimeout(function() {
//check if chat changed to get the stickychat Class
var $chatbox = chrome$("#chatbox");
var hasStickyChatClass = $chatbox.hasClass("stickyChat");
expect(hasStickyChatClass).to.be(true);
// select chat always on screen and fire change event
chrome$('#titlecross').click();
setTimeout(function() {
//check if chat changed to remove the stickychat Class
var hasStickyChatClass = $chatbox.hasClass("stickyChat");
expect(hasStickyChatClass).to.be(false);
done();
}, 10)
}, 10)
await helper.hideChat();
expect(helper.isChatboxSticky()).to.be(false);
expect(helper.isChatboxShown()).to.be(false);
});
xit("Checks showChat=false URL Parameter hides chat then when removed it shows chat", function(done) {