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

refactor(multi-select): rewrite all enzyme tests with React Testing Library (FE-6693) #7037

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Parsium
Copy link
Contributor

@Parsium Parsium commented Oct 24, 2024

Proposed behaviour

  • Rewrite all Enzyme tests with React Testing Library (RTL)

Current behaviour

  • The majority of the jest tests for MultiSelect are written with Enzyme, which is a legacy package

Checklist

  • Commits follow our style guide
  • Related issues linked in commit messages if required
  • Screenshots are included in the PR if useful
  • All themes are supported if required
  • Unit tests added or updated if required
  • Playwright automation tests added or updated if required
  • Storybook added or updated if required
  • Translations added or updated (including creating or amending translation keys table in storybook) if required
  • Typescript d.ts file added or updated if required
  • Related docs have been updated if required

QA

  • Tested in provided StackBlitz sandbox/Storybook
  • Add new Playwright test coverage if required
  • Carbon implementation matches Design System/designs
  • UI Tests GitHub check reviewed if required

Additional context

Testing instructions

const isClickTriggeredBySelect = useRef(false);
const isMouseDownReported = useRef(false);
const isMouseDownOnInput = useRef(false);
const isOpenedByFocus = useRef(false);
const [isOpenedByFocus, setIsOpenedByFocus] = useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

question(non-blocking): What has been the thinking in moving this from ref to state? Did you discover an issue or something else when writing the new tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the changes have improved the code, but I'm not convinced we needed to do this at this time as we are just trying to get this refactored to RTL and all the Selects are being rewritten anyway

const isClickTriggeredBySelect = useRef(false);
const isMouseDownReported = useRef(false);
const isMouseDownOnInput = useRef(false);
const isOpenedByFocus = useRef(false);
const [isOpenedByFocus, setIsOpenedByFocus] = useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the changes have improved the code, but I'm not convinced we needed to do this at this time as we are just trying to get this refactored to RTL and all the Selects are being rewritten anyway

jest.restoreAllMocks();
});

test("displays input field", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

comment: I'm not sure we get much value from this test as we can imply it's presence/visibility from the other tests that query/assert against it

);
});

it("closes when input is clicked twice", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (non-blocking): might be worth doing the same test for the input icon

expect(screen.getByRole("combobox")).toHaveValue("");
});

test("clears the input after an option is selected", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

question: won't the input always have an empty value as nothing has been typed here?

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

Successfully merging this pull request may close these issues.

3 participants