2013-03-21 18:18:28 +01:00
|
|
|
var common = require('../common.js').common;
|
|
|
|
|
|
|
|
common.start_and_log_in();
|
|
|
|
|
|
|
|
// We could use the messages sent by 01-site.js, but we want to
|
|
|
|
// 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' },
|
|
|
|
|
2013-03-22 01:42:46 +01:00
|
|
|
{ stream: 'Venice', subject: 'frontend test',
|
|
|
|
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() {
|
|
|
|
common.expected_messages('zhome', [
|
2013-07-17 22:53:07 +02:00
|
|
|
'Verona > frontend test',
|
2013-03-22 01:42:46 +01:00
|
|
|
'You and Cordelia Lear, King Hamlet',
|
|
|
|
'You and Cordelia Lear'
|
2013-03-21 19:38:18 +01:00
|
|
|
], [
|
|
|
|
'<p>test message D</p>',
|
2013-03-22 01:42:46 +01:00
|
|
|
'<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() {
|
2013-03-21 18:18:28 +01:00
|
|
|
common.expected_messages('zfilt', [
|
2013-07-17 22:53:07 +02:00
|
|
|
'Verona > frontend test',
|
|
|
|
'Verona > other subject',
|
|
|
|
'Verona > frontend test'
|
2013-03-21 18:18:28 +01:00
|
|
|
], [
|
|
|
|
'<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() {
|
|
|
|
common.expected_messages('zfilt', [
|
2013-07-17 22:53:07 +02:00
|
|
|
'Verona > frontend test'
|
2013-03-21 19:38:18 +01:00
|
|
|
], [
|
|
|
|
'<p>test message A</p>',
|
|
|
|
'<p>test message B</p>',
|
|
|
|
'<p>test message D</p>'
|
|
|
|
]);
|
|
|
|
}
|
2013-03-21 18:18:28 +01:00
|
|
|
|
2013-03-22 01:42:46 +01:00
|
|
|
function expect_subject() {
|
|
|
|
common.expected_messages('zfilt', [
|
2013-07-17 22:53:07 +02:00
|
|
|
'Verona > frontend test',
|
|
|
|
'Venice > frontend test',
|
|
|
|
'Verona > frontend test'
|
2013-03-22 01:42:46 +01:00
|
|
|
], [
|
|
|
|
'<p>test message A</p>',
|
|
|
|
'<p>test message B</p>',
|
|
|
|
'<p>other message</p>',
|
|
|
|
'<p>test message D</p>'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function expect_huddle() {
|
2013-03-21 19:38:18 +01:00
|
|
|
common.expected_messages('zfilt', [
|
2013-03-21 18:18:28 +01:00
|
|
|
'You and Cordelia Lear, King Hamlet'
|
|
|
|
], [
|
2013-03-21 19:38:18 +01:00
|
|
|
'<p>personal A</p>',
|
|
|
|
'<p>personal B</p>',
|
2013-03-21 18:18:28 +01:00
|
|
|
'<p>personal D</p>'
|
|
|
|
]);
|
2013-03-21 19:38:18 +01:00
|
|
|
}
|
|
|
|
|
2013-03-22 01:42:46 +01:00
|
|
|
function expect_1on1() {
|
|
|
|
common.expected_messages('zfilt', [
|
|
|
|
'You and Cordelia Lear'
|
|
|
|
], [
|
|
|
|
'<p>personal C</p>',
|
|
|
|
'<p>personal E</p>'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function expect_all_pm() {
|
|
|
|
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>'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function un_narrow() {
|
2013-03-29 00:03:11 +01:00
|
|
|
casper.then(common.un_narrow);
|
2013-03-22 01:42:46 +01:00
|
|
|
casper.then(expect_home);
|
|
|
|
}
|
|
|
|
|
2013-03-21 19:38:18 +01:00
|
|
|
|
|
|
|
// Narrow by clicking links.
|
|
|
|
|
|
|
|
common.wait_for_receive(function () {
|
2013-03-22 01:42:46 +01:00
|
|
|
casper.test.info('Narrowing by clicking stream');
|
2013-03-21 19:38:18 +01:00
|
|
|
casper.click('*[title="Narrow to stream \\\"Verona\\\""]');
|
|
|
|
});
|
|
|
|
|
2013-07-29 18:26:55 +02:00
|
|
|
casper.waitUntilVisible('#zfilt', function () {
|
2013-03-21 19:38:18 +01:00
|
|
|
expect_stream();
|
|
|
|
});
|
2013-07-29 20:23:49 +02:00
|
|
|
un_narrow();
|
2013-03-21 18:18:28 +01:00
|
|
|
|
2013-07-29 18:26:55 +02:00
|
|
|
casper.waitUntilVisible('#zhome', function () {
|
2013-03-21 19:38:18 +01:00
|
|
|
expect_home();
|
2013-03-22 01:42:46 +01:00
|
|
|
casper.test.info('Narrowing by clicking subject');
|
2013-07-16 21:00:52 +02:00
|
|
|
casper.click('*[title="Narrow to stream \\\"Verona\\\", topic \\\"frontend test\\\""]');
|
2013-03-21 18:18:28 +01:00
|
|
|
});
|
|
|
|
|
2013-07-29 18:26:55 +02:00
|
|
|
casper.waitUntilVisible('#zfilt', function () {
|
2013-03-21 19:38:18 +01:00
|
|
|
expect_stream_subject();
|
2013-03-22 01:42:46 +01:00
|
|
|
|
|
|
|
// This time, un-narrow by hitting the search 'x'
|
|
|
|
casper.test.info('Un-narrowing');
|
|
|
|
casper.click('#search_exit');
|
2013-03-21 18:18:28 +01:00
|
|
|
});
|
|
|
|
|
2013-07-29 18:26:55 +02:00
|
|
|
casper.waitUntilVisible('#zhome', function () {
|
2013-03-21 19:38:18 +01:00
|
|
|
expect_home();
|
2013-03-22 01:42:46 +01:00
|
|
|
casper.test.info('Narrowing by clicking personal');
|
2013-03-21 18:18:28 +01:00
|
|
|
casper.click('*[title="Narrow to your private messages with Cordelia Lear, King Hamlet"]');
|
|
|
|
});
|
|
|
|
|
2013-03-22 01:42:46 +01:00
|
|
|
|
2013-07-29 18:26:55 +02:00
|
|
|
casper.waitUntilVisible('#zfilt', function () {
|
2013-03-22 01:42:46 +01:00
|
|
|
expect_huddle();
|
|
|
|
|
2013-08-06 21:32:15 +02:00
|
|
|
// Un-narrow by clicking "Zulip"
|
2013-03-22 01:42:46 +01:00
|
|
|
casper.test.info('Un-narrowing');
|
|
|
|
casper.click('.brand');
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Narrow by typing in search strings or operators.
|
|
|
|
|
|
|
|
// Put the specified string into the search box, then
|
|
|
|
// select the menu item matching 'item'.
|
|
|
|
function do_search(str, item) {
|
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info('Searching ' + str + ', ' + item);
|
|
|
|
|
|
|
|
casper.evaluate(function (str, item) {
|
|
|
|
// Set the value and then send a bogus keyup event to trigger
|
|
|
|
// the typeahead.
|
|
|
|
$('#search_query')
|
|
|
|
.focus()
|
|
|
|
.val(str)
|
|
|
|
.trigger($.Event('keyup', { which: 0 }));
|
|
|
|
|
|
|
|
// You might think these steps should be split by casper.then,
|
|
|
|
// but apparently that's enough to make the typeahead close (??),
|
|
|
|
// but not the first time you use do_search.
|
|
|
|
|
|
|
|
// Trigger the typeahead.
|
|
|
|
// Reaching into the guts of Bootstrap Typeahead like this is not
|
|
|
|
// great, but I found it very hard to do it any other way.
|
|
|
|
var tah = $('#search_query').data().typeahead;
|
|
|
|
tah.mouseenter({
|
|
|
|
currentTarget: $('.typeahead:visible li:contains("'+item+'")')[0]
|
|
|
|
});
|
|
|
|
tah.select();
|
|
|
|
}, {str: str, item: item});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function search_and_check(str, item, check) {
|
|
|
|
do_search(str, item);
|
|
|
|
|
|
|
|
casper.then(check);
|
|
|
|
un_narrow();
|
|
|
|
}
|
|
|
|
|
2013-07-29 18:26:55 +02:00
|
|
|
casper.waitUntilVisible('#zhome', expect_home);
|
2013-03-22 01:42:46 +01:00
|
|
|
|
|
|
|
// Test stream / recipient autocomplete in the search bar
|
|
|
|
search_and_check('Verona', 'Narrow to stream', expect_stream);
|
|
|
|
search_and_check('Cordelia', 'Narrow to private', expect_1on1);
|
|
|
|
|
|
|
|
// Test operators
|
|
|
|
search_and_check('stream:verona', 'Narrow', expect_stream);
|
|
|
|
search_and_check('stream:verona subject:frontend+test', 'Narrow', expect_stream_subject);
|
|
|
|
search_and_check('subject:frontend+test', 'Narrow', expect_subject);
|
|
|
|
|
|
|
|
|
|
|
|
// Narrow by clicking the left sidebar.
|
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info('Narrowing with left sidebar');
|
|
|
|
});
|
|
|
|
casper.thenClick('#stream_filters [data-name="Verona"] a', expect_stream);
|
|
|
|
casper.thenClick('#global_filters [data-name="home"] a', expect_home);
|
2013-07-10 03:22:34 +02:00
|
|
|
casper.thenClick('#global_filters [data-name="private"] a', expect_all_pm);
|
2013-03-22 01:42:46 +01:00
|
|
|
un_narrow();
|
2013-03-21 19:38:18 +01:00
|
|
|
|
2013-03-21 18:18:28 +01:00
|
|
|
|
|
|
|
common.then_log_out();
|
|
|
|
|
|
|
|
// Run the above queued actions.
|
|
|
|
casper.run(function () {
|
|
|
|
casper.test.done();
|
|
|
|
});
|