2015-10-14 00:21:23 +02:00
|
|
|
var common = require('../casper_lib/common.js').common;
|
2013-03-21 18:18:28 +01:00
|
|
|
|
|
|
|
common.start_and_log_in();
|
|
|
|
|
2016-06-25 01:41:07 +02:00
|
|
|
// We could use the messages sent by 02-site.js, but we want to
|
2013-03-21 18:18:28 +01:00
|
|
|
// make sure each test file can be run individually (which the
|
|
|
|
// 'run' script provides for).
|
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info('Sending messages');
|
|
|
|
});
|
|
|
|
|
2014-03-07 20:59:30 +01:00
|
|
|
common.then_send_many([
|
2013-03-21 18:18:28 +01:00
|
|
|
{ stream: 'Verona', subject: 'frontend test',
|
|
|
|
content: 'test message A' },
|
|
|
|
|
|
|
|
{ stream: 'Verona', subject: 'frontend test',
|
|
|
|
content: 'test message B' },
|
|
|
|
|
|
|
|
{ stream: 'Verona', subject: 'other subject',
|
|
|
|
content: 'test message C' },
|
|
|
|
|
2016-04-13 04:50:20 +02:00
|
|
|
{ stream: 'Denmark', subject: 'frontend test',
|
2013-03-22 01:42:46 +01:00
|
|
|
content: 'other message' },
|
|
|
|
|
2013-07-24 20:41:09 +02:00
|
|
|
{ recipient: 'cordelia@zulip.com, hamlet@zulip.com',
|
2013-03-21 18:18:28 +01:00
|
|
|
content: 'personal A' },
|
|
|
|
|
2013-07-24 20:41:09 +02:00
|
|
|
{ recipient: 'cordelia@zulip.com, hamlet@zulip.com',
|
2013-03-21 18:18:28 +01:00
|
|
|
content: 'personal B' },
|
|
|
|
|
2013-07-24 20:41:09 +02:00
|
|
|
{ recipient: 'cordelia@zulip.com',
|
2013-03-21 18:18:28 +01:00
|
|
|
content: 'personal C' },
|
|
|
|
|
|
|
|
{ stream: 'Verona', subject: 'frontend test',
|
|
|
|
content: 'test message D' },
|
|
|
|
|
2013-07-24 20:41:09 +02:00
|
|
|
{ recipient: 'cordelia@zulip.com, hamlet@zulip.com',
|
2013-03-22 01:42:46 +01:00
|
|
|
content: 'personal D' },
|
|
|
|
|
2013-07-24 20:41:09 +02:00
|
|
|
{ recipient: 'cordelia@zulip.com',
|
2013-03-22 01:42:46 +01:00
|
|
|
content: 'personal E' }
|
2013-03-21 18:18:28 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
2013-03-21 19:38:18 +01:00
|
|
|
// Define the messages we expect to see when narrowed.
|
2013-03-21 18:18:28 +01:00
|
|
|
|
2013-03-21 19:38:18 +01:00
|
|
|
function expect_home() {
|
2016-09-20 12:43:06 +02:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#zhome', function () {
|
|
|
|
common.expected_messages('zhome', [
|
|
|
|
'Verona > frontend test',
|
|
|
|
'You and Cordelia Lear, King Hamlet',
|
|
|
|
'You and Cordelia Lear'
|
|
|
|
], [
|
|
|
|
'<p>test message D</p>',
|
|
|
|
'<p>personal D</p>',
|
|
|
|
'<p>personal E</p>'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2013-03-21 19:38:18 +01:00
|
|
|
}
|
2013-03-21 18:18:28 +01:00
|
|
|
|
2013-03-21 19:38:18 +01:00
|
|
|
function expect_stream() {
|
2016-09-20 12:43:06 +02:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#zfilt', function () {
|
|
|
|
common.expected_messages('zfilt', [
|
|
|
|
'Verona > frontend test',
|
|
|
|
'Verona > other subject',
|
|
|
|
'Verona > frontend test'
|
|
|
|
], [
|
|
|
|
'<p>test message A</p>',
|
|
|
|
'<p>test message B</p>',
|
|
|
|
'<p>test message C</p>',
|
|
|
|
'<p>test message D</p>'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2013-03-21 19:38:18 +01:00
|
|
|
}
|
2013-03-21 18:18:28 +01:00
|
|
|
|
2013-03-21 19:38:18 +01:00
|
|
|
function expect_stream_subject() {
|
2016-09-20 12:43:06 +02:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#zfilt', function () {
|
|
|
|
common.expected_messages('zfilt', [
|
|
|
|
'Verona > frontend test'
|
|
|
|
], [
|
|
|
|
'<p>test message A</p>',
|
|
|
|
'<p>test message B</p>',
|
|
|
|
'<p>test message D</p>'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2013-03-21 19:38:18 +01:00
|
|
|
}
|
2013-03-21 18:18:28 +01:00
|
|
|
|
2013-03-22 01:42:46 +01:00
|
|
|
function expect_subject() {
|
2016-09-20 12:43:06 +02:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#zfilt', function () {
|
|
|
|
common.expected_messages('zfilt', [
|
|
|
|
'Verona > frontend test',
|
|
|
|
'Denmark > frontend test',
|
|
|
|
'Verona > frontend test'
|
|
|
|
], [
|
|
|
|
'<p>test message A</p>',
|
|
|
|
'<p>test message B</p>',
|
|
|
|
'<p>other message</p>',
|
|
|
|
'<p>test message D</p>'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2013-03-22 01:42:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function expect_huddle() {
|
2016-09-20 12:43:06 +02:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#zfilt', function () {
|
|
|
|
common.expected_messages('zfilt', [
|
|
|
|
'You and Cordelia Lear, King Hamlet'
|
|
|
|
], [
|
|
|
|
'<p>personal A</p>',
|
|
|
|
'<p>personal B</p>',
|
|
|
|
'<p>personal D</p>'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2013-03-21 19:38:18 +01:00
|
|
|
}
|
|
|
|
|
2013-03-22 01:42:46 +01:00
|
|
|
function expect_1on1() {
|
2016-09-20 12:43:06 +02:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#zfilt', function () {
|
|
|
|
common.expected_messages('zfilt', [
|
|
|
|
'You and Cordelia Lear'
|
|
|
|
], [
|
|
|
|
'<p>personal C</p>',
|
|
|
|
'<p>personal E</p>'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2013-03-22 01:42:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function expect_all_pm() {
|
2016-09-20 12:43:06 +02:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#zfilt', function () {
|
|
|
|
common.expected_messages('zfilt', [
|
|
|
|
'You and Cordelia Lear, King Hamlet',
|
|
|
|
'You and Cordelia Lear'
|
|
|
|
], [
|
|
|
|
'<p>personal A</p>',
|
|
|
|
'<p>personal B</p>',
|
|
|
|
'<p>personal C</p>',
|
|
|
|
'<p>personal D</p>',
|
|
|
|
'<p>personal E</p>'
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
2013-03-22 01:42:46 +01:00
|
|
|
}
|
|
|
|
|
2015-12-10 20:37:01 +01:00
|
|
|
function check_narrow_title(title) {
|
|
|
|
return function () {
|
|
|
|
// need to get title tag from HTML
|
|
|
|
// test if it's equal to some string passed in to function
|
|
|
|
casper.test.assertSelectorHasText('title', title, 'Got expected narrow title');
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-03-22 01:42:46 +01:00
|
|
|
function un_narrow() {
|
2013-03-29 00:03:11 +01:00
|
|
|
casper.then(common.un_narrow);
|
2016-09-20 12:43:06 +02:00
|
|
|
expect_home();
|
2015-12-10 20:37:01 +01:00
|
|
|
casper.then(check_narrow_title('home - Zulip Dev - Zulip'));
|
2013-03-22 01:42:46 +01:00
|
|
|
}
|
|
|
|
|
2015-12-10 20:37:01 +01:00
|
|
|
function search_and_check(str, item, check, narrow_title) {
|
2016-06-09 09:29:49 +02:00
|
|
|
common.select_item_via_typeahead('#search_query', str, item);
|
2016-09-20 12:43:06 +02:00
|
|
|
check();
|
2015-12-10 20:37:01 +01:00
|
|
|
casper.then(check_narrow_title(narrow_title));
|
2013-03-22 01:42:46 +01:00
|
|
|
un_narrow();
|
|
|
|
}
|
|
|
|
|
2016-07-29 16:15:50 +02:00
|
|
|
function search_silent_user(str, item) {
|
|
|
|
common.select_item_via_typeahead('#search_query', str, item);
|
2016-09-08 14:10:41 +02:00
|
|
|
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);
|
|
|
|
});
|
2016-07-29 16:15:50 +02:00
|
|
|
});
|
|
|
|
un_narrow();
|
|
|
|
}
|
|
|
|
|
|
|
|
function search_non_existing_user(str, item) {
|
|
|
|
common.select_item_via_typeahead('#search_query', str, item);
|
2016-09-08 14:10:41 +02:00
|
|
|
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);
|
|
|
|
});
|
2016-07-29 16:15:50 +02:00
|
|
|
});
|
|
|
|
un_narrow();
|
|
|
|
}
|
|
|
|
|
2016-09-20 12:43:06 +02:00
|
|
|
// Narrow by clicking links.
|
|
|
|
|
2016-09-08 14:10:41 +02:00
|
|
|
casper.then(function () {
|
2016-09-20 12:43:06 +02:00
|
|
|
common.wait_for_receive(function () {
|
|
|
|
casper.test.info('Narrowing by clicking stream');
|
|
|
|
casper.click('*[title="Narrow to stream \\\"Verona\\\""]');
|
|
|
|
});
|
2016-09-08 14:10:41 +02:00
|
|
|
});
|
2013-03-22 01:42:46 +01:00
|
|
|
|
2016-09-20 12:43:06 +02:00
|
|
|
expect_stream();
|
|
|
|
|
|
|
|
casper.then(check_narrow_title('Verona - Zulip Dev - Zulip'));
|
|
|
|
|
|
|
|
un_narrow();
|
|
|
|
|
|
|
|
expect_home();
|
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info('Narrowing by clicking subject');
|
|
|
|
casper.click('*[title="Narrow to stream \\\"Verona\\\", topic \\\"frontend test\\\""]');
|
|
|
|
});
|
|
|
|
|
|
|
|
expect_stream_subject();
|
|
|
|
|
|
|
|
casper.then(check_narrow_title('frontend test - Zulip Dev - Zulip'));
|
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
// This time, un-narrow by hitting the search 'x'
|
|
|
|
casper.test.info('Un-narrowing');
|
|
|
|
casper.click('#search_exit');
|
|
|
|
});
|
|
|
|
|
|
|
|
expect_home();
|
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info('Narrowing by clicking personal');
|
|
|
|
casper.click('*[title="Narrow to your private messages with Cordelia Lear, King Hamlet"]');
|
|
|
|
});
|
|
|
|
|
|
|
|
expect_huddle();
|
|
|
|
|
|
|
|
casper.then(check_narrow_title('private - Zulip Dev - Zulip'));
|
|
|
|
|
|
|
|
casper.then(function () {
|
|
|
|
// Un-narrow by clicking "Zulip"
|
|
|
|
casper.test.info('Un-narrowing');
|
|
|
|
casper.click('.brand');
|
|
|
|
});
|
|
|
|
|
|
|
|
expect_home();
|
|
|
|
|
|
|
|
// Narrow by typing in search strings or operators.
|
2013-03-22 01:42:46 +01:00
|
|
|
// Test stream / recipient autocomplete in the search bar
|
2015-12-10 20:37:01 +01:00
|
|
|
search_and_check('Verona', 'Narrow to stream', expect_stream,
|
|
|
|
'Verona - Zulip Dev - Zulip');
|
2016-09-20 12:43:06 +02:00
|
|
|
|
2015-12-10 20:37:01 +01:00
|
|
|
search_and_check('Cordelia', 'Narrow to private', expect_1on1,
|
2016-09-20 12:43:06 +02:00
|
|
|
'private - Zulip Dev - Zulip');
|
2013-03-22 01:42:46 +01:00
|
|
|
|
|
|
|
// Test operators
|
2015-12-10 20:37:01 +01:00
|
|
|
search_and_check('stream:Verona', 'Narrow', expect_stream,
|
2016-09-20 12:43:06 +02:00
|
|
|
'Verona - Zulip Dev - Zulip');
|
|
|
|
|
2015-12-10 20:37:01 +01:00
|
|
|
search_and_check('stream:Verona subject:frontend+test', 'Narrow', expect_stream_subject,
|
2016-09-20 12:43:06 +02:00
|
|
|
'frontend test - Zulip Dev - Zulip');
|
|
|
|
|
2016-10-16 23:09:45 +02:00
|
|
|
search_and_check('stream:Verona topic:frontend+test', 'Narrow', expect_stream_subject,
|
|
|
|
'frontend test - Zulip Dev - Zulip');
|
|
|
|
|
2015-12-10 20:37:01 +01:00
|
|
|
search_and_check('subject:frontend+test', 'Narrow', expect_subject,
|
2016-09-20 12:43:06 +02:00
|
|
|
'home - Zulip Dev - Zulip');
|
2013-03-22 01:42:46 +01:00
|
|
|
|
2016-07-29 16:15:50 +02:00
|
|
|
search_silent_user('sender:emailgateway@zulip.com', 'Narrow');
|
2016-09-20 12:43:06 +02:00
|
|
|
|
2016-07-29 16:15:50 +02:00
|
|
|
search_non_existing_user('sender:dummyuser@zulip.com', 'Narrow');
|
|
|
|
|
2013-03-22 01:42:46 +01:00
|
|
|
// Narrow by clicking the left sidebar.
|
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info('Narrowing with left sidebar');
|
2016-09-20 12:43:06 +02:00
|
|
|
casper.click('#stream_filters [data-name="Verona"] a');
|
2013-03-22 01:42:46 +01:00
|
|
|
});
|
2016-09-20 12:43:06 +02:00
|
|
|
|
|
|
|
expect_stream();
|
|
|
|
|
2015-12-10 20:37:01 +01:00
|
|
|
casper.then(check_narrow_title('Verona - Zulip Dev - Zulip'));
|
2016-09-20 12:43:06 +02:00
|
|
|
|
|
|
|
casper.thenClick('#global_filters [data-name="home"] a');
|
|
|
|
|
|
|
|
expect_home();
|
|
|
|
|
2015-12-10 20:37:01 +01:00
|
|
|
casper.then(check_narrow_title('home - Zulip Dev - Zulip'));
|
2016-09-20 12:43:06 +02:00
|
|
|
|
|
|
|
casper.thenClick('#global_filters [data-name="private"] a');
|
|
|
|
|
|
|
|
expect_all_pm();
|
|
|
|
|
2015-12-10 20:37:01 +01:00
|
|
|
casper.then(check_narrow_title('private - Zulip Dev - Zulip'));
|
2013-03-21 19:38:18 +01:00
|
|
|
|
2016-09-20 12:43:06 +02:00
|
|
|
un_narrow();
|
2013-03-21 18:18:28 +01:00
|
|
|
|
2016-06-13 22:06:12 +02:00
|
|
|
// Make sure stream search filters the stream list
|
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info('Search streams using left sidebar');
|
|
|
|
casper.test.assertExists('.stream-list-filter.notdisplayed', 'Stream filter box not visible initially');
|
2016-09-20 12:43:06 +02:00
|
|
|
casper.click('#streams_header .sidebar-title');
|
2016-06-13 22:06:12 +02:00
|
|
|
});
|
|
|
|
|
2016-09-20 12:43:06 +02:00
|
|
|
casper.waitWhileSelector('.stream-list-filter.notdisplayed', function () {
|
2016-06-13 22:06:12 +02:00
|
|
|
casper.test.assertExists('#stream_filters [data-name="Denmark"]', 'Original stream list contains Denmark');
|
|
|
|
casper.test.assertExists('#stream_filters [data-name="Scotland"]', 'Original stream list contains Scotland');
|
|
|
|
casper.test.assertExists('#stream_filters [data-name="Verona"]', 'Original stream list contains Verona');
|
|
|
|
});
|
|
|
|
|
|
|
|
// We search for the beginning of "Verona", not case sensitive
|
|
|
|
casper.then(function () {
|
|
|
|
casper.evaluate(function () {
|
|
|
|
$('.stream-list-filter').expectOne()
|
|
|
|
.focus()
|
|
|
|
.val('ver')
|
|
|
|
.trigger($.Event('input'));
|
|
|
|
});
|
|
|
|
});
|
2016-09-20 12:43:06 +02:00
|
|
|
|
|
|
|
// There will be no race condition between these two waits because we
|
|
|
|
// expect them to happen in parallel.
|
|
|
|
casper.waitWhileSelector('#stream_filters [data-name="Denmark"]', function () {
|
2016-06-13 22:06:12 +02:00
|
|
|
casper.test.assertDoesntExist('#stream_filters [data-name="Denmark"]', 'Filtered stream list does not contain Denmark');
|
2016-09-20 12:43:06 +02:00
|
|
|
});
|
|
|
|
casper.waitWhileSelector('#stream_filters [data-name="Scotland"]', function () {
|
2016-06-13 22:06:12 +02:00
|
|
|
casper.test.assertDoesntExist('#stream_filters [data-name="Scotland"]', 'Filtered stream list does not contain Scotland');
|
2016-09-20 12:43:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.then(function () {
|
2016-06-13 22:06:12 +02:00
|
|
|
casper.test.assertExists('#stream_filters [data-name="Verona"]', 'Filtered stream list does contain Verona');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Clearing the list should give us back all the streams in the list
|
|
|
|
casper.then(function () {
|
|
|
|
casper.evaluate(function () {
|
|
|
|
$('.stream-list-filter').expectOne()
|
|
|
|
.focus()
|
|
|
|
.val('')
|
|
|
|
.trigger($.Event('input'));
|
|
|
|
});
|
|
|
|
});
|
2016-09-20 12:43:06 +02:00
|
|
|
|
|
|
|
// There will be no race condition between these waits because we
|
|
|
|
// expect them to happen in parallel.
|
|
|
|
casper.waitForSelector('#stream_filters [data-name="Denmark"]', function () {
|
2016-06-13 22:06:12 +02:00
|
|
|
casper.test.assertExists('#stream_filters [data-name="Denmark"]', 'Restored stream list contains Denmark');
|
2016-09-20 12:43:06 +02:00
|
|
|
});
|
|
|
|
casper.waitForSelector('#stream_filters [data-name="Scotland"]', function () {
|
|
|
|
casper.test.assertExists('#stream_filters [data-name="Denmark"]', 'Restored stream list contains Scotland');
|
|
|
|
});
|
|
|
|
casper.waitForSelector('#stream_filters [data-name="Verona"]', function () {
|
|
|
|
casper.test.assertExists('#stream_filters [data-name="Denmark"]', 'Restored stream list contains Verona');
|
2016-06-13 22:06:12 +02:00
|
|
|
});
|
|
|
|
|
2016-09-20 12:43:06 +02:00
|
|
|
|
2016-06-13 22:06:12 +02:00
|
|
|
casper.thenClick('#streams_header .sidebar-title');
|
|
|
|
|
2016-09-20 12:43:06 +02:00
|
|
|
casper.waitForSelector('.stream-list-filter.notdisplayed', function () {
|
2016-06-13 22:06:12 +02:00
|
|
|
casper.test.assertExists('.stream-list-filter.notdisplayed', 'Stream filter box not visible after second click');
|
|
|
|
});
|
|
|
|
|
|
|
|
un_narrow();
|
|
|
|
|
2013-03-21 18:18:28 +01:00
|
|
|
common.then_log_out();
|
|
|
|
|
|
|
|
// Run the above queued actions.
|
|
|
|
casper.run(function () {
|
|
|
|
casper.test.done();
|
|
|
|
});
|