mirror of https://github.com/zulip/zulip.git
Remove race conditions in casper tests.
Chaining together `wait*` functions can create race conditions in the frontend tests. To avoid race condition, we need to insert `then` function between two `wait*` functions.
This commit is contained in:
parent
8fbbb3a471
commit
d171e2c8d9
|
@ -141,24 +141,32 @@ function un_narrow() {
|
|||
|
||||
// Narrow by clicking links.
|
||||
|
||||
casper.then(function () {
|
||||
common.wait_for_receive(function () {
|
||||
casper.test.info('Narrowing by clicking stream');
|
||||
casper.click('*[title="Narrow to stream \\\"Verona\\\""]');
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#zfilt', function () {
|
||||
expect_stream();
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(check_narrow_title('Verona - Zulip Dev - Zulip'));
|
||||
un_narrow();
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#zhome', function () {
|
||||
expect_home();
|
||||
casper.test.info('Narrowing by clicking subject');
|
||||
casper.click('*[title="Narrow to stream \\\"Verona\\\", topic \\\"frontend test\\\""]');
|
||||
});
|
||||
casper.then(check_narrow_title('frontend test - Zulip Dev - Zulip'));
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
check_narrow_title('frontend test - Zulip Dev - Zulip');
|
||||
casper.waitUntilVisible('#zfilt', function () {
|
||||
expect_stream_subject();
|
||||
|
||||
|
@ -166,15 +174,18 @@ casper.waitUntilVisible('#zfilt', function () {
|
|||
casper.test.info('Un-narrowing');
|
||||
casper.click('#search_exit');
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#zhome', function () {
|
||||
expect_home();
|
||||
casper.test.info('Narrowing by clicking personal');
|
||||
casper.click('*[title="Narrow to your private messages with Cordelia Lear, King Hamlet"]');
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(check_narrow_title('private - Zulip Dev - Zulip'));
|
||||
|
||||
casper.then(function () {
|
||||
check_narrow_title('private - Zulip Dev - Zulip');
|
||||
casper.waitUntilVisible('#zfilt', function () {
|
||||
expect_huddle();
|
||||
|
||||
|
@ -182,6 +193,7 @@ casper.waitUntilVisible('#zfilt', function () {
|
|||
casper.test.info('Un-narrowing');
|
||||
casper.click('.brand');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Narrow by typing in search strings or operators.
|
||||
|
@ -195,27 +207,33 @@ function search_and_check(str, item, check, narrow_title) {
|
|||
|
||||
function search_silent_user(str, item) {
|
||||
common.select_item_via_typeahead('#search_query', str, item);
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#silent_user', function () {
|
||||
casper.test.info("Empty feed for silent user visible.");
|
||||
var expected_message = "\n You haven't received any messages sent by this user yet!"+
|
||||
"\n ";
|
||||
this.test.assertEquals(casper.fetchText('#silent_user'), expected_message);
|
||||
});
|
||||
});
|
||||
un_narrow();
|
||||
}
|
||||
|
||||
function search_non_existing_user(str, item) {
|
||||
common.select_item_via_typeahead('#search_query', str, item);
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#non_existing_user', function () {
|
||||
casper.test.info("Empty feed for non existing user visible.");
|
||||
var expected_message = "\n This user does not exist!"+
|
||||
"\n ";
|
||||
this.test.assertEquals(casper.fetchText('#non_existing_user'), expected_message);
|
||||
});
|
||||
});
|
||||
un_narrow();
|
||||
}
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#zhome', expect_home);
|
||||
});
|
||||
|
||||
// Test stream / recipient autocomplete in the search bar
|
||||
search_and_check('Verona', 'Narrow to stream', expect_stream,
|
||||
|
|
|
@ -19,37 +19,48 @@ casper.waitForText("And reply to this message", function () {
|
|||
casper.page.sendEvent('keypress', "c");
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#compose', function () {
|
||||
casper.test.assertVisible('#stream', 'Stream input box visible');
|
||||
common.check_form('#send_message_form', {stream: '', subject: ''}, "Stream empty on new compose");
|
||||
casper.click('body');
|
||||
casper.page.sendEvent('keypress', "C");
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#private_message_recipient', function () {
|
||||
common.check_form('#send_message_form', {recipient: ''}, "Recipient empty on new PM");
|
||||
casper.click('body');
|
||||
casper.page.sendEvent('keypress', 'c');
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#stream', function () {
|
||||
common.check_form('#send_message_form', {stream: '', subject: ''}, "Stream empty on new compose");
|
||||
|
||||
// Check that when you reply to a message it pre-populates the stream and subject fields
|
||||
casper.click('body');
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitWhileVisible('#stream', function () {
|
||||
casper.clickLabel("We reply to this message");
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#stream', function () {
|
||||
common.check_form('#send_message_form', {stream: "Verona", subject: "Reply test"}, "Stream populated after reply by click");
|
||||
// Or recipient field
|
||||
casper.click('body');
|
||||
casper.clickLabel("And reply to this message");
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#private_message_recipient', function () {
|
||||
common.check_form('#send_message_form', {recipient: "cordelia@zulip.com"}, "Recipient populated after PM click");
|
||||
|
||||
|
@ -57,23 +68,30 @@ casper.waitUntilVisible('#private_message_recipient', function () {
|
|||
casper.page.sendEvent('keypress', 'k');
|
||||
casper.page.sendEvent('keypress', 'r');
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#stream', function () {
|
||||
common.check_form('#send_message_form', {stream: "Verona", subject: "Reply test"}, "Stream populated after reply with `r`");
|
||||
|
||||
// Test "closing" the compose box
|
||||
casper.click('body');
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitWhileVisible('#stream', function () {
|
||||
casper.test.assertNotVisible('#stream', 'Close stream compose box');
|
||||
casper.page.sendEvent('keypress', "C");
|
||||
casper.click('body');
|
||||
});
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitWhileVisible('#private-message', function () {
|
||||
casper.test.assertNotVisible('#private-message', 'Close PM compose box');
|
||||
});
|
||||
});
|
||||
|
||||
// Test focus after narrowing to PMs with a user and typing 'c'
|
||||
casper.then(function () {
|
||||
|
@ -82,11 +100,14 @@ casper.then(function () {
|
|||
casper.waitUntilVisible('#tab_list li.private_message', function () {
|
||||
casper.page.sendEvent('keypress', 'c');
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#compose', function () {
|
||||
casper.test.assertEval(function () {
|
||||
return document.activeElement === $('#stream')[0];
|
||||
}, 'Stream box focused after narrowing to PMs with a user and pressing `c`');
|
||||
});
|
||||
});
|
||||
|
||||
// Make sure multiple PM recipients display properly.
|
||||
var recipients = ['cordelia@zulip.com', 'othello@zulip.com'];
|
||||
|
@ -107,6 +128,8 @@ casper.then(function () {
|
|||
casper.waitUntilVisible('#zhome', function () {
|
||||
casper.clickLabel('A huddle to check spaces');
|
||||
});
|
||||
|
||||
casper.then(function () {
|
||||
casper.waitUntilVisible('#compose', function () {
|
||||
// It may be possible to get the textbox contents with CasperJS,
|
||||
// but it's easier to just evaluate jQuery in page context here.
|
||||
|
@ -116,6 +139,7 @@ casper.waitUntilVisible('#compose', function () {
|
|||
casper.test.assertEquals(displayed_recipients, recipients.join(', '),
|
||||
'Recipients are displayed correctly in a huddle reply');
|
||||
});
|
||||
});
|
||||
|
||||
common.then_log_out();
|
||||
|
||||
|
|
Loading…
Reference in New Issue