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

feat: first draft of anvil-cmg filter tests (#4068) #4071

Merged
merged 16 commits into from
Aug 23, 2024

Conversation

jpaten
Copy link
Contributor

@jpaten jpaten commented Jul 8, 2024

Ticket

Closes #4068 .

Reviewers

@NoopDog .

Changes

Added the following tests for AnVIL-CMG

  • Check that all filters defined in explorer/e2e/anvilTabs.js display on each tab, are clickable, and cause a checkbox to be displayed
  • Check that selecting the first 5 checkboxes on one arbitrary filter on the datasets tab does not remove any elements from the table
  • Check that selecting the first checkbox on an one arbitrary filter on the datasets causes that box to remain checked when each of the other tabs is selected
  • Check that the stated number of entries visible matches the number displayed next to the entry on the filter menu for an arbitrary but constant set of filters
  • Check that the blue filter bubbles match the filter settings and that clicking them deselects the filter for an arbitrary but constant set of filters
  • Check that the "Clear All" button functions correctly for an arbitrary but constant set of filters

@jpaten jpaten linked an issue Jul 8, 2024 that may be closed by this pull request
@github-actions github-actions bot added the canary Done by the Clever Canary team label Jul 8, 2024
@jpaten jpaten force-pushed the 4068-add-e2e-test-for-filters branch 2 times, most recently from 78bf69e to ac63c9d Compare July 15, 2024 01:33
@jpaten jpaten marked this pull request as ready for review July 15, 2024 04:32
@jpaten jpaten requested a review from NoopDog July 15, 2024 04:37
} from "../testFunctions";
import { anvilFilters, anvilTabs, anvilTabTestOrder } from "./anvil-tabs";

test.describe.configure({ mode: "parallel", timeout: 60 * 1000 });
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you be able to tell me why you needed to add this here rather than in a global config file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made a mistake - that shouldn't have been necessary, I think I just copied the header of this file form another test where I had also forgotten to remove it. I'll remove this header from all the tests in #4078 , thanks for catching it here!

);
});

