fix(examples): properly update memoized value in non-schema case (#6641)
This commit is contained in:
@@ -332,14 +332,14 @@ export const inferSchema = (thing) => {
|
||||
return thing // Hopefully this will have something schema like in it... `type` for example
|
||||
}
|
||||
|
||||
export const createXMLExample = (schema, config={}, o) => {
|
||||
export const createXMLExample = (schema, config, o) => {
|
||||
const json = sampleFromSchemaGeneric(schema, config, o, true)
|
||||
if (!json) { return }
|
||||
|
||||
return XML(json, { declaration: true, indent: "\t" })
|
||||
}
|
||||
|
||||
export const sampleFromSchema = (schema, config={}, o) =>
|
||||
export const sampleFromSchema = (schema, config, o) =>
|
||||
sampleFromSchemaGeneric(schema, config, o, false)
|
||||
|
||||
export const memoizedCreateXMLExample = memoizee(createXMLExample)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { fromJS } from "immutable"
|
||||
import { createXMLExample, sampleFromSchema } from "corePlugins/samples/fn"
|
||||
import { createXMLExample, sampleFromSchema, memoizedCreateXMLExample, memoizedSampleFromSchema } from "corePlugins/samples/fn"
|
||||
|
||||
describe("sampleFromSchema", () => {
|
||||
it("handles Immutable.js objects for nested schemas", function () {
|
||||
@@ -1457,3 +1457,64 @@ describe("createXMLExample", function () {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("memoizedSampleFromSchema", () => {
|
||||
it("should sequentially update memoized overrideExample", () => {
|
||||
const definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
foo: {
|
||||
type: "string"
|
||||
}
|
||||
},
|
||||
example: {
|
||||
foo: null
|
||||
}
|
||||
}
|
||||
|
||||
const expected = {
|
||||
foo: "override"
|
||||
}
|
||||
expect(memoizedSampleFromSchema(definition, {}, expected)).toEqual(expected)
|
||||
|
||||
const updatedExpected = {
|
||||
foo: "cat"
|
||||
}
|
||||
expect(memoizedSampleFromSchema(definition, {}, updatedExpected)).toEqual(updatedExpected)
|
||||
})
|
||||
})
|
||||
|
||||
describe("memoizedCreateXMLExample", () => {
|
||||
it("should sequentially update memoized overrideExample", () => {
|
||||
const expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bar>\n\t<foo>override</foo>\n</bar>"
|
||||
|
||||
const definition = {
|
||||
type: "object",
|
||||
properties: {
|
||||
foo: {
|
||||
type: "string",
|
||||
xml: {
|
||||
name: "foo"
|
||||
}
|
||||
}
|
||||
},
|
||||
example: {
|
||||
foo: null
|
||||
},
|
||||
xml: {
|
||||
name: "bar"
|
||||
}
|
||||
}
|
||||
|
||||
const overrideExample = {
|
||||
foo: "override"
|
||||
}
|
||||
expect(memoizedCreateXMLExample(definition, {}, overrideExample)).toEqual(expected)
|
||||
|
||||
const updatedOverrideExample = {
|
||||
foo: "cat"
|
||||
}
|
||||
const updatedExpected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bar>\n\t<foo>cat</foo>\n</bar>"
|
||||
expect(memoizedCreateXMLExample(definition, {}, updatedOverrideExample)).toEqual(updatedExpected)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user