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

[REF] tests: remove mock content editable helper #5494

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

LucasLefevre
Copy link
Collaborator

@LucasLefevre LucasLefevre commented Jan 16, 2025

Description:

We have a class ContentEditableHelper which is a helper class designed
to manipulate the DOM and the selection of the composer element.

It has been mocked since the begining of o-spreadsheet, which means all the
business logic inside isn't tested at all!

It was mocked because jsdom (the lib implementing/mocking DOM for running
tests in nodejs) didn't support the Selection API at the time this project
was started.

However, the Selection API was implemented back in 2019 and we've updated
jsdom since then.

ContentEditableHelper has grown over the years and it now contains even more
business logic which is worth testing.
And it's probably meant to grow even more in the future as we add features
to the composer (as an example, see task 4471274).

This commit removes our mock and we now rely on jsdom implementation.

Caveats:

  • jsdom doesn't update the selection when arrow keys (right or left) are
    pressed. We have to manual set the selection at the right place.
  • jsdom doesn't support having the focusNode/offset before the anchorNode/offset
    (selecting multiple characters from right-to-left). Hence it can now longer
    be tested and one test had to be removed.

Task: 4491759

review checklist

  • feature is organized in plugin, or UI components
  • support of duplicate sheet (deep copy)
  • in model/core: ranges are Range object, and can be adapted (adaptRanges)
  • in model/UI: ranges are strings (to show the user)
  • undo-able commands (uses this.history.update)
  • multiuser-able commands (has inverse commands and transformations where needed)
  • new/updated/removed commands are documented
  • exportable in excel
  • translations (_t("qmsdf %s", abc))
  • unit tested
  • clean commented code
  • track breaking changes
  • doc is rebuild (npm run doc)
  • status is correct in Odoo

The goal is to re-use those functions in the test suite to easily
insert new text at the current selection (see next commit)
@robodoo
Copy link
Collaborator

robodoo commented Jan 16, 2025

Pull request status dashboard

@LucasLefevre LucasLefevre force-pushed the master-remove-content-editable-mock-lul branch 3 times, most recently from e38b25f to 999a226 Compare January 17, 2025 09:38
We have a class `ContentEditableHelper` which is a helper class designed
to manipulate the DOM and the selection of the composer element.

It has been mocked since the begining of o-spreadsheet, which means all the
business logic inside isn't tested at all!

It was mocked because jsdom (the lib implementing/mocking DOM for running
tests in nodejs) didn't support the Selection API at the time this project
was started.

However, the Selection API was implemented back in 2019 and we've updated
jsdom since then.

`ContentEditableHelper` has grown over the years and it now contains even more
business logic which is worth testing.
And it's probably meant to grow even more in the future as we add features
to the composer (as an example, see task 4471274).

This commit removes our mock and we now rely on jsdom implementation.

Caveats:
- jsdom doesn't update the selection when arrow keys (right or left) are
  pressed. We have to manual set the selection at the right place.
- jsdom doesn't support having the focusNode/offset before the anchorNode/offset
  (selecting multiple characters from right-to-left). Hence it can now longer
  be tested and one test had to be removed.

Task: 4491759
@LucasLefevre LucasLefevre force-pushed the master-remove-content-editable-mock-lul branch from 999a226 to 4e3cab2 Compare January 17, 2025 09:51
@LucasLefevre LucasLefevre changed the title Master remove content editable mock lul [REF] tests: remove mock content editable helper Jan 17, 2025
@@ -896,7 +962,7 @@ describe("composer", () => {
expect(composerStore.currentContent).toEqual("Azerty");
expect(composerStore.composerSelection).toEqual({ start: 6, end: 6 });

composerStore.changeComposerCursorSelection(6, 4);
composerStore.changeComposerCursorSelection(4, 6);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

right-to-left selection isn't supported

@@ -777,28 +850,20 @@ describe("composer", () => {
expect(composerStore.editionMode).toBe("inactive");
});

test("Select a right-to-left range with the keyboard", async () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

right-to-left selection isn't supported

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