2020-07-15 01:29:15 +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) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return stream_checkbox(stream_name) + " input ~ span";
|
2020-01-28 22:01:49 +01:00
|
|
|
}
|
|
|
|
|
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) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return user_checkbox(email) + " input ~ span";
|
2020-01-27 19:16:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function is_checked(email) {
|
|
|
|
var sel = user_checkbox(email);
|
2020-07-15 00:34:28 +02:00
|
|
|
return casper.evaluate(
|
|
|
|
function (sel) {
|
|
|
|
return $(sel).find("input")[0].checked;
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sel: sel,
|
|
|
|
}
|
|
|
|
);
|
2020-01-27 19:16:27 +01:00
|
|
|
}
|
|
|
|
|
2013-03-20 22:38:20 +01:00
|
|
|
common.start_and_log_in();
|
|
|
|
|
2013-07-05 17:43:56 +02:00
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
var menu_selector = "#settings-dropdown";
|
2016-10-07 19:05:59 +02:00
|
|
|
|
2020-07-15 01:29:15 +02: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/,
|
2020-07-15 00:34:28 +02:00
|
|
|
"URL suggests we are on streams page"
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitUntilVisible("#subscription_overlay.new-style", function () {
|
2020-07-15 00:34:28 +02: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
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitUntilVisible(".sub_unsub_button.checked", function () {
|
|
|
|
casper.test.assertExists(".sub_unsub_button.checked", "Initial subscriptions loaded");
|
|
|
|
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-07-15 00:34:28 +02: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 () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.click("#copy-from-stream-expand-collapse");
|
2016-12-17 19:28:51 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
casper.waitUntilVisible("#stream-checkboxes", function () {
|
2020-07-15 01:29:15 +02: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'");
|
2020-07-15 01:29:15 +02:00
|
|
|
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-07-15 00:34:28 +02:00
|
|
|
casper.test.assertEquals(
|
|
|
|
casper.visible(user_checkbox("cordelia@zulip.com")),
|
|
|
|
false,
|
|
|
|
"Cordelia is not visible"
|
|
|
|
);
|
|
|
|
casper.test.assertEquals(
|
|
|
|
casper.visible(user_checkbox("othello@zulip.com")),
|
|
|
|
true,
|
|
|
|
"Othello is visible"
|
|
|
|
);
|
2017-01-26 16:06:21 +01:00
|
|
|
|
|
|
|
/* The filter should not impact streams */
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertEquals(
|
|
|
|
casper.visible(stream_checkbox("Scotland")),
|
|
|
|
true,
|
|
|
|
"Scotland is visible"
|
|
|
|
);
|
|
|
|
casper.test.assertEquals(casper.visible(stream_checkbox("Rome")), 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");
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.click(".subs_set_all_users");
|
2017-01-12 21:41:14 +01:00
|
|
|
casper.wait(100, function () {
|
2020-07-15 00:34:28 +02: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");
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.click(".subs_unset_all_users");
|
2017-01-12 21:41:14 +01:00
|
|
|
casper.wait(100, function () {
|
2020-07-15 00:34:28 +02: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");
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.fill("form#stream_creation_form", {user_list_filter: ""});
|
2016-07-07 00:58:11 +02:00
|
|
|
});
|
|
|
|
casper.then(function () {
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertEquals(
|
|
|
|
casper.visible(user_checkbox("cordelia@zulip.com")),
|
|
|
|
true,
|
|
|
|
"Cordelia is visible again"
|
|
|
|
);
|
|
|
|
casper.test.assertEquals(
|
|
|
|
casper.visible(user_checkbox("othello@zulip.com")),
|
|
|
|
true,
|
|
|
|
"Othello is visible again"
|
|
|
|
);
|
|
|
|
casper.test.assertEquals(
|
|
|
|
casper.visible(stream_checkbox("Scotland")),
|
|
|
|
true,
|
|
|
|
"Scotland is visible again"
|
|
|
|
);
|
|
|
|
casper.test.assertEquals(
|
|
|
|
casper.visible(stream_checkbox("Rome")),
|
|
|
|
true,
|
|
|
|
"Rome is visible again"
|
|
|
|
);
|
2016-07-07 00:58:11 +02:00
|
|
|
});
|
2017-03-21 07:21:38 +01:00
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitUntilVisible("#stream_creation_form", function () {
|
|
|
|
casper.test.assertTextExists("Create stream", "New stream creation panel");
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.fill("form#stream_creation_form", {
|
|
|
|
stream_name: "Waseemio",
|
|
|
|
stream_description: "Oimeesaw",
|
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.click(stream_span("Scotland"));
|
|
|
|
casper.click(user_span("cordelia@zulip.com"));
|
|
|
|
casper.click(user_span("othello@zulip.com"));
|
|
|
|
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 () {
|
2020-07-15 01:29:15 +02:00
|
|
|
return $(".stream-name").is(':contains("Waseemio")');
|
2017-03-21 07:21:38 +01:00
|
|
|
});
|
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");
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertSelectorHasText(".stream-name", "Waseemio");
|
|
|
|
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.
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.test.assertSelectorHasText(".subscriber-count-text", "4");
|
|
|
|
casper.fill("form#stream_creation_form", {stream_name: " "});
|
|
|
|
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-07-15 01:29:15 +02:00
|
|
|
common.wait_for_text("#stream_name_error", "A stream needs to have a name", function () {
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertTextExists(
|
|
|
|
"A stream needs to have a name",
|
|
|
|
"Can't create a stream with an empty name"
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.click("form#stream_creation_form button.button.white");
|
|
|
|
casper.fill("form#stream_creation_form", {stream_name: "Waseemio"});
|
|
|
|
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-07-15 00:34:28 +02:00
|
|
|
common.wait_for_text(
|
|
|
|
"#stream_name_error",
|
|
|
|
"A stream with this name already exists",
|
|
|
|
function () {
|
|
|
|
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");
|
|
|
|
casper.click("form#stream_creation_form button.button.white");
|
|
|
|
}
|
|
|
|
);
|
2016-10-12 08:53:57 +02:00
|
|
|
});
|
2017-06-07 09:33:25 +02:00
|
|
|
casper.then(function () {
|
2020-07-15 01:29:15 +02:00
|
|
|
common.wait_for_text("#search_stream_name", "", function () {
|
2020-07-15 00:34:28 +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"
|
|
|
|
);
|
2017-06-07 09:33:25 +02:00
|
|
|
});
|
2016-10-12 08:53:57 +02:00
|
|
|
});
|
|
|
|
casper.then(function () {
|
|
|
|
casper.evaluate(function () {
|
2020-07-15 00:34:28 +02:00
|
|
|
$('#stream_filter input[type="text"]').expectOne().val("waseem").trigger($.Event("input"));
|
2016-10-12 08:53:57 +02:00
|
|
|
});
|
|
|
|
});
|
2020-07-15 01:29:15 +02:00
|
|
|
casper.waitForSelectorTextChange(".streams-list", function () {
|
2020-07-15 00:34:28 +02:00
|
|
|
casper.test.assertSelectorHasText(
|
|
|
|
".stream-row .stream-name",
|
|
|
|
"Waseemio",
|
|
|
|
"Waseemio stream exists after filtering"
|
|
|
|
);
|
|
|
|
casper.test.assertSelectorHasText(
|
|
|
|
".stream-row.notdisplayed .stream-name",
|
|
|
|
"Verona",
|
|
|
|
"Verona stream not shown after filtering"
|
|
|
|
);
|
|
|
|
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();
|
|
|
|
});
|