ni / nimble

The NI Nimble Design System
https://nimble.ni.dev
MIT License
29 stars 9 forks source link

Rich test editor | Fix intermittent tests on mention nodes #2200

Closed vivinkrishna-ni closed 1 week ago

vivinkrishna-ni commented 2 weeks ago

Pull Request

🤨 Rationale

Fixes #2150

👩‍💻 Implementation

The tests that are mentioned in the above issue are failing intermittently because there was an error within the Tiptap code in extension-mention package where the collapseToEnd() is failed to execute. This is because the window.getSelection() returns like there is no selection in the editor. Due to this error is thrown, the tests were failing intermittently.

As mentioned, the getSelection() returns like there is no selection in the editor because the editor is not focused when inserting content via Tiptap's insertContent method from the page object. So when committing a mention node by clicking or using the keyboard to select an option from the mention popup, this error throws. This is identified by having a breakpoint at the line in mention.ts where the tests were failing all the time.

However, in the UI, after adding the @ character and selecting the option from the mention-listbox either using the mouse or keyboard, it works as expected. So in the tests to resolve this intermittent failure, I have focused the editor after the content is inserted so that the selection returns the expected value and does not throw any error just like from the storybook it works.

🧪 Testing

  1. Manually verified by running the tests in a loop locally.
  2. Manually verified by running tests individually and by having a breakpoint at the Tiptap’s mention.ts.
  3. Running the tests a couple of times in the pipeline to verify whether it's intermittent in the actual pipeline.

✅ Checklist

vivinkrishna-ni commented 2 weeks ago

@m-akinc Could you please buddy review this PR?