mirror of https://github.com/grafana/grafana
Plugins: Mock Icon component to prevent console errors (#39901)
* feat(grafana-ui): externalise react-inlinesvg for mocking * feat(grafana-toolkit): mock react-inlinesvg to prevent svg fetch errors in tests * test(toolkit): remove assertion on array length of moduleNameMapper overrides * feat(toolkit): set testId to match the Icon name prop in react-inlinesvg mockpull/39913/head
parent
a17e38f638
commit
cc7f7e30e9
@ -0,0 +1,25 @@ |
||||
// Due to the grafana/ui Icon component making fetch requests to
|
||||
// `/public/img/icon/<icon_name>.svg` we need to mock react-inlinesvg to prevent
|
||||
// the failed fetch requests from displaying errors in console.
|
||||
|
||||
import React from 'react'; |
||||
|
||||
type Callback = (...args: any[]) => void; |
||||
|
||||
export interface StorageItem { |
||||
content: string; |
||||
queue: Callback[]; |
||||
status: string; |
||||
} |
||||
|
||||
export const cacheStore: { [key: string]: StorageItem } = Object.create(null); |
||||
|
||||
const SVG_FILE_NAME_REGEX = /(.+)\/(.+)\.svg$/; |
||||
|
||||
const InlineSVG = ({ src }: { src: string }) => { |
||||
// testId will be the file name without extension (e.g. `public/img/icons/angle-double-down.svg` -> `angle-double-down`)
|
||||
const testId = src.replace(SVG_FILE_NAME_REGEX, '$2'); |
||||
return <svg xmlns="http://www.w3.org/2000/svg" data-testid={testId} viewBox="0 0 24 24" />; |
||||
}; |
||||
|
||||
export default InlineSVG; |
Loading…
Reference in new issue