Files
swagger-ui/test/unit/components/highlight-code.jsx
kyy f464ba2d31
Some checks failed
Node.js CI / build (push) Failing after 2s
Node.js CI / e2e-tests (+(a11y|security|bugs)/**/*cy.js) (push) Failing after 2s
Node.js CI / e2e-tests (features/**/!(o|d|m)*.cy.js) (push) Failing after 2s
Node.js CI / e2e-tests (features/**/+(o|d)*.cy.js) (push) Failing after 2s
Node.js CI / e2e-tests (features/**/m*.cy.js) (push) Failing after 2s
CodeQL / Analyze (javascript) (push) Failing after 2m49s
Security scan for docker image / build (push) Failing after 54s
Update swagger-ui
2025-06-24 13:40:26 +09:00

44 lines
1.6 KiB
JavaScript
Executable File

import React from "react"
import expect from "expect"
import { shallow, mount } from "enzyme"
import HighlightCode from "core/plugins/syntax-highlighting/components/HighlightCode"
import SyntaxHighlighter from "core/plugins/syntax-highlighting/components/SyntaxHighlighter"
const fakeGetConfigs = () => ({ syntaxHighlight: { activated: true, theme: "agate" }})
const fakeGetComponent = (name, isContainer) => {
const components = { HighlightCode, SyntaxHighlighter }
const Component = components[name]
if (isContainer) {
return ({ ...props }) => {
return <Component getConfigs={fakeGetConfigs} getComponent={fakeGetComponent} {...props} />
}
}
return Component
}
describe("<HighlightCode />", () => {
it("should render a Download button if downloadable", () => {
const props = { downloadable: true, getConfigs: fakeGetConfigs, getComponent: fakeGetComponent }
const wrapper = shallow(<HighlightCode {...props} />)
expect(wrapper.find(".download-contents").length).toEqual(1)
})
it("should render a Copy To Clipboard button if copyable", () => {
const props = { canCopy: true, getConfigs: fakeGetConfigs, getComponent: fakeGetComponent }
const wrapper = shallow(<HighlightCode {...props} />)
expect(wrapper.find("CopyToClipboard").length).toEqual(1)
})
it("should render values in a preformatted element", () => {
const value = "test text"
const props = { children: value , getConfigs: fakeGetConfigs, getComponent: fakeGetComponent }
const wrapper = mount(<HighlightCode {...props} />)
const preTag = wrapper.find("pre")
expect(preTag.length).toEqual(1)
expect(preTag.text()).toEqual(value)
})
})