fix(config): cast configuration values into proper types (#9829)
Refs #9808
This commit is contained in:
@@ -30,21 +30,6 @@ describe("<FilterContainer/>", function(){
|
||||
expect(renderedColInsideFilter.length).toEqual(1)
|
||||
})
|
||||
|
||||
it("does not render FilterContainer if filter is null", function(){
|
||||
|
||||
// Given
|
||||
let props = {...mockedProps}
|
||||
props.layoutSelectors = {...mockedProps.specSelectors}
|
||||
props.layoutSelectors.currentFilter = function() {return null}
|
||||
|
||||
// When
|
||||
let wrapper = mount(<FilterContainer {...props}/>)
|
||||
|
||||
// Then
|
||||
const renderedColInsideFilter = wrapper.find(Col)
|
||||
expect(renderedColInsideFilter.length).toEqual(0)
|
||||
})
|
||||
|
||||
it("does not render FilterContainer if filter is false", function(){
|
||||
|
||||
// Given
|
||||
|
||||
104
test/unit/core/config/type-cast/index.js
Normal file
104
test/unit/core/config/type-cast/index.js
Normal file
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* @prettier
|
||||
*/
|
||||
import typeCast from "core/config/type-cast"
|
||||
|
||||
jest.mock("core/presets/apis", () => {})
|
||||
|
||||
describe("typeCast", () => {
|
||||
it("should cast stringified `true` and `false` values to `boolean`", () => {
|
||||
const config = {
|
||||
deepLinking: "true",
|
||||
tryItOutEnabled: "false",
|
||||
withCredentials: "true",
|
||||
filter: "false",
|
||||
}
|
||||
|
||||
const expectedConfig = {
|
||||
deepLinking: true,
|
||||
tryItOutEnabled: false,
|
||||
withCredentials: true,
|
||||
filter: false,
|
||||
}
|
||||
|
||||
expect(typeCast(config)).toStrictEqual(expectedConfig)
|
||||
})
|
||||
|
||||
it("should cast stringified `number` values to `number`", () => {
|
||||
const config = {
|
||||
defaultModelExpandDepth: "5",
|
||||
defaultModelsExpandDepth: "-1",
|
||||
maxDisplayedTags: "1",
|
||||
}
|
||||
|
||||
const expectedConfig = {
|
||||
defaultModelExpandDepth: 5,
|
||||
defaultModelsExpandDepth: -1,
|
||||
maxDisplayedTags: 1,
|
||||
}
|
||||
|
||||
expect(typeCast(config)).toStrictEqual(expectedConfig)
|
||||
})
|
||||
|
||||
it("should cast stringified `null` values to `null`", () => {
|
||||
const config = {
|
||||
validatorUrl: "null",
|
||||
}
|
||||
|
||||
const expectedConfig = {
|
||||
validatorUrl: null,
|
||||
}
|
||||
|
||||
expect(typeCast(config)).toStrictEqual(expectedConfig)
|
||||
})
|
||||
|
||||
it("should cast `string` values to `string`", () => {
|
||||
const config = { defaultModelRendering: "model", filter: "pet" }
|
||||
|
||||
const expectedConfig = { defaultModelRendering: "model", filter: "pet" }
|
||||
|
||||
expect(typeCast(config)).toStrictEqual(expectedConfig)
|
||||
})
|
||||
|
||||
it("should cast stringified values to correct type", () => {
|
||||
const config = {
|
||||
dom_id: "null",
|
||||
oauth2RedirectUrl: "undefined",
|
||||
syntaxHighlight: "false",
|
||||
urls: "null",
|
||||
}
|
||||
|
||||
const expectedConfig = {
|
||||
dom_id: null,
|
||||
oauth2RedirectUrl: undefined,
|
||||
syntaxHighlight: { activated: false },
|
||||
urls: null,
|
||||
}
|
||||
|
||||
expect(typeCast(config)).toStrictEqual(expectedConfig)
|
||||
})
|
||||
|
||||
it("should cast incorrect value types to default value", () => {
|
||||
const config = {
|
||||
deepLinking: "deepLinking",
|
||||
urls: "urls",
|
||||
syntaxHighlight: "syntaxHighlight",
|
||||
spec: "spec",
|
||||
maxDisplayedTags: "null",
|
||||
defaultModelExpandDepth: {},
|
||||
defaultModelsExpandDepth: false,
|
||||
}
|
||||
|
||||
const expectedConfig = {
|
||||
deepLinking: false,
|
||||
urls: null,
|
||||
syntaxHighlight: { activated: true, theme: "agate" },
|
||||
spec: {},
|
||||
maxDisplayedTags: -1,
|
||||
defaultModelExpandDepth: 1,
|
||||
defaultModelsExpandDepth: 1,
|
||||
}
|
||||
|
||||
expect(typeCast(config)).toStrictEqual(expectedConfig)
|
||||
})
|
||||
})
|
||||
@@ -49,44 +49,6 @@ describe("swagger-client plugin - withCredentials", () => {
|
||||
const loadedFn = loaded(oriExecute, system)
|
||||
loadedFn()
|
||||
|
||||
expect(oriExecute.mock.calls.length).toBe(1)
|
||||
expect(system.fn.fetch.withCredentials).toBe(false)
|
||||
})
|
||||
|
||||
it("should allow setting flag to true via config as string", () => {
|
||||
// for query string config
|
||||
const system = {
|
||||
fn: {
|
||||
fetch: jest.fn().mockImplementation(() => Promise.resolve())
|
||||
},
|
||||
getConfigs: () => ({
|
||||
withCredentials: "true"
|
||||
})
|
||||
}
|
||||
const oriExecute = jest.fn()
|
||||
|
||||
const loadedFn = loaded(oriExecute, system)
|
||||
loadedFn()
|
||||
|
||||
expect(oriExecute.mock.calls.length).toBe(1)
|
||||
expect(system.fn.fetch.withCredentials).toBe(true)
|
||||
})
|
||||
|
||||
it("should allow setting flag to false via config as string", () => {
|
||||
// for query string config
|
||||
const system = {
|
||||
fn: {
|
||||
fetch: jest.fn().mockImplementation(() => Promise.resolve())
|
||||
},
|
||||
getConfigs: () => ({
|
||||
withCredentials: "false"
|
||||
})
|
||||
}
|
||||
const oriExecute = jest.fn()
|
||||
|
||||
const loadedFn = loaded(oriExecute, system)
|
||||
loadedFn()
|
||||
|
||||
expect(oriExecute.mock.calls.length).toBe(1)
|
||||
expect(system.fn.fetch.withCredentials).toBe(false)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user