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

tests(storybook): adding selection commands for text #313

Closed
wants to merge 5 commits into from

Conversation

Cronus1007
Copy link
Contributor

Stale PR for discussion

Related Issues

Author Checklist

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to master from fork:branchname
  • Manual accessibility test performed
    • Keyboard-only access, including forms
    • Contrast at least WCAG Level A
    • Appropriate labels, alt text, and instructions

@Cronus1007 Cronus1007 changed the title Issue 120 tests(storybook): adding selection commands for text Mar 23, 2021
@Cronus1007
Copy link
Contributor Author

Cronus1007 commented Mar 23, 2021

@irmerk @mttrbrts @DianaLease The biggest problem here is referring to Text Node. I used createTreeWalker to refer to text Node but it is not working as I suppose it to work.

@Cronus1007 Cronus1007 marked this pull request as draft March 23, 2021 14:31
@Cronus1007 Cronus1007 marked this pull request as ready for review March 23, 2021 17:20
@mttrbrts
Copy link
Member

Thanks @Cronus1007 we're in the process of migrating the CI pipeline which affects how these tests are run. Please be patient while we complete this work.

I used createTreeWalker to refer to text Node but it is not working as I suppose it to work.

Can you describe the issue in some more detail, please?

@Cronus1007
Copy link
Contributor Author

@mttrbrts Since cypress doesn't have any api to provide selection of text required in the e2e testing of web-components library. So here I have written commands to select the text but the problem that arises here that I am unable to detect Text Node. It is easy to detect Image Nodes like this

const [imageNode] = Editor.nodes(editor, { match: n => n.type === 'image' });

We need a similair way to detect Text Nodes as well in Slate .

@mttrbrts
Copy link
Member

mttrbrts commented Mar 24, 2021

@mttrbrts Since cypress doesn't have any api to provide selection of text required in the e2e testing of web-components library. So here I have written commands to select the text but the problem that arises here that I am unable to detect Text Node. It is easy to detect Image Nodes like this

const [imageNode] = Editor.nodes(editor, { match: n => n.type === 'image' });

We need a similair way to detect Text Nodes as well in Slate .

Got it, thanks @Cronus1007. I'll review and get back to you. Unless @dselman @irmerk or @DianaLease has an immediate solution?

Copy link
Member

@sanketshevkar sanketshevkar left a comment

Choose a reason for hiding this comment

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

@Cronus1007 can you describe the role of getTextNodeNode function and createTreeWalker function?

@Cronus1007
Copy link
Contributor Author

@sanketshevkar

  • Since Slate document is a nested and recursive structure so the first data structure that comes to mind is tree and for representing a text A Text Node must be there so it is important to getTextNode and should be the root node.
  • Second createTreeWalker is a function which gets this node and parses the text from beginning node to the end node.

@sanketshevkar
Copy link
Member

@Cronus1007
While testing I found out that el in the getTextNode function stores the whole body as an object within the storybook iframe instead of just the text node object that you want to select. Is this the same behaviour you are expecting?

@Cronus1007
Copy link
Contributor Author

@sanketshevkar Here createTreeWalker function requires their first argument as node.But the $el refers to the text so it is required to convert the text into node.

@jolanglinais
Copy link
Member

Unsure if I'm following, but @Cronus1007 Slate has a number of built in API to identify text. There are some examples throughout the code here in web-components of us using this to look at the text value or attributes.

Comment on lines +27 to +39
Cypress.Commands.add('selection', { prevSubject: true }, (subject, fn) => {
cy.wrap(subject)
.trigger('mousedown')
.then(fn)
.trigger('mouseup');

cy.document().trigger('selectionchange');
return cy.wrap(subject);
});

Cypress.Commands.add('setSelection', { prevSubject: true }, (subject, query, endQuery) => {
return cy.wrap(subject)
.selection($el => {
Copy link
Contributor Author

@Cronus1007 Cronus1007 Apr 2, 2021

Choose a reason for hiding this comment

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

@irmerk Yes you are on the right path.Here the $el should identify the text as node although I have wrapped a node here in selection custom command.But still it is taking up the text rather than the element.
Here I want to refer to this as well since Slate follows nested and recursive structure but still it is unable to capture node.A problem may be there in selection Custom Command.
Plus @sanketshevkar PR #311 would also fail until we found a way to select the text.

Copy link
Member

@sanketshevkar sanketshevkar Apr 2, 2021

Choose a reason for hiding this comment

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

#311 does not require the text to be selected, its about placing the cursor in a para and then changing the headings.

Copy link
Member

Choose a reason for hiding this comment

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

I think I'm not following after all. Why do we need these custom commands when Slate has built in functions for this?

Copy link
Contributor Author

@Cronus1007 Cronus1007 Apr 6, 2021

Choose a reason for hiding this comment

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

@irmerk I guess you are not on the right track.Since slate has no connection with the selection of text.The Cypress automates that work which a user has to do.The selection of text must be done by Cypress.

@jolanglinais
Copy link
Member

I am still unfamiliar with Cypress. This PR would need help from @dselman @mttrbrts @rkotangoor

@Cronus1007 Cronus1007 closed this May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants