Files
swagger-ui/test/core/plugins/spec/actions.js
Owen Conti 91a4794ab5 Merge ft/performance (#3670)
* Updated docs for correct usage of SWAGGER_JSON

* Removed href attribute from anchor tag if deeplinking is disabled

* If deeplinking is disabled the anchor tag has no href attribute as a result the mouse pointer is not a pointer as it is no longer a hyperlink, setting the cursor explicitly to pointer.

* Refactor: use ternary operators at attribute level instead of element level

* Only polyfill Promise if it doesn't exist at all

* v3.1.7

* Typo fix

* fix #3624

* Squash commit: OAS3 Try-It-Out changes

* Parse JSON requestBodies so Client can consume them correctly

* Use Client branch

* Fix typo in swagger-client dependency

* Fix property names being displayed in array models

* Working on refactoring of model.jsx

* Fit linter and tests

* Add comment to array-model for to clarify change. Rework logic in `Model.render()` to fix bug with overriding name and schema from `$ref` definition.

* v3.2.0

* fromJS does not maintain order of object properties. Use a reviver function with fromJS inside the response.jsx component for the passed down schema prop.

* OAS3 Accept header control: Component-side

* OAS3 Accept header control: State-side

* Update response.jsx to use already existing, fromJSOrdered function

* Added test for response.jsx to make sure properties are passed to `ModelExample` component in the correct order

* Remove `it.only` from new test

* Fixes #3596

Wrap `isShownKey` values in a function that replaces spaces with underscores. When parsing the hash on route change, replace the spaces in the values with underscores again.

* Replace spaces with underscores when setting the hash value and inserting the ID into the DOM. Escape the deep link path when querying for the DOM element on hash change.

* Handle null value in createDeepLinkPath

* Add extra check for String types in `createDeepLinkPath`. Add `trim()` call on passed-in value in `createDeepLinkPath`. Added unit tests for new deep link util functions.

* LINTING!

* Roll back win import removal

Lost in merge conflict....

* More merge oversights...
2017-09-15 22:09:35 -06:00

184 lines
4.9 KiB
JavaScript

/* eslint-env mocha */
import expect, { createSpy } from "expect"
import { fromJS } from "immutable"
import { execute, executeRequest } from "corePlugins/spec/actions"
describe("spec plugin - actions", function(){
describe("execute", function(){
xit("should collect a full request and call fn.executeRequest", function(){
// Given
const system = {
fn: {
fetch: 1
},
specActions: {
executeRequest: createSpy()
},
specSelectors: {
spec: () => fromJS({spec: 1}),
parameterValues: () => fromJS({values: 2}),
contentTypeValues: () => fromJS({requestContentType: "one", responseContentType: "two"})
}
}
// When
let executeFn = execute({ path: "/one", method: "get"})
executeFn(system)
// Then
expect(system.specActions.executeRequest.calls[0].arguments[0]).toEqual({
fetch: 1,
method: "get",
pathName: "/one",
parameters: {
values: 2
},
requestContentType: "one",
responseContentType: "two",
spec: {
spec: 1
}
})
})
xit("should allow passing _extra_ properties to executeRequest", function(){
// Given
const system = {
fn: {},
specActions: {
executeRequest: createSpy()
},
specSelectors: {
spec: () => fromJS({}),
parameterValues: () => fromJS({}),
contentTypeValues: () => fromJS({})
}
}
// When
let executeFn = execute({ hi: "hello" })
executeFn(system)
// Then
expect(system.specActions.executeRequest.calls[0].arguments[0]).toInclude({hi: "hello"})
})
})
describe("executeRequest", function(){
xit("should call fn.execute with arg ", function(){
const system = {
fn: {
execute: createSpy().andReturn(Promise.resolve())
},
specActions: {
setResponse: createSpy()
}
}
// When
let executeFn = executeRequest({one: 1})
let res = executeFn(system)
// Then
expect(res).toBeA(Promise)
expect(system.fn.execute.calls.length).toEqual(1)
expect(system.fn.execute.calls[0].arguments[0]).toEqual({
one: 1
})
})
it("should pass requestInterceptor/responseInterceptor to fn.execute", function(){
// Given
let configs = {
requestInterceptor: createSpy(),
responseInterceptor: createSpy()
}
const system = {
fn: {
buildRequest: createSpy(),
execute: createSpy().andReturn(Promise.resolve())
},
specActions: {
executeRequest: createSpy(),
setMutatedRequest: createSpy(),
setRequest: createSpy()
},
specSelectors: {
spec: () => fromJS({}),
parameterValues: () => fromJS({}),
contentTypeValues: () => fromJS({}),
url: () => fromJS({}),
isOAS3: () => false
},
getConfigs: () => configs
}
// When
let executeFn = executeRequest({
pathName: "/one",
method: "GET",
operation: fromJS({operationId: "getOne"})
})
let res = executeFn(system)
// Then
expect(system.fn.execute.calls.length).toEqual(1)
expect(system.fn.execute.calls[0].arguments[0]).toIncludeKey("requestInterceptor")
expect(system.fn.execute.calls[0].arguments[0]).toInclude({
responseInterceptor: configs.responseInterceptor
})
expect(system.specActions.setMutatedRequest.calls.length).toEqual(0)
expect(system.specActions.setRequest.calls.length).toEqual(1)
let wrappedRequestInterceptor = system.fn.execute.calls[0].arguments[0].requestInterceptor
wrappedRequestInterceptor(system.fn.execute.calls[0].arguments[0])
expect(configs.requestInterceptor.calls.length).toEqual(1)
expect(system.specActions.setMutatedRequest.calls.length).toEqual(1)
expect(system.specActions.setRequest.calls.length).toEqual(1)
})
})
xit("should call specActions.setResponse, when fn.execute resolves", function(){
const response = {serverResponse: true}
const system = {
fn: {
execute: createSpy().andReturn(Promise.resolve(response))
},
specActions: {
setResponse: createSpy()
},
errActions: {
newSpecErr: createSpy()
}
}
// When
let executeFn = executeRequest({
pathName: "/one",
method: "GET"
})
let executePromise = executeFn(system)
// Then
return executePromise.then( () => {
expect(system.specActions.setResponse.calls.length).toEqual(1)
expect(system.specActions.setResponse.calls[0].arguments).toEqual([
"/one",
"GET",
response
])
})
})
it.skip("should call errActions.newErr, if the fn.execute rejects", function(){
})
})