Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
puppeteer: Migrate narrow test from casper.
Dinesh62c69af6d578
diff --git a/frontend_tests/casper_tests/03-narrow.js b/frontend_tests/casper_tests/03-narrow.jsdeleted file mode 100644index ecf8e464b31..00000000000--- a/frontend_tests/casper_tests/03-narrow.js+++ /dev/null@@ -1,566 +0,0 @@-"use strict";--var common = require("../casper_lib/common.js");--common.start_and_log_in();--function get_stream_li(stream_name) {- var stream_id = common.get_stream_id(stream_name);- return '#stream_filters [data-stream-id="' + stream_id + '"]';-}--// We could use the messages sent by 02-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");-});--common.then_send_many([- {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"},-- {stream: "Denmark", subject: "frontend test", content: "other message"},-- {recipient: "[email protected], [email protected]", content: "personal A"},-- {recipient: "[email protected], [email protected]", content: "personal B"},-- {recipient: "[email protected]", content: "personal C"},-- {stream: "Verona", subject: "frontend test", content: "test message D"},-- {recipient: "[email protected], [email protected]", content: "personal D"},-- {recipient: "[email protected]", content: "personal E"},-]);--// Define the messages we expect to see when narrowed.--function expect_home() {- 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>"]- );- });- });-}--function expect_stream() {- 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>",- ]- );- });- });-}--function expect_stream_subject() {- 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>"]- );-- casper.test.assertEquals(- casper.fetchText("#left_bar_compose_stream_button_big"),- "New topic"- );- });- });-}--function expect_subject() {- 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>",- ]- );- });- });-}--function expect_huddle() {- 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>"]- );- });- });-}--function expect_1on1() {- casper.then(function () {- casper.waitUntilVisible("#zfilt", function () {- common.expected_messages(- "zfilt",- ["You and Cordelia Lear"],- ["<p>personal C</p>", "<p>personal E</p>"]- );- });- });-}--function expect_all_pm() {- 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>",- ]- );-- casper.test.assertEquals(- casper.fetchText("#left_bar_compose_stream_button_big"),- "New stream message"- );- });- });-}--function expect_non_existing_user() {- 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);- });- });-}--function expect_non_existing_users() {- casper.then(function () {- casper.waitUntilVisible("#non_existing_users", function () {- casper.test.info("Empty feed for non existing user visible.");- var expected_message = "\n One or more of these users do not exist!" + "\n ";- this.test.assertEquals(casper.fetchText("#non_existing_users"), expected_message);- });- });-}--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");- };-}--function un_narrow() {- casper.then(common.un_narrow);- expect_home();- casper.then(check_narrow_title("home - Zulip Dev - Zulip"));-}--function search_and_check(str, item, check, narrow_title) {- common.select_item_via_typeahead("#search_query", str, item);- check();- casper.then(check_narrow_title(narrow_title));- un_narrow();-}--function search_silent_user(str, item) {- common.select_item_via_typeahead("#search_query", str, item);- 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);- });- });- un_narrow();-}--function search_non_existing_user(str, item) {- common.select_item_via_typeahead("#search_query", str, item);- expect_non_existing_user();- un_narrow();-}--// Narrow by clicking links.--casper.then(function () {- common.wait_for_receive(function () {- casper.test.info("Narrowing by clicking stream");- casper.click('*[title="Narrow to stream \\"Verona\\""]');- });-});--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 () {- // Un-narrow by clicking "Zulip"- casper.test.info("Un-narrowing");- casper.click(".brand");-});--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("Cordelia Lear, King Hamlet - 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.-// Test stream / recipient autocomplete in the search bar-search_and_check("Verona", "Stream", expect_stream, "Verona - Zulip Dev - Zulip");--search_and_check("Cordelia", "Private", expect_1on1, "Cordelia Lear - Zulip Dev - Zulip");--// Test operators-search_and_check("stream:Verona", "", expect_stream, "Verona - Zulip Dev - Zulip");--search_and_check(- "stream:Verona subject:frontend+test",- "",- expect_stream_subject,- "frontend test - Zulip Dev - Zulip"-);--search_and_check(- "stream:Verona topic:frontend+test",- "",- expect_stream_subject,- "frontend test - Zulip Dev - Zulip"-);--search_and_check("subject:frontend+test", "", expect_subject, "home - Zulip Dev - Zulip");--search_silent_user("sender:[email protected]", "");--search_non_existing_user("sender:[email protected]", "");--search_and_check("pm-with:[email protected]", "", expect_non_existing_user, "Invalid user");--search_and_check(- "pm-with:[email protected],[email protected]",- "",- expect_non_existing_users,- "Invalid users"-);--// Narrow by clicking the left sidebar.-casper.then(function () {- casper.test.info("Narrowing with left sidebar");- casper.click(get_stream_li("Verona") + " a");-});--expect_stream();--casper.then(check_narrow_title("Verona - Zulip Dev - Zulip"));--casper.thenClick(".top_left_all_messages a");--expect_home();--casper.then(check_narrow_title("home - Zulip Dev - Zulip"));--casper.thenClick(".top_left_private_messages a");--expect_all_pm();--casper.then(check_narrow_title("Private messages - Zulip Dev - Zulip"));--un_narrow();--// Make sure stream search filters the stream list-casper.then(function () {- casper.test.info("Search streams using left sidebar");- casper.test.assertExists(- ".input-append.notdisplayed",- "Stream filter box not visible initially"- );- casper.click("#streams_header .sidebar-title");-});--casper.waitWhileSelector("#streams_list .input-append.notdisplayed", function () {- casper.test.assertExists(get_stream_li("Denmark"), "Original stream list contains Denmark");- casper.test.assertExists(get_stream_li("Venice"), "Original stream list contains Venice");- casper.test.assertExists(get_stream_li("Verona"), "Original stream list contains Verona");-});--// Enter the search box and test highlighted suggestion navigation-casper.then(function () {- casper.evaluate(function () {- $(".stream-list-filter").expectOne().trigger("focus").trigger($.Event("click"));- });-});--casper.waitForSelector("#stream_filters .highlighted_stream", function () {- casper.test.info("Suggestion highlighting - initial situation");- casper.test.assertExist(- get_stream_li("Denmark") + ".highlighted_stream",- "Stream Denmark is highlighted"- );- casper.test.assertDoesntExist(- get_stream_li("Venice") + ".highlighted_stream",- "Stream Venice is not highlighted"- );- casper.test.assertDoesntExist(- get_stream_li("Verona") + ".highlighted_stream",- "Stream Verona is not highlighted"- );-});--// Use arrow keys to navigate through suggestions-casper.then(function () {- function arrow(key) {- casper.sendKeys(".stream-list-filter", casper.page.event.key[key], {keepFocus: true});- }- arrow("Down"); // Denmark -> Venice- arrow("Up"); // Venice -> Denmark- arrow("Up"); // Denmark -> Denmark- arrow("Down"); // Denmark -> Venice-});--casper.then(function () {- casper.waitForSelector(get_stream_li("Venice") + ".highlighted_stream", function () {- casper.test.info("Suggestion highlighting - after arrow key navigation");- casper.test.assertDoesntExist(- get_stream_li("Denmark") + ".highlighted_stream",- "Stream Denmark is not highlighted"- );- casper.test.assertExist(- get_stream_li("Venice") + ".highlighted_stream",- "Stream Venice is highlighted"- );- casper.test.assertDoesntExist(- get_stream_li("Verona") + ".highlighted_stream",- "Stream Verona is not highlighted"- );- });-});--// We search for the beginning of "Venice", not case sensitive-casper.then(function () {- casper.evaluate(function () {- $(".stream-list-filter")- .expectOne()- .trigger("focus")- .val("vEnI")- .trigger($.Event("input"))- .trigger($.Event("click"));- });-});--// There will be no race condition between these two waits because we-// expect them to happen in parallel.-casper.waitWhileVisible(get_stream_li("Denmark"), function () {- casper.test.info("Search term entered");- casper.test.assertDoesntExist(- get_stream_li("Denmark"),- "Filtered stream list does not contain Denmark"- );-});-casper.waitWhileVisible(get_stream_li("Verona"), function () {- casper.test.assertDoesntExist(- get_stream_li("Verona"),- "Filtered stream list does not contain Verona"- );-});--casper.then(function () {- casper.test.assertExists(get_stream_li("Venice"), "Filtered stream list does contain Venice");- casper.test.assertExists(- get_stream_li("Venice") + ".highlighted_stream",- "Stream Venice is highlighted"- );-});--// Clearing the list should give us back all the streams in the list-casper.then(function () {- casper.evaluate(function () {- $(".stream-list-filter").expectOne().trigger("focus").val("").trigger($.Event("input"));- });-});--casper.then(function () {- casper.waitUntilVisible(get_stream_li("Denmark"), function () {- casper.test.assertExists(get_stream_li("Denmark"), "Restored stream list contains Denmark");- });- casper.waitUntilVisible(get_stream_li("Venice"), function () {- casper.test.assertExists(get_stream_li("Denmark"), "Restored stream list contains Venice");- });- casper.waitUntilVisible(get_stream_li("Verona"), function () {- casper.test.assertExists(get_stream_li("Denmark"), "Restored stream list contains Verona");- });-});--casper.thenClick("#streams_header .sidebar-title");--casper.waitForSelector(".input-append.notdisplayed", function () {- casper.test.assertExists(- ".input-append.notdisplayed",- "Stream filter box not visible after second click"- );-});--// We search for the beginning of "Verona", not case sensitive-casper.then(function () {- casper.evaluate(function () {- $(".stream-list-filter").expectOne().trigger("focus").val("ver").trigger($.Event("input"));- });-});--casper.waitWhileVisible(get_stream_li("Denmark"), function () {- // Clicking the narrowed list should clear the search- casper.click(get_stream_li("Verona") + " a");- expect_stream();- casper.test.assertEquals(- casper.fetchText(".stream-list-filter"),- "",- "Clicking on a stream clears the search"- );-});--un_narrow();--function assert_in_list(name) {- casper.test.assertExists(- '#user_presences li [data-name="' + name + '"]',- "User " + name + " is IN buddy list"- );-}--function assert_selected(name) {- casper.test.assertExists(- '#user_presences li.highlighted_user [data-name="' + name + '"]',- "User " + name + " is SELECTED IN buddy list"- );-}--function assert_not_selected(name) {- assert_in_list(name);- casper.test.assertDoesntExist(- '#user_presences li.highlighted_user [data-name="' + name + '"]',- "User " + name + " is NOT SELECTED buddy list"- );-}--// User search at the right sidebar-casper.then(function () {- casper.test.info("Search users using right sidebar");- assert_in_list("Desdemona");- assert_in_list("Cordelia Lear");- assert_in_list("King Hamlet");- assert_in_list("aaron");-});--// Enter the search box and test selected suggestion navigation-// Click on search icon-casper.then(function () {- casper.evaluate(function () {- $("#user_filter_icon").expectOne().trigger("focus").trigger($.Event("click"));- });-});--casper.waitForSelector("#user_presences .highlighted_user", function () {- casper.test.info("Suggestion highlighting - initial situation");- assert_selected("Desdemona");- assert_not_selected("Cordelia Lear");- assert_not_selected("King Hamlet");- assert_not_selected("aaron");-});--// Use arrow keys to navigate through suggestions-casper.then(function () {- function arrow(key) {- casper.sendKeys(".user-list-filter", casper.page.event.key[key], {keepFocus: true});- }-- // go down 2, up 3 (which is really 2), then down 3- // Iago- // Cordelia- // Desdemona- // Hamlet- arrow("Down");- arrow("Down");- arrow("Up");- arrow("Up");- arrow("Up"); // does nothing- arrow("Down");- arrow("Down");- arrow("Down");-});--casper.waitForSelector(- '#user_presences li.highlighted_user [data-name="King Hamlet"]',- function () {- casper.test.info("Suggestion highlighting - after arrow key navigation");- assert_not_selected("Iago");- assert_not_selected("Cordelia Lear");- assert_selected("King Hamlet");- }-);--common.then_log_out();--// Run the above queued actions.-casper.run(function () {- casper.test.done();-});diff --git a/frontend_tests/puppeteer_tests/02-message-basics.js b/frontend_tests/puppeteer_tests/02-message-basics.jsindex e85ac8dc5fa..d7ec40f2f3e 100644--- a/frontend_tests/puppeteer_tests/02-message-basics.js+++ b/frontend_tests/puppeteer_tests/02-message-basics.js@@ -1,7 +1,408 @@"use strict";+const assert = require("assert").strict;+const common = require("../puppeteer_lib/common");+async function get_stream_li(page, stream_name) {+ const stream_id = await common.get_stream_id(page, stream_name);+ return `#stream_filters [data-stream-id="${stream_id}"]`;+}++async function expect_home(page) {+ await common.check_messages_sent(page, "zhome", [+ ["Verona > test", ["verona test a", "verona test b"]],+ ["Verona > other topic", ["verona other topic c"]],+ ["Denmark > test", ["denmark message"]],+ ["You and Cordelia Lear, King Hamlet", ["group pm a", "group pm b"]],+ ["You and Cordelia Lear", ["pm c"]],+ ["Verona > test", ["verona test d"]],+ ["You and Cordelia Lear, King Hamlet", ["group pm d"]],+ ["You and Cordelia Lear", ["pm e"]],+ ]);+}++async function expect_verona_stream(page) {+ await page.waitForSelector("#zfilt", {visible: true});+ await common.check_messages_sent(page, "zfilt", [+ ["Verona > test", ["verona test a", "verona test b"]],+ ["Verona > other topic", ["verona other topic c"]],+ ["Verona > test", ["verona test d"]],+ ]);+ assert.strictEqual(await page.title(), "Verona - Zulip Dev - Zulip");+}++async function expect_verona_stream_test_topic(page) {+ await page.waitForSelector("#zfilt", {visible: true});+ await common.check_messages_sent(page, "zfilt", [+ ["Verona > test", ["verona test a", "verona test b", "verona test d"]],+ ]);+ assert.strictEqual(+ await common.get_text_from_selector(page, "#left_bar_compose_stream_button_big"),+ "New topic",+ );+}++async function expect_verona_other_topic(page) {+ await page.waitForSelector("#zfilt", {visible: true});+ await common.check_messages_sent(page, "zfilt", [+ ["Verona > other topic", ["verona other topic c"]],+ ]);+}++async function expect_test_topic(page) {+ await page.waitForSelector("#zfilt", {visible: true});+ await common.check_messages_sent(page, "zfilt", [+ ["Verona > test", ["verona test a", "verona test b"]],+ ["Denmark > test", ["denmark message"]],+ ["Verona > test", ["verona test d"]],+ ]);+}++async function expect_huddle(page) {+ await page.waitForSelector("#zfilt", {visible: true});+ await common.check_messages_sent(page, "zfilt", [+ ["You and Cordelia Lear, King Hamlet", ["group pm a", "group pm b", "group pm d"]],+ ]);+ assert.strictEqual(await page.title(), "Cordelia Lear, King Hamlet - Zulip Dev - Zulip");+}++async function expect_cordelia_private_narrow(page) {+ await page.waitForSelector("#zfilt", {visible: true});+ await common.check_messages_sent(page, "zfilt", [["You and Cordelia Lear", ["pm c", "pm e"]]]);+}++async function un_narrow(page) {+ if (await page.evaluate(() => $(".message_comp").is(":visible"))) {+ await page.keyboard.press("Escape");+ }+ await page.keyboard.press("Escape");+ await page.waitForSelector("#zhome .message_row", {visible: true});+ assert.strictEqual(await page.title(), "home - Zulip Dev - Zulip");+}++async function un_narrow_by_clicking_org_icon(page) {+ await page.click(".brand");+}++async function test_navigations_from_home(page) {+ console.log("Narrowing by clicking stream");+ await page.evaluate(() => $(`*[title='Narrow to stream "Verona"']`).click());+ await expect_verona_stream(page);++ assert.strictEqual(await page.title(), "Verona - Zulip Dev - Zulip");+ await un_narrow(page);+ await expect_home(page);++ console.log("Narrowing by clicking topic");+ await page.click('*[title="Narrow to stream \\"Verona\\", topic \\"test\\""]');+ await expect_verona_stream_test_topic(page);++ await un_narrow_by_clicking_org_icon(page);+ await expect_home(page);++ console.log("Narrowing by clicking group personal header");+ await page.evaluate(() =>+ $('*[title="Narrow to your private messages with Cordelia Lear, King Hamlet"]').click(),+ );+ await expect_huddle(page);++ await un_narrow_by_clicking_org_icon(page);+ await expect_home(page);+}++async function search_and_check(page, search_str, item_to_select, check, expected_narrow_title) {+ await common.select_item_via_typeahead(page, "#search_query", search_str, item_to_select);+ await check(page);+ assert.strictEqual(await page.title(), expected_narrow_title);+ await un_narrow(page);+ await expect_home(page);+}++async function search_silent_user(page, str, item) {+ await common.select_item_via_typeahead(page, "#search_query", str, item);+ await page.waitForSelector("#silent_user", {visible: true});+ const expect_message = "You haven't received any messages sent by this user yet!";+ assert.strictEqual(await common.get_text_from_selector(page, "#silent_user"), expect_message);+ await un_narrow(page);+}++async function expect_non_existing_user(page) {+ await page.waitForSelector("#non_existing_user", {visible: true});+ const expected_message = "This user does not exist!";+ assert.strictEqual(+ await common.get_text_from_selector(page, "#non_existing_user"),+ expected_message,+ );+}++async function expect_non_existing_users(page) {+ await page.waitForSelector("#non_existing_users", {visible: true});+ const expected_message = "One or more of these users do not exist!";+ assert.strictEqual(+ await common.get_text_from_selector(page, "#non_existing_users"),+ expected_message,+ );+}++async function search_non_existing_user(page, str, item) {+ await common.select_item_via_typeahead(page, "#search_query", str, item);+ await expect_non_existing_user(page);+ await un_narrow(page);+}++async function search_tests(page) {+ await search_and_check(+ page,+ "Verona",+ "Stream",+ expect_verona_stream,+ "Verona - Zulip Dev - Zulip",+ );++ await search_and_check(+ page,+ "Cordelia",+ "Private",+ expect_cordelia_private_narrow,+ "Cordelia Lear - Zulip Dev - Zulip",+ );++ await search_and_check(+ page,+ "stream:Verona",+ "",+ expect_verona_stream,+ "Verona - Zulip Dev - Zulip",+ );++ await search_and_check(+ page,+ "stream:Verona topic:test",+ "",+ expect_verona_stream_test_topic,+ "test - Zulip Dev - Zulip",+ );++ await search_and_check(+ page,+ "stream:Verona topic:other+topic",+ "",+ expect_verona_other_topic,+ "other topic - Zulip Dev - Zulip",+ );++ await search_and_check(page, "topic:test", "", expect_test_topic, "home - Zulip Dev - Zulip");++ await search_silent_user(page, "sender:[email protected]", "");++ await search_non_existing_user(page, "sender:[email protected]", "");++ await search_and_check(+ page,+ "pm-with:[email protected]",+ "",+ expect_non_existing_user,+ "Invalid user - Zulip Dev - Zulip",+ );++ await search_and_check(+ page,+ "pm-with:[email protected],[email protected]",+ "",+ expect_non_existing_users,+ "Invalid users - Zulip Dev - Zulip",+ );+}++async function expect_all_pm(page) {+ await page.waitForSelector("#zfilt", {visible: true});+ await common.check_messages_sent(page, "zfilt", [+ ["You and Cordelia Lear, King Hamlet", ["group pm a", "group pm b"]],+ ["You and Cordelia Lear", ["pm c"]],+ ["You and Cordelia Lear, King Hamlet", ["group pm d"]],+ ["You and Cordelia Lear", ["pm e"]],+ ]);+ assert.strictEqual(+ await common.get_text_from_selector(page, "#left_bar_compose_stream_button_big"),+ "New stream message",+ );+ assert.strictEqual(await page.title(), "Private messages - Zulip Dev - Zulip");+}++async function test_narrow_by_clicking_the_left_sidebar(page) {+ console.log("Narrowing with left sidebar");++ await page.click((await get_stream_li(page, "Verona")) + " a");+ await expect_verona_stream(page);++ await page.click(".top_left_all_messages a");+ await expect_home(page);++ await page.click(".top_left_private_messages a");+ await expect_all_pm(page);++ await un_narrow(page);+}++async function arrow(page, direction) {+ await page.keyboard.press(`Arrow${direction}`);+}++async function test_search_venice(page) {+ await page.evaluate(() => {+ $(".stream-list-filter")+ .expectOne()+ .trigger("focus")+ .val("vEnI") // Must be case insensitive.+ .trigger($.Event("input"))+ .trigger($.Event("click"));+ });++ await page.waitForSelector(await get_stream_li(page, "Denmark"), {hidden: true});+ await page.waitForSelector(await get_stream_li(page, "Verona"), {hidden: true});+ await page.waitForSelector((await get_stream_li(page, "Venice")) + ".highlighted_stream", {+ visible: true,+ });++ // Clearing list gives back all the streams in the list+ await page.evaluate(() =>+ $(".stream-list-filter").expectOne().trigger("focus").val("").trigger($.Event("input")),+ );+ await page.waitForSelector(await get_stream_li(page, "Denmark"), {visible: true});+ await page.waitForSelector(await get_stream_li(page, "Venice"), {visible: true});+ await page.waitForSelector(await get_stream_li(page, "Verona"), {visible: true});++ await page.click("#streams_header .sidebar-title");+ await page.waitForSelector(".input-append.notdisplayed");+}++async function test_stream_search_filters_stream_list(page) {+ console.log("Search streams using left side bar");++ await page.waitForSelector(".input-append.notdisplayed"); // Stream filter box invisible initially+ await page.click("#streams_header .sidebar-title");++ await page.waitForSelector("#streams_list .input-append.notdisplayed", {hidden: true});++ // assert streams exist by waiting till they're visible+ await page.waitForSelector(await get_stream_li(page, "Denmark"), {visible: true});+ await page.waitForSelector(await get_stream_li(page, "Venice"), {visible: true});+ await page.waitForSelector(await get_stream_li(page, "Verona"), {visible: true});++ // Enter the search box and test highlighted suggestion+ await page.evaluate(() =>+ $(".stream-list-filter").expectOne().trigger("focus").trigger($.Event("click")),+ );++ await page.waitForSelector("#stream_filters .highlighted_stream", {visible: true});+ // First stream in list gets highlihted on clicking search.+ await page.waitForSelector((await get_stream_li(page, "Denmark")) + ".highlighted_stream", {+ visible: true,+ });+ await page.waitForSelector((await get_stream_li(page, "Venice")) + ".highlighted_stream", {+ hidden: true,+ });+ await page.waitForSelector((await get_stream_li(page, "Verona")) + ".highlighted_stream", {+ hidden: true,+ });++ // Navigate through suggesrions using arrow keys+ await arrow(page, "Down"); // Denmark -> Venice+ await arrow(page, "Up"); // Venice -> Denmark+ await arrow(page, "Up"); // Denmark -> Denmark+ await arrow(page, "Down"); // Denmark -> Venice++ await page.waitForSelector((await get_stream_li(page, "Venice")) + ".highlighted_stream", {+ visible: true,+ });+ await page.waitForSelector((await get_stream_li(page, "Denmark")) + ".highlighted_stream", {+ hidden: true,+ });+ await page.waitForSelector((await get_stream_li(page, "Verona")) + ".highlighted_stream", {+ hidden: true,+ });++ await test_search_venice(page);++ // Search for brginning of "Verona".+ await page.evaluate(() =>+ $(".stream-list-filter").expectOne().trigger("focus").val("ver").trigger($.Event("input")),+ );+ await page.waitForSelector(await get_stream_li(page, "Denmark"), {hidden: true});+ await page.click(await get_stream_li(page, "Verona"));+ await expect_verona_stream(page);+ assert.strictEqual(+ await common.get_text_from_selector(page, ".stream-list-filter"),+ "",+ "Clicking on stream didn't clear search",+ );+ await un_narrow(page);+}++async function test_users_search(page) {+ console.log("Search users using right sidebar");+ async function assert_in_list(page, name) {+ await page.waitForSelector(`#user_presences li [data-name="${name}"]`, {visible: true});+ }++ async function assert_selected(page, name) {+ await page.waitForSelector(`#user_presences li.highlighted_user [data-name="${name}"]`, {+ visible: true,+ });+ }++ async function assert_not_selected(page, name) {+ await common.assert_selector_doesnt_exist(+ page,+ `#user_presences li.highlighted_user [data-name="${name}"]`,+ );+ }++ await assert_in_list(page, "Desdemona");+ await assert_in_list(page, "Cordelia Lear");+ await assert_in_list(page, "King Hamlet");+ await assert_in_list(page, "aaron");++ // Enter the search box and test selected suggestion navigation+ await page.evaluate(() =>+ $("#user_filter_icon").expectOne().trigger("focus").trigger($.Event("click")),+ );+ await page.waitForSelector("#user_presences .highlighted_user", {visible: true});+ await assert_selected(page, "Desdemona");+ await assert_not_selected(page, "Cordelia Lear");+ await assert_not_selected(page, "King Hamlet");+ await assert_not_selected(page, "aaron");++ // Navigate using arrow keys.+ // go down 2, up 3, then down 3+ // Desdemona+ // aaron+ // Cordelia Lear+ // Iago+ await arrow(page, "Down");+ await arrow(page, "Down");+ await arrow(page, "Up");+ await arrow(page, "Up");+ await arrow(page, "Up"); // does nothing; allready on the top.+ await arrow(page, "Down");+ await arrow(page, "Down");+ await arrow(page, "Down");++ // Now Iago must be highlighted+ await page.waitForSelector('#user_presences li.highlighted_user [data-name="Iago"]', {+ visible: true,+ });+ await assert_not_selected(page, "King Hamlet");+ await assert_not_selected(page, "aaron");+ await assert_not_selected(page, "Desdemona");++ // arrow up and press Enter. We should be taken to pms with Cordelia Lear+ await arrow(page, "Up");+ await page.keyboard.press("Enter");+ await expect_cordelia_private_narrow(page);+}+async function message_basic_tests(page) {await common.log_in(page);@@ -10,17 +411,22 @@ async function message_basic_tests(page) {{stream: "Verona", topic: "test", content: "verona test a"},{stream: "Verona", topic: "test", content: "verona test b"},{stream: "Verona", topic: "other topic", content: "verona other topic c"},+ {stream: "Denmark", topic: "test", content: "denmark message"},{recipient: "[email protected], [email protected]", content: "group pm a"},{recipient: "[email protected], [email protected]", content: "group pm b"},{recipient: "[email protected]", content: "pm c"},+ {stream: "Verona", topic: "test", content: "verona test d"},+ {recipient: "[email protected], [email protected]", content: "group pm d"},+ {recipient: "[email protected]", content: "pm e"},]);- await common.check_messages_sent(page, "zhome", [- ["Verona > test", ["verona test a", "verona test b"]],- ["Verona > other topic", ["verona other topic c"]],- ["You and Cordelia Lear, King Hamlet", ["group pm a", "group pm b"]],- ["You and Cordelia Lear", ["pm c"]],- ]);+ await expect_home(page);++ await test_navigations_from_home(page);+ await search_tests(page);+ await test_narrow_by_clicking_the_left_sidebar(page);+ await test_stream_search_filters_stream_list(page);+ await test_users_search(page);await common.log_out(page);}