test.setTimeout(120000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you give me the background on why we need the test.setTimeout calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi! When I ran these tests locally, I found that they would sometimes take too long and timeout. Adding the setTimeout calls here means the timeout for these particular tests is extended from 60 seconds to 120 seconds, which resolved the issue. I can also reduce the number of tests they run on if that is preferable. If this timeout value was changed in the global config, the timeout for all tests would be longer than necessary, causing tests to take longer if they fail.

Comment on lines 13 to 14
const filter_index_list = [3, 4, 5, 10, 6, 2];
const filter_index_list_short = [1, 10, 3];
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you be able to update these two to be MACRO_CASE to help indicate they are constants? Also, can you create constants for the integer values so it's more obvious what they are? For example:

const FILTER_ASSAY_INDEX = 3;
const FILTER_GENDER_INDEX = 4;

const FILTER_INDEX_LIST = [FILTER_ASSAY_INDEX, FILTER_GENDER_INDEX];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do! Do you think it makes sense to store those constants in this file or in anvilTabs.ts?

.click();
// Expect all checkboxes to be unchecked initially and to work properly
await expect(page.getByRole("checkbox").first()).toBeVisible();
const all_checkboxes = await page.getByRole("checkbox").all();
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you update this variable to be camel-case (and also any other snake-case local variables throughout)?

}) => {
await testFilterPersistence(
page,
anvilFilters[3],
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you create a constant for 3 so help indicate its value?

testFilterPersistence,
testFilterPresence,
} from "../testFunctions";
import { anvilFilters, anvilTabs, anvilTabTestOrder } from "./anvil-tabs";
Copy link
Contributor

Choose a reason for hiding this comment

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

This is outside the scope of this PR but would you be able to update anvilFilters, anvilTabs, and anvilTabTestOrder to be MACRO_CASE to help indicate they are constants?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah sure! I'll do it in the cleanup ticket

page,
anvilTabs.datasets,
filter_index_list.map((x) => anvilFilters[x]),
25
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's create a constant for this default page size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on how I've done other tests, it'd might make sense to have it as an attribute of each tab object (so each tab would have an associated maxPages), since I've tried to store constants that relate to the site there. I can make it a constant in this file though if you think that'd make more sense though, I've just tried to keep the constants there those that relate to the configuration of the actual test.


export const getFirstElementTextLocator = (
page: Page,
workColumnPosition: number
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename this to columnIndex? I'm not familiar with "work column" so feel free to keep it as is if this is a known concept.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, just a random variable name I thought of at the time but that only made sense in my head, I'll make sure to review those in more detail for future PRs!

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you go ahead and rename workColumnPosition to columnIndex, here and throughout?

export async function testFilterPresence(
page: Page,
tab: TabDescription,
filters: string[]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this an array of filter names? If so, what about renaming this to filterNames?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update this to filterNames, here and throughout? Can you also update the corresponding for (const filter of filters) to for (const filterName of filterNames)?

Copy link
Contributor

@MillenniumFalconMechanic MillenniumFalconMechanic left a comment

Choose a reason for hiding this comment

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

Looks good, thanks Jonah! I've asked for a couple of changes. Once you've pushed your updates, I'll do another review round on testFunctions.

page,
}) => {
test.setTimeout(120000);
await testFilterBubbles(
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we call the bubbles "tags"; can you rename bubbles to "tags" here and throughout?

explorer/e2e/anvil/anvil-tabs.ts Show resolved Hide resolved

export const getFirstElementTextLocator = (
page: Page,
workColumnPosition: number
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you go ahead and rename workColumnPosition to columnIndex, here and throughout?

import { TabDescription } from "./testInterfaces";

/* eslint-disable sonarjs/no-duplicate-string -- ignoring duplicate strings here */
// Run the "Expect each tab to appear as selected when the corresponding url is accessed" test

export const getFirstElementTextLocator = (
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this function is grabbing the first row in the table and then grabbing the text from the nth column; if so, can you rename this to getFirstRowNthColumnCellTextLocator or similar? It's a long name but I feel its gives a clearer idea of the function's intention.

@@ -207,4 +215,208 @@ export async function testPreSelectedColumns(
}
}

export const filterRegex = (filter: string): RegExp =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment describing the regex?

export async function testFilterPresence(
page: Page,
tab: TabDescription,
filters: string[]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update this to filterNames, here and throughout? Can you also update the corresponding for (const filter of filters) to for (const filterName of filterNames)?

/\.\S*/
);
if (filterNameMatch == null) {
test.fail();
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to return a boolean here and call test.fail in the calling code? This matches the pattern in testFilterCount.

@@ -1,8 +1,22 @@
import { expect, Page } from "@playwright/test";
import { expect, Locator, Page, test } from "@playwright/test";
import { TabDescription } from "./testInterfaces";

/* eslint-disable sonarjs/no-duplicate-string -- ignoring duplicate strings here */
// Run the "Expect each tab to appear as selected when the corresponding url is accessed" test
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this comment go with the function below? If so, can you remove the whitespace below?

import { TabDescription } from "./testInterfaces";

/* eslint-disable sonarjs/no-duplicate-string -- ignoring duplicate strings here */
// Run the "Expect each tab to appear as selected when the corresponding url is accessed" test

export const getFirstElementTextLocator = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you be able to add TSDocs for each function in this functions file? You can see examples of what I'm expecting here, here, or here.

Copy link
Contributor

@MillenniumFalconMechanic MillenniumFalconMechanic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Jonah!

@jpaten jpaten force-pushed the 4068-add-e2e-test-for-filters branch from 6d4b8b4 to ffa69f5 Compare August 23, 2024 03:39
@jpaten jpaten merged commit 7657375 into main Aug 23, 2024
4 checks passed
@jpaten jpaten deleted the 4068-add-e2e-test-for-filters branch August 23, 2024 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
canary Done by the Clever Canary team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add E2E Test for Filters
2 participants