2019-10-25 09:45:13 +02:00
|
|
|
var common = require('../casper_lib/common.js');
|
2013-03-20 22:38:20 +01:00
|
|
|
|
2020-01-28 21:30:41 +01:00
|
|
|
function stream_checkbox(stream_name) {
|
2020-01-28 21:43:44 +01:00
|
|
|
const stream_id = common.get_stream_id(stream_name);
|
|
|
|
return '#stream-checkboxes [data-stream-id="' + stream_id + '"]';
|
2020-01-28 21:30:41 +01:00
|
|
|
}
|
|
|
|
|
2020-01-28 22:01:49 +01:00
|
|
|
function stream_span(stream_name) {
|
|
|
|
return stream_checkbox(stream_name) + ' input ~ span';
|
|
|
|
}
|
|
|
|
|
2020-01-27 17:40:59 +01:00
|
|
|
function user_checkbox(email) {
|
2020-01-27 17:48:26 +01:00
|
|
|
var user_id = common.get_user_id(email);
|
|
|
|
return '#user-checkboxes [data-user-id="' + user_id + '"]';
|
2020-01-27 17:40:59 +01:00
|
|
|
}
|
|
|
|
|
2020-01-27 19:16:27 +01:00
|
|
|
function user_span(email) {
|
|
|
|
return user_checkbox(email) + ' input ~ span';
|
|
|
|
}
|
|
|
|
|
|
|
|
function is_checked(email) {
|
|
|
|
var sel = user_checkbox(email);
|
|
|
|
return casper.evaluate(function (sel) {
|
|
|
|
return $(sel).find('input')[0].checked;
|
|
|
|
}, {
|
|
|
|
sel: sel,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-03-20 22:38:20 +01:00
|
|
|
common.start_and_log_in();
|
|
|
|
|
2013-07-05 17:43:56 +02:00
|
|
|
casper.then(function () {
|
2016-10-07 19:05:59 +02:00
|
|
|
var menu_selector = '#settings-dropdown';
|
|
|
|
|
2017-03-09 00:20:22 +01:00
|
|
|
casper.test.info('Streams page');
|
2016-10-07 19:05:59 +02:00
|
|
|
|
|
|
|
casper.waitUntilVisible(menu_selector, function () {
|
|
|
|
casper.click(menu_selector);
|
|
|
|
casper.then(function () {
|
2017-03-09 00:20:22 +01:00
|
|
|
casper.click('a[href^="#streams"]');
|
2016-10-07 19:05:59 +02:00
|
|
|
casper.test.assertUrlMatch(
|
2017-03-09 00:20:22 +01:00
|
|
|
/^http:\/\/[^/]+\/#streams/,
|
|
|
|
'URL suggests we are on streams page');
|
2016-11-01 22:32:10 +01:00
|
|
|
casper.waitUntilVisible('#subscription_overlay.new-style', function () {
|
2017-03-09 00:20:22 +01:00
|
|
|
casper.test.assertExists('#subscription_overlay.new-style', 'Streams page is active');
|
2016-11-01 22:32:10 +01:00
|
|
|
});
|
2016-10-07 19:05:59 +02:00
|
|
|
});
|
|
|
|
});
|
2013-03-20 22:38:20 +01:00
|
|
|
});
|
2016-10-07 19:05:59 +02:00
|
|
|
|
2017-02-10 07:57:28 +01:00
|
|
|
casper.waitUntilVisible('.sub_unsub_button.checked', function () {
|
2016-10-29 01:58:22 +02:00
|
|
|
casper.test.assertExists('.sub_unsub_button.checked', 'Initial subscriptions loaded');
|
2017-09-29 19:20:44 +02:00
|
|
|
casper.click('#add_new_subscription .create_stream_button');
|
2016-07-07 00:58:11 +02:00
|
|
|
});
|
2016-11-01 22:32:10 +01:00
|
|
|
|
2016-07-07 00:58:11 +02:00
|
|
|
casper.then(function () {
|
2020-01-27 17:40:59 +01:00
|
|
|
casper.test.assertExists(user_checkbox('cordelia@zulip.com'), 'Original user list contains Cordelia');
|
|
|
|
casper.test.assertExists(user_checkbox('othello@zulip.com'), 'Original user list contains Othello');
|
2016-07-07 00:58:11 +02:00
|
|
|
});
|
2016-12-17 19:28:51 +01:00
|
|
|
|
2017-02-10 07:57:28 +01:00
|
|
|
casper.waitUntilVisible("#copy-from-stream-expand-collapse", function () {
|
2016-12-17 19:28:51 +01:00
|
|
|
casper.click('#copy-from-stream-expand-collapse');
|
|
|
|
});
|
|
|
|
|
|
|
|
casper.waitUntilVisible("#stream-checkboxes", function () {
|
2020-01-28 21:30:41 +01:00
|
|
|
casper.test.assertExists(stream_checkbox('Scotland'), 'Original stream list contains Scotland');
|
|
|
|
casper.test.assertExists(stream_checkbox('Rome'), 'Original stream list contains Rome');
|
2016-12-17 19:28:51 +01:00
|
|
|
});
|
|
|
|
|
2017-02-10 07:57:28 +01:00
|
|
|
casper.waitUntilVisible("form#stream_creation_form", function () {
|
2016-12-17 19:28:51 +01:00
|
|
|
casper.test.info("Filtering with keyword 'ot'");
|
|
|
|
casper.fill('form#stream_creation_form', {user_list_filter: 'ot'});
|
2016-07-07 00:58:11 +02:00
|
|
|
});
|
2017-02-10 07:57:28 +01:00
|
|
|
casper.waitUntilVisible("#user-checkboxes", function () {
|
2020-01-27 17:40:59 +01:00
|
|
|
casper.test.assertEquals(casper.visible(user_checkbox('cordelia@zulip.com')),
|
2016-12-17 19:28:51 +01:00
|
|
|
false,
|
2017-01-11 23:47:14 +01:00
|
|
|
"Cordelia is not visible");
|
2020-01-27 17:40:59 +01:00
|
|
|
casper.test.assertEquals(casper.visible(user_checkbox('othello@zulip.com')),
|
2016-07-07 00:58:11 +02:00
|
|
|
true,
|
2017-01-11 23:47:14 +01:00
|
|
|
"Othello is visible");
|
2017-01-26 16:06:21 +01:00
|
|
|
|
|
|
|
/* The filter should not impact streams */
|
2020-01-28 21:30:41 +01:00
|
|
|
casper.test.assertEquals(casper.visible(stream_checkbox('Scotland')),
|
2016-12-17 19:28:51 +01:00
|
|
|
true,
|
2017-01-11 23:47:14 +01:00
|
|
|
"Scotland is visible");
|
2020-01-28 21:30:41 +01:00
|
|
|
casper.test.assertEquals(casper.visible(stream_checkbox('Rome')),
|
2017-01-26 16:06:21 +01:00
|
|
|
true,
|
|
|
|
"Rome is visible");
|
2016-07-07 00:58:11 +02:00
|
|
|
});
|
2017-01-12 21:41:14 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info("Check Uncheck only visible users for new stream");
|
|
|
|
casper.click('.subs_set_all_users');
|
|
|
|
casper.wait(100, function () {
|
2020-01-27 19:16:27 +01:00
|
|
|
casper.test.assert(
|
|
|
|
!is_checked('cordelia@zulip.com'),
|
|
|
|
"Cordelia is unchecked");
|
|
|
|
casper.test.assert(
|
|
|
|
is_checked('othello@zulip.com'),
|
|
|
|
"Othello is checked");
|
2017-01-12 21:41:14 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info("Check Uncheck only visible users for new stream");
|
|
|
|
casper.click('.subs_unset_all_users');
|
|
|
|
casper.wait(100, function () {
|
2020-01-27 19:16:27 +01:00
|
|
|
casper.test.assert(
|
|
|
|
!is_checked('othello@zulip.com'),
|
|
|
|
"Othello is unchecked");
|
2017-01-12 21:41:14 +01:00
|
|
|
});
|
|
|
|
});
|
2016-07-07 00:58:11 +02:00
|
|
|
casper.then(function () {
|
|
|
|
casper.test.info("Clearing user filter search box");
|
|
|
|
casper.fill('form#stream_creation_form', {user_list_filter: ''});
|
|
|
|
});
|
|
|
|
casper.then(function () {
|
2020-01-27 17:40:59 +01:00
|
|
|
casper.test.assertEquals(casper.visible(user_checkbox('cordelia@zulip.com')),
|
2016-07-07 00:58:11 +02:00
|
|
|
true,
|
2017-01-11 23:47:14 +01:00
|
|
|
"Cordelia is visible again");
|
2020-01-27 17:40:59 +01:00
|
|
|
casper.test.assertEquals(casper.visible(user_checkbox('othello@zulip.com')),
|
2016-12-17 19:28:51 +01:00
|
|
|
true,
|
2017-01-11 23:47:14 +01:00
|
|
|
"Othello is visible again");
|
2020-01-28 21:30:41 +01:00
|
|
|
casper.test.assertEquals(casper.visible(stream_checkbox('Scotland')),
|
2016-07-07 00:58:11 +02:00
|
|
|
true,
|
2017-01-11 23:47:14 +01:00
|
|
|
"Scotland is visible again");
|
2020-01-28 21:30:41 +01:00
|
|
|
casper.test.assertEquals(casper.visible(stream_checkbox('Rome')),
|
2016-12-17 19:28:51 +01:00
|
|
|
true,
|
2017-01-11 23:47:14 +01:00
|
|
|
"Rome is visible again");
|
2016-07-07 00:58:11 +02:00
|
|
|
});
|
2017-03-21 07:21:38 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitUntilVisible('#stream_creation_form', function () {
|
|
|
|
casper.test.assertTextExists('Create stream', 'New stream creation panel');
|
|
|
|
casper.fill('form#stream_creation_form', {stream_name: 'Waseemio', stream_description: 'Oimeesaw'});
|
2020-01-28 22:01:49 +01:00
|
|
|
casper.click(stream_span('Scotland'));
|
2020-01-27 19:16:27 +01:00
|
|
|
casper.click(user_span('cordelia@zulip.com'));
|
|
|
|
casper.click(user_span('othello@zulip.com'));
|
2017-09-29 19:20:44 +02:00
|
|
|
casper.click('form#stream_creation_form button.button.sea-green');
|
2017-03-21 07:21:38 +01:00
|
|
|
});
|
2016-11-01 22:32:10 +01:00
|
|
|
});
|
|
|
|
|
2017-03-21 07:21:38 +01:00
|
|
|
casper.then(function () {
|
|
|
|
casper.waitFor(function () {
|
|
|
|
return casper.evaluate(function () {
|
|
|
|
return $('.stream-name').is(':contains("Waseemio")');
|
|
|
|
});
|
2013-03-20 22:38:20 +01:00
|
|
|
});
|
|
|
|
});
|
2017-03-21 07:21:38 +01:00
|
|
|
|
2013-07-05 17:43:56 +02:00
|
|
|
casper.then(function () {
|
2016-10-12 09:45:25 +02:00
|
|
|
casper.test.info("User should be subscribed to stream Waseemio");
|
2016-10-28 23:27:02 +02:00
|
|
|
casper.test.assertSelectorHasText('.stream-name', 'Waseemio');
|
2016-11-27 15:31:53 +01:00
|
|
|
casper.test.assertSelectorHasText('.description', 'Oimeesaw');
|
2016-12-17 19:28:51 +01:00
|
|
|
// Based on the selected checkboxes while creating stream,
|
|
|
|
// 4 users from Scotland are added.
|
2020-05-27 05:31:36 +02:00
|
|
|
// 1 user, Cordelia, is added. Othello (subscribed to Scotland) is removed.
|
|
|
|
// FIXME: This assertion may pick up the count from a random other stream.
|
|
|
|
casper.test.assertSelectorHasText('.subscriber-count-text', '4');
|
2016-10-12 08:53:57 +02:00
|
|
|
casper.fill('form#stream_creation_form', {stream_name: ' '});
|
2017-09-29 19:20:44 +02:00
|
|
|
casper.click('form#stream_creation_form button.button.sea-green');
|
2016-10-12 08:53:57 +02:00
|
|
|
});
|
2017-06-07 09:33:25 +02:00
|
|
|
casper.then(function () {
|
2020-03-31 14:39:19 +02:00
|
|
|
common.wait_for_text('#stream_name_error', 'A stream needs to have a name', function () {
|
2017-06-07 09:33:25 +02:00
|
|
|
casper.test.assertTextExists('A stream needs to have a name', "Can't create a stream with an empty name");
|
2017-09-29 19:20:44 +02:00
|
|
|
casper.click('form#stream_creation_form button.button.white');
|
2017-06-07 09:33:25 +02:00
|
|
|
casper.fill('form#stream_creation_form', {stream_name: 'Waseemio'});
|
2017-09-29 19:20:44 +02:00
|
|
|
casper.click('form#stream_creation_form button.button.sea-green');
|
2017-06-07 09:33:25 +02:00
|
|
|
});
|
2016-10-12 08:53:57 +02:00
|
|
|
});
|
2017-06-07 09:33:25 +02:00
|
|
|
casper.then(function () {
|
2020-03-31 14:39:19 +02:00
|
|
|
common.wait_for_text('#stream_name_error', 'A stream with this name already exists', function () {
|
2017-06-07 09:33:25 +02:00
|
|
|
casper.test.assertTextExists('A stream with this name already exists', "Can't create a stream with a duplicate name");
|
|
|
|
casper.test.info('Streams should be filtered when typing in the create box');
|
2017-09-29 19:20:44 +02:00
|
|
|
casper.click('form#stream_creation_form button.button.white');
|
2017-06-07 09:33:25 +02:00
|
|
|
});
|
2016-10-12 08:53:57 +02:00
|
|
|
});
|
2017-06-07 09:33:25 +02:00
|
|
|
casper.then(function () {
|
2020-03-31 14:39:19 +02:00
|
|
|
common.wait_for_text('#search_stream_name', '', function () {
|
2017-06-07 09:33:25 +02:00
|
|
|
casper.test.assertSelectorHasText('.stream-row[data-stream-name="Verona"] .stream-name', 'Verona', 'Verona stream exists before filtering');
|
|
|
|
casper.test.assertSelectorDoesntHaveText('.stream-row.notdisplayed .stream-name', 'Verona', 'Verona stream shown before filtering');
|
|
|
|
});
|
2016-10-12 08:53:57 +02:00
|
|
|
});
|
|
|
|
casper.then(function () {
|
|
|
|
casper.evaluate(function () {
|
2020-03-21 19:12:23 +01:00
|
|
|
$('#stream_filter input[type="text"]')
|
|
|
|
.expectOne()
|
|
|
|
.val('waseem')
|
2018-05-07 01:42:17 +02:00
|
|
|
.trigger($.Event('input'));
|
2016-10-12 08:53:57 +02:00
|
|
|
});
|
|
|
|
});
|
2020-03-21 19:12:23 +01:00
|
|
|
casper.waitForSelectorTextChange('.streams-list', function () {
|
2016-10-28 23:27:02 +02:00
|
|
|
casper.test.assertSelectorHasText('.stream-row .stream-name', 'Waseemio', 'Waseemio stream exists after filtering');
|
2020-03-21 19:12:23 +01:00
|
|
|
casper.test.assertSelectorHasText('.stream-row.notdisplayed .stream-name', 'Verona', 'Verona stream not shown after filtering');
|
2016-10-28 23:27:02 +02:00
|
|
|
casper.test.assertSelectorDoesntHaveText('.stream-row.notdisplayed .stream-name', 'Waseemio', 'Waseemio stream shown after filtering');
|
2013-03-20 22:38:20 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
common.then_log_out();
|
|
|
|
|
|
|
|
casper.run(function () {
|
|
|
|
casper.test.done();
|
|
|
|
});
|