mirror of
https://github.com/zulip/zulip.git
synced 2026-07-12 21:04:41 +08:00
Test user-sidebar unread counts & fix broken tests
This is hard to break up into separate commits; sorry about that. Before this commit we had 3 tests: 1. Claims to check that an unread count was 3, but actually doesn't. 2. Checks that scrolling down causes the left-sidebar stream unread count to decrease. 3. Claims to check that unread counts are correct, but actually doesn't. From talking to Leo, it seems that he originally tried to actually do what tests 1 and 3 claim to do, but found it too fragile to check an exact unread count because of font sizes, layout, etc. We now have 4 tests. For each of the stream sidebar and user sidebar, we test that: 1. Scrolling down causes the unread count to decrease 2. Logging out and back in again leaves the unread count unchanged I've removed the two bogus tests and some other code that didn't seem to serve a purpose. (imported from commit 9f8e4b521e2765099510426d0b7e2960885e6f19)
This commit is contained in:
parent
d4661b22c8
commit
f0e9786c08
@ -177,6 +177,11 @@ exports.wait_for_receive = function (step) {
|
||||
}, step);
|
||||
};
|
||||
|
||||
// Wait until the loading spinner goes away (helpful just after logging in).
|
||||
exports.wait_for_load = function (step) {
|
||||
casper.waitWhileVisible('.loading_indicator_spinner', step);
|
||||
};
|
||||
|
||||
// innerText sometimes gives us non-breaking space characters, and occasionally
|
||||
// a different number of spaces than we expect.
|
||||
exports.normalize_spaces = function (str) {
|
||||
|
||||
@ -4,23 +4,20 @@ var common = require('../common.js').common;
|
||||
/*global keep_pointer_in_view: true */
|
||||
/*global process_visible_unread_messages: true */
|
||||
|
||||
function send_with_content(content) {
|
||||
common.send_message('stream', {
|
||||
stream: 'Verona',
|
||||
subject: 'unread test',
|
||||
content: content
|
||||
});
|
||||
function get_selector_num(selector_string) {
|
||||
var ret = casper.evaluate(function (selector_string) {
|
||||
return $(selector_string).text();
|
||||
}, {selector_string: selector_string});
|
||||
|
||||
var num = parseInt(ret, 10);
|
||||
if (isNaN(num)) {
|
||||
num = 0;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
// Iago
|
||||
common.start_and_log_in(undefined, {width: 1280, height: 600});
|
||||
casper.then(function () {
|
||||
send_with_content('Iago unread test 0');
|
||||
});
|
||||
common.then_log_out();
|
||||
|
||||
// Othello
|
||||
casper.open("http://localhost:9981/accounts/login");
|
||||
casper.start("http://localhost:9981/accounts/login");
|
||||
common.then_log_in({username: 'othello@zulip.com', password: 'GX5MTQ+qYSzcmDoH'});
|
||||
|
||||
casper.then(function () {
|
||||
@ -31,44 +28,40 @@ casper.then(function () {
|
||||
});
|
||||
|
||||
common.then_log_out();
|
||||
|
||||
// Iago
|
||||
common.then_log_in({username: 'iago@zulip.com', password: 'JhwLkBydEG1tAL5P'});
|
||||
|
||||
send_with_content('Iago unread test 1');
|
||||
send_with_content('Iago unread test 2');
|
||||
send_with_content('Iago unread test 3');
|
||||
send_with_content('Iago unread test 4');
|
||||
send_with_content('Iago unread test 5');
|
||||
send_with_content('Iago unread test 6');
|
||||
send_with_content('Iago unread test 7');
|
||||
send_with_content('Iago unread test 8');
|
||||
send_with_content('Iago unread test 9');
|
||||
send_with_content('Iago unread test 10');
|
||||
send_with_content('Iago unread test 11');
|
||||
send_with_content('Iago unread test 12');
|
||||
send_with_content('Iago unread test 13');
|
||||
common.then_log_out();
|
||||
|
||||
common.then_log_in({username: 'othello@zulip.com', password: 'GX5MTQ+qYSzcmDoH'});
|
||||
casper.then(function () {
|
||||
// Make sure we have 3 unread messages
|
||||
casper.test.assertSelectorHasText("a[href='#narrow/stream/Verona']", 'Verona', 'Unread count in sidebar is correct');
|
||||
casper.test.info('Sending messages (this may take a while...)');
|
||||
});
|
||||
|
||||
// Sending a message should not increase the count
|
||||
send_with_content('Othello unread test 4');
|
||||
send_with_content('Othello unread test 5');
|
||||
// Send interleaved messages to both stream Verona and Othello,
|
||||
// so we can test both stream and PM unread counts.
|
||||
var i;
|
||||
for (i = 1; i <= 13; i++) {
|
||||
common.send_message('stream', {
|
||||
stream: 'Verona',
|
||||
subject: 'unread test',
|
||||
content: 'Iago unread stream message ' + i.toString()
|
||||
});
|
||||
common.send_message('private', {
|
||||
recipient: 'othello@zulip.com',
|
||||
content: 'Iago unread PM ' + i.toString()
|
||||
});
|
||||
}
|
||||
common.then_log_out();
|
||||
|
||||
casper.then(function () {
|
||||
function get_sidebar() { return casper.evaluate(function () { return $("a[href='#narrow/stream/Verona']").text(); }); }
|
||||
function get_sidebar_num() {
|
||||
var match = get_sidebar().match(/\w+\s*\((\d+)\)/);
|
||||
if (match) {
|
||||
return parseInt(match[1], 10);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// Othello
|
||||
common.then_log_in({username: 'othello@zulip.com', password: 'GX5MTQ+qYSzcmDoH'});
|
||||
|
||||
var verona_sidebar_selector = "a[href='#narrow/stream/Verona'] .value";
|
||||
var iago_sidebar_selector = "a[data-email='iago@zulip.com'] .value";
|
||||
|
||||
var last_stream_count;
|
||||
var last_pm_count;
|
||||
|
||||
common.wait_for_load(function () {
|
||||
function send_key(key) { casper.page.sendEvent('keypress', key); casper.wait(50); }
|
||||
|
||||
function scroll_to(ypos) {
|
||||
@ -84,19 +77,36 @@ casper.then(function () {
|
||||
// Due to font size and height variance across platforms, we are restricted from checking specific
|
||||
// unread counts as they might not be consistent. However, we do know that after scrolling
|
||||
// down more messages should be marked as read
|
||||
var sidebar_initial = get_sidebar_num();
|
||||
var first_stream_count = get_selector_num(verona_sidebar_selector);
|
||||
var first_pm_count = get_selector_num(iago_sidebar_selector);
|
||||
for(i = 0; i < 1500; i += 100) {
|
||||
scroll_to(i);
|
||||
}
|
||||
|
||||
var sidebar_end = get_sidebar_num();
|
||||
casper.test.assert(sidebar_end < sidebar_initial, "Unread count in sidebar decreases after scrolling");
|
||||
last_stream_count = get_selector_num(verona_sidebar_selector);
|
||||
last_pm_count = get_selector_num(iago_sidebar_selector);
|
||||
casper.test.assert(last_stream_count < first_stream_count,
|
||||
"Unread count in stream sidebar decreases after scrolling");
|
||||
casper.test.assert(last_pm_count < first_pm_count,
|
||||
"Unread count in user sidebar decreases after scrolling");
|
||||
|
||||
});
|
||||
|
||||
// We need to be idle for a second to send a pointer update,
|
||||
// then wait a little bit more to let the pointer update finish.
|
||||
// Two seconds seems safe.
|
||||
casper.wait(2000);
|
||||
|
||||
common.then_log_out();
|
||||
common.then_log_in({username: 'othello@zulip.com', password: 'GX5MTQ+qYSzcmDoH'});
|
||||
casper.then(function () {
|
||||
casper.test.assertSelectorHasText("a[href='#narrow/stream/Verona']", 'Verona', 'Sidebar unread correct on login');
|
||||
common.wait_for_load(function () {
|
||||
// Make sure logging out and in didn't change the unread count.
|
||||
casper.test.assertEquals(get_selector_num(verona_sidebar_selector),
|
||||
last_stream_count,
|
||||
'Stream sidebar unread correct on login');
|
||||
casper.test.assertEquals(get_selector_num(iago_sidebar_selector),
|
||||
last_pm_count,
|
||||
'User sidebar unread correct on login');
|
||||
});
|
||||
|
||||
// Run the above queued actions.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user