Filter $$ref from examples (#4392)
* fix(dev-server): don't open localhost in a browser * tests: refactor model-example enzyme tests to be more isolated * tests: add failing sampleFromSchema tests for $$ref keys * tests: add additional test for user-created $$ref values * fix: create deeplyStripKey; use it to filter $$refs out of examples * tests: add cases for deeplyStripKey
This commit is contained in:
@@ -21,7 +21,8 @@ import {
|
||||
createDeepLinkPath,
|
||||
escapeDeepLinkPath,
|
||||
sanitizeUrl,
|
||||
extractFileNameFromContentDispositionHeader
|
||||
extractFileNameFromContentDispositionHeader,
|
||||
deeplyStripKey
|
||||
} from "core/utils"
|
||||
import win from "core/window"
|
||||
|
||||
@@ -942,6 +943,58 @@ describe("utils", function() {
|
||||
})
|
||||
})
|
||||
|
||||
describe("deeplyStripKey", function() {
|
||||
it("should filter out a specified key", function() {
|
||||
const input = {
|
||||
$$ref: "#/this/is/my/ref",
|
||||
a: {
|
||||
$$ref: "#/this/is/my/other/ref",
|
||||
value: 12345
|
||||
}
|
||||
}
|
||||
const result = deeplyStripKey(input, "$$ref")
|
||||
expect(result).toEqual({
|
||||
a: {
|
||||
value: 12345
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it("should filter out a specified key by predicate", function() {
|
||||
const input = {
|
||||
$$ref: "#/this/is/my/ref",
|
||||
a: {
|
||||
$$ref: "#/keep/this/one",
|
||||
value: 12345
|
||||
}
|
||||
}
|
||||
const result = deeplyStripKey(input, "$$ref", (v) => v !== "#/keep/this/one")
|
||||
expect(result).toEqual({
|
||||
a: {
|
||||
value: 12345,
|
||||
$$ref: "#/keep/this/one"
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it("should only call the predicate when the key matches", function() {
|
||||
const input = {
|
||||
$$ref: "#/this/is/my/ref",
|
||||
a: {
|
||||
$$ref: "#/this/is/my/other/ref",
|
||||
value: 12345
|
||||
}
|
||||
}
|
||||
let count = 0
|
||||
|
||||
const result = deeplyStripKey(input, "$$ref", () => {
|
||||
count++
|
||||
return true
|
||||
})
|
||||
expect(count).toEqual(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe("parse and serialize search", function() {
|
||||
afterEach(function() {
|
||||
win.location.search = ""
|
||||
|
||||
Reference in New Issue
Block a user