Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added puppeteer tests for recent topic view. #18170

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

aryanshridhar
Copy link
Member

Added puppeteer tests for Recent topic View as listed within #18031 and fixed a minor typo within drafts.ts.

Updated checklist:

  • Filters selection -- ce7b593
  • Search for topics -- 88c65f4
  • Clicking on row elements like stream and topic takes them to appropriate narrow -- 3c0f9a7
  • Read and mute action buttons work properly -- f3886f5
  • Compose actions work as intended.

Issues:

Added few comments below addressing the issues.


Would appreciate a review @amanagr.

Also, Thanks to @Riken-Shah for guiding me with the hurdles faced with nondeterminstic failures.(Still need to fix them though!)

Rectified a minor typo by renaming `dissapear` to `disappear`.
Added puppeteer test for `recent-topic` view at the time of initial
page load.
Here, `initial page load` refers to the point when puppeteer navigates
to recent topic view using the left sidebar.
…view.

Added puppeteer tests for elliptical filters within
recent topic view.
The commit adds the following tests:

Single selection:

- test_all_filter_button: Tests for `All` elliptical filter button.
- test_include_muted_filter_button: Tests for `Include muted` filter.
- test_unread_filter_button: Tests for `Unread` filter button.
- test_participated_filter_button: Tests for `Participated` elliptical filter.

Multiple selection (when multiple filters are triggered):

- test_include_muted_and_unread_filter_button: Tests for `Include muted`
as well as `Unread` filter button.
- test_unread_and_participated_filter_button: Tests for `Unread` and
`Participated` filter buttons.
- test_include_muted_and_participated_filter_button: Tests for `Include Muted`
and `Participated` elliptical filters.
- test_all_filters: Tests when all the elliptical filter buttons are triggered.

Fixes part of zulip#18031.
The following commit adds tests for stream and topic navigation
within recent topic view. When clicked row elements like stream/
topic it navigates to their appropriate narrow.

The tests include following functions:

- test_stream_navigation: Tests for stream navigation, i.e, when
clicked upon certain stream from recent topic view.
- test_topic_navigation: Tests for topic navigation when clicked
upon a certain topic.
- test_recent_topic_hotkey: Tests for `t` keyboard hotkey which
navigates back to `Recent topic view` from a particular narrow.

Fixes part of zulip#18031.
Added puppeteer tests for search input field within recent
topic view, which filters the topics with respect to
the text passed within the input field.

The commit adds the following test function:

- test_filter_topic_input: Filters the recent topic feed when text `nas`
is passed within the `filter topic` input field.

Fixes part of zulip#18031.
…pic.

Added tests for read and mute topic row actions within
recent topic view.
The commit adds the following tests:

- test_mark_as_read_button: Tests for `mark as read` button by
marking the `plotter` topic as read.
- test_muted_topic_button: Tests for `mute topic` button by
muting the `URLS` topic row.

Fixes part of zulip#18031.
recent_topic_page,
no_of_topics,
);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing a nondeterminstic failure when targeted it to run for 100x in CI. Here's the link to workflow which is failing at around 20ish iteration.
As the workflow suggestes, it's causing because of this (wait_for_topics_to_filter) block of function since the waitForFunction isn't returning a truth value and hence causing a TimeoutError error.

Looking to the artifacts generated, It's surprising to see that the filter input still contains some text. Here's the screenshot:
failure-0

Would love any suggestions regarding it :)

Edit: The main purpose for this function is to wait until all the topics are filtered once any query is typed in filter input field (Since it takes a few milliseconds for the recent topic ListWidget to filter).

Edit 2: Added a different workaround for the function and triggered the workflow file again. Let's hope I get lucky this time :)

Edit 3: Ahh! Still failing!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After checking the screenshot it looks like the input value was not fully typed.

So, it's not the issue with this code.

The most probably fix for this is to when you type in filter input make sure you click it first then wait until it is focused then start writing.

Check the last point of this https://zulip.readthedocs.io/en/latest/testing/testing-with-puppeteer.html#debugging-puppeteer-tests.

await trigger_filter_button(page, unread_filter_button);

