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

Allow configurable data-testid attribute on file input #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,43 @@ var quill = new Quill(editor, {
}
});
```

### Automated testing example with Cypress

You may configure a `data-testid` attribute for testing frameworks such as
[Cypress](https://cypress.io/) to find the file input and upload images.

#### Configuring the data-testid
```javascript
var quill = new Quill(editor, {
// ...
modules: {
// ...
imageUploader: {
upload: myUploadFunction,
testId: "quill-image-upload"
}
}
});
```

#### Selecting and uploading in Cypress
```javascript
it("Uploads images correctly", () => {
cy.visit("/posts/new");

// the file input should be available for selection after this point
cy.get("button.ql-image").click();

// select the file input using the data-testid attribute given in the
// configuration and upload a file to it
cy.get("input[type=file][data-testid=quill-image-upload]").selectFile(
"cypress/fixtures/my-post-header.png",
{ force: true } // may be needed for non-visible inputs
);

// Verify that your image appears. Should wait for your upload function to
// finish and insert the image into the content.
cy.get(".ql-editor img").should("exist");
});
```
2 changes: 1 addition & 1 deletion dist/demo.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading