forked from swagger-api/swagger-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: drag and drop files into the editor (swagger-api#1660)
* Enable users to drag and drop spec files into the editor * adding some tests * Update tests to use expect, and remove sinon * Adding some documentation for the drag and drop feature * refine documentation * `spec` -> `document` * meta: increate async test timeout to 110ms in CI
- Loading branch information
1 parent
c1d3e14
commit 6a705cf
Showing
8 changed files
with
177 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,10 @@ docker run -d -p 80:8080 swagger-editor | |
|
||
You can then view the app by navigating to `http://localhost` in your browser. | ||
|
||
## Documentation | ||
|
||
* [Importing your OpenAPI document](docs/import.md) | ||
|
||
## Security contact | ||
|
||
Please disclose any security-related issues or vulnerabilities by emailing [[email protected]](mailto:[email protected]), instead of using the public issue tracker. | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Importing OpenAPI documents | ||
|
||
Swagger Editor can import your OpenAPI document, which can be formatted as JSON or YAML. | ||
|
||
### File → Import File | ||
|
||
Click **Choose File** and select import. The file you are importing has to be a valid JSON or YAML OpenAPI document. Swagger Editor will prompt you about validation errors, if any exist. | ||
|
||
### File → Import URL | ||
|
||
Paste the URL to your OpenAPI document. | ||
|
||
### Drag and Drop | ||
|
||
Simply drag and drop your OpenAPI JSON or YAML document into the Swagger Editor browser window. | ||
|
||
![Swagger Editor drag and drop demo](./drag-and-drop.gif) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import expect from "expect" | ||
|
||
describe("EditorLayout", function() { | ||
let EditorLayout | ||
|
||
// If alert isn't defined, create a dummy one, and remember to clean it up afterwards | ||
if (typeof global.alert === "undefined") { | ||
before(function () { | ||
global.alert = function() { } | ||
}) | ||
after(function () { | ||
delete global.alert | ||
}) | ||
} | ||
|
||
// Same for FileReader | ||
if (typeof global.FileReader === "undefined") { | ||
before(function () { | ||
global.FileReader = function() {} | ||
}) | ||
after(function () { | ||
delete global.FileReader | ||
}) | ||
} | ||
|
||
// Create spies for alert and FileReader, and then load the module under test. | ||
before(function () { | ||
expect.spyOn(global, "alert") | ||
expect.spyOn(global, "FileReader") | ||
EditorLayout = require("src/layout").default | ||
}) | ||
// Undo the spies afterwards | ||
after(function () { | ||
expect.restoreSpies() | ||
}) | ||
|
||
// Reset spies after each test | ||
afterEach(function () { | ||
global.alert.reset() | ||
global.FileReader.reset() | ||
}) | ||
|
||
describe("when file(s) are dropped", function() { | ||
describe("if one or more files are of an unexpected type", function() { | ||
it("should alert the user that their file(s) were rejected", () => { | ||
const editorLayout = new EditorLayout() | ||
|
||
editorLayout.onDrop([], ["rejected.file.1"]) | ||
editorLayout.onDrop([], ["rejected.file.1", "rejected.file.2"]) | ||
|
||
expect(global.alert.calls.length).toEqual(2) | ||
|
||
global.alert.calls.forEach(call => { | ||
expect(call.arguments[0]).toMatch(/^Sorry.*/) | ||
}) | ||
}) | ||
}) | ||
|
||
describe("if more than one file of an expected type is dropped", function() { | ||
it("should alert the user that their file(s) were rejected", () => { | ||
const editorLayout = new EditorLayout() | ||
|
||
editorLayout.onDrop(["accepted.file.1", "accepted.file.2"], []) | ||
expect(global.alert.calls.length).toEqual(1) | ||
expect(global.alert.calls[0].arguments[0]).toMatch(/^Sorry.*/) | ||
}) | ||
}) | ||
|
||
describe("if exactly one file of an expected type is dropped", function() { | ||
it("should call the updateSpec function passed in as props with the contents of the file", () => { | ||
const fileContents = "This is my awesome file!" | ||
const props = { | ||
specActions: { | ||
updateSpec: expect.createSpy() | ||
} | ||
} | ||
global.FileReader.andReturn({ | ||
readAsText: function () { this.onloadend() }, | ||
result: fileContents | ||
}) | ||
|
||
const editorLayout = new EditorLayout(props) | ||
|
||
editorLayout.onDrop(["accepted.file"]) | ||
|
||
expect(props.specActions.updateSpec).toHaveBeenCalledWith(fileContents) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters