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

updates bullet tests for expansion #2243

Open
wants to merge 1 commit into
base: test-michael
Choose a base branch
from

Conversation

Cur1yJ
Copy link

@Cur1yJ Cur1yJ commented Aug 7, 2024

Updates broken expansion tests

  • Updates tests to work without adding additional attributes to frontend component
  • No longer relies on the downstream findSubthoughts function, instead, utilizes the index of the payloads to be tested
  • Takes a layered approach, first checking the state, then the DOM
  • Keeps the original goals of the tests in-place

@Cur1yJ Cur1yJ changed the base branch from main to test-michael August 7, 2024 00:47
Comment on lines +292 to +293
// Expect that the entire "pin" section is removed:
expect(newState).not.toContain('- =pin\n - true')
Copy link
Contributor

@raineorshine raineorshine Aug 7, 2024

Choose a reason for hiding this comment

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

We already have reducer tests that make assertions about the Redux state, so we actually want to avoid accessing or exporting the state in the component tests.

The component tests should test what is rendered to the DOM.

Comment on lines +149 to +150
// Click the second bullet directly:
await userEvent.click(bulletElements[1]) // Index 1 for the second bullet
Copy link
Contributor

Choose a reason for hiding this comment

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

Selecting all bullets and then indexing into the array is not ideal, because it couples the test to the linear order of thoughts as they are rendered from top-to-bottom on the screen. If a thought is the 2nd or 4th or 10th from the top, that's not very meaningful to the user. While it's not much of a problem when only rendering a few thoughts, it's going to become a problem for tests that involve a larger number of thoughts, or deeply nested thoughts. Pretty soon you have developers counting lines of code in order to figure out which thoughtContainers[12] refers to. And adding one thought at the top changes the indexes all the way down.

Instead, we want to find a way to select a thought based on its text. You can use contextToPath(['a', 'b']) to get the path which can be used to select the exact testid of interest. Or you could select by the visible text itself, or embed the thought value in a data attribute. They each have their tradeoffs, but at least they are not dependent on the linear order.

Let me know what you think. Thanks!

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

Successfully merging this pull request may close these issues.

2 participants