const stream_names = await get_stream_names(page);
assert.deepStrictEqual(stream_names, []);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default there isn't any unread topic/muted topic when the puppeteer logs in. This leads to Unread filter button returns a empty array of topics and Include Muted filter button to return the same result as All filter button.
(Mentioned this as I somehow felt like this isn't the right way to proceed.)

@amanagr
Copy link
Member

amanagr commented Apr 16, 2021

@Riken-Shah can you take point in reviewing this? I am not the best person to review these tests. I will take a look later.

Copy link
Member

@Riken-Shah Riken-Shah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aryanshridhar posted a batch of comments.

Let me know if you need any help!

const recent_topic_page = "#recent_topics_view";

// Returns an array based on all text found within the selector passed.
async function get_selector_text(page: Page, selector: string): Promise<string[]> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function name can be improved.
Something like get_all_element_text_from_selector?


import common from "../puppeteer_lib/common";

const recent_topic_page = "#recent_topics_view";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't done something like this on other tests.
I really like the idea of declaring common selectors at the top.

@@ -16,6 +20,11 @@ async function get_selector_text(page: Page, selector: string): Promise<string[]
return text;
}

async function trigger_filter_button(page: Page, selector: string): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so we need this function here.
(Also, the function name doesn't justify what it does.)

But I really like this idea.
Maybe we can add this function in common.ts by the name wait_and_click.
And refactor all the puppeteer tests to use this.
Thoughts @chdinesh1089, @andersk?

recent_topic_page,
no_of_topics,
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After checking the screenshot it looks like the input value was not fully typed.

So, it's not the issue with this code.

The most probably fix for this is to when you type in filter input make sure you click it first then wait until it is focused then start writing.

Check the last point of this https://zulip.readthedocs.io/en/latest/testing/testing-with-puppeteer.html#debugging-puppeteer-tests.

async function wait_for_topics_to_filter(page: Page, no_of_topics: number): Promise<void> {
await page.waitForSelector(recent_topic_page);

await page.waitForFunction(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insted of this how about,

// Subtracting 1 from $("table:first tr").length because of heading row.
 await page.waitForFunction((no_of_topics: number) => ($("table:first tr").length - 1) === no_of_topics,{}, no_of_topics);


for (let i = 0; i < input_text.length; i += 1) {
await page.keyboard.press("Backspace");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you are using this function to only clear the value of #recent_topics_search.

How about this,

    await page.waitForSelector(recent_topic_page);
    const recent_topic_search_selector = "#recent_topics_search";
    await page.click(recent_topic_search_selector);
    await page.waitForFunction(() => $(`#recent_topics_search:focus`).attr("id") === "recent_topics_search");
    await common.clear_and_type(page, recent_topic_search_selector, " ");
    // Wait for all topics to load back again.
    await wait_for_topics_to_filter(page, 7);

Also, update the name of the function.
Maybe clear_recent_topic_search ?

Tip: When you want to clear the value and then type you can use common.clear_and_type.

await page.evaluate((topic: string) => {
const mark_as_read_icon = $(`.on_hover_topic_read[data-topic-name='${topic}']`);
mark_as_read_icon.trigger("click");
}, topic);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not await page.click(`.on_hover_topic_read[data-topic-name='${topic}']`);?

Tip: Avoid using evaluated js as much as you can.

const mute_icon = $(`.on_hover_topic_mute[data-topic-name='${topic}']`);
mute_icon.trigger("click");
}, topic);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not await page.click(`.on_hover_topic_mute[data-topic-name='${topic}']`);?

@@ -5,6 +5,10 @@ import type {Page} from "puppeteer";
import common from "../puppeteer_lib/common";

const recent_topic_page = "#recent_topics_view";
const all_filter_button = ".btn-recent-filters[data-filter='all']";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so we need this as a global variable as it's only used once.


async function test_stream_navigation(page: Page, stream_name: string): Promise<void> {
await page.waitForSelector(recent_topic_page, {visible: true});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so we need this function.

As we are using it only once.

You can study this function about how to navigate with the stream,

async function navigate_using_left_sidebar(


async function test_topic_navigation(page: Page, topic_name: string): Promise<void> {
await page.waitForSelector(recent_topic_page, {visible: true});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so we need this function.

Reason -- Same as this comment.

@Riken-Shah
Copy link
Member

@aryanshridhar After you are done with the changes, can you also check it by running 100x in Firefox mode?

@zulipbot
Copy link
Member

Heads up @aryanshridhar, we just merged some commits that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants