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

feat: add userEvent.copy and userEvent.cut #787

Merged
merged 2 commits into from
Nov 17, 2021
Merged

feat: add userEvent.copy and userEvent.cut #787

merged 2 commits into from
Nov 17, 2021

Conversation

ph-fritsche
Copy link
Member

@ph-fritsche ph-fritsche commented Nov 17, 2021

What:

Add APIs:

  • userEvent.copy(options): Copy current selection
  • userEvent.cut(options): Copy current selection and remove from DOM if in editable context

Return:
DataTransfer with the copied contents

options:

  • writeToClipboard: If set to true, writes contents to Clipboard API and returns Promise<DataTransfer>
  • document: Used instead of global.document.

Why:

With these our users can test workflows with copy&paste.

How:

The implementation in #785 allowed to implement these on top of it.

Checklist:

  • Documentation
  • Tests
  • Ready to be merged

Additional information

userEvent.setup().copy() (and cut) should default to using the Clipboard API.
Overloading these now is not worth it, as we can change the default value for writeToClipboardData during alpha when we resolved #504.

@ph-fritsche ph-fritsche added this to the userEvent v14 milestone Nov 17, 2021
@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 17, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit f3709fb:

Sandbox Source
userEvent-PR-template Configuration

@codecov
Copy link

codecov bot commented Nov 17, 2021

Codecov Report

Merging #787 (f3709fb) into alpha (8b6cd1d) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             alpha      #787   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           68        71    +3     
  Lines         1539      1603   +64     
  Branches       580       602   +22     
=========================================
+ Hits          1539      1603   +64     
Impacted Files Coverage Δ
src/clipboard/copy.ts 100.00% <100.00%> (ø)
src/clipboard/cut.ts 100.00% <100.00%> (ø)
src/clipboard/paste.ts 100.00% <100.00%> (ø)
src/setup.ts 100.00% <100.00%> (ø)
src/utils/dataTransfer/Clipboard.ts 100.00% <100.00%> (ø)
src/utils/dataTransfer/DataTransfer.ts 100.00% <100.00%> (ø)
src/utils/focus/copySelection.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b6cd1d...f3709fb. Read the comment docs.

@ph-fritsche ph-fritsche merged commit b754dd4 into alpha Nov 17, 2021
@ph-fritsche ph-fritsche deleted the feat-copy branch November 17, 2021 14:10
@github-actions
Copy link

🎉 This PR is included in version 14.0.0-alpha.14 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

1 participant