Skip to content
Snippets Groups Projects
Commit 83514c4e authored by Sky Brewer's avatar Sky Brewer
Browse files

Reduce duplication of mocks

Also add message on data that it is mocked data
parent f9e7b4aa
No related branches found
No related tags found
No related merge requests found
Pipeline #188485 passed
/** /**
* Mock data and variants for Editor and JSONEditor testing * Mock data and variants for Editor and JSONEditor testing
*/ */
const startup = `# const startup = `# MOCK CONFIG FOR TESTING
# Require module: essioc # Require module: essioc
# #
require essioc require essioc
......
...@@ -4,7 +4,7 @@ import { ...@@ -4,7 +4,7 @@ import {
editorModes, editorModes,
editorThemes editorThemes
} from "../../components/code/Editor"; } from "../../components/code/Editor";
import { files } from "./data"; import { files } from "../../mocks/Editor/Editor";
export default { export default {
title: "Code/Editor" title: "Code/Editor"
......
...@@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react"; ...@@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
import { JSONEditor } from "../../components/code/JSONEditor"; import { JSONEditor } from "../../components/code/JSONEditor";
import { editorModes, editorThemes } from "../../components/code/Editor"; import { editorModes, editorThemes } from "../../components/code/Editor";
import { sbDisabledArg } from "../utils/common-args"; import { sbDisabledArg } from "../utils/common-args";
import { schema, invalid } from "./data"; import { schemaTwo, invalid } from "../../mocks/Editor/Editor";
export default { export default {
title: "Code/JSONEditor" title: "Code/JSONEditor"
...@@ -28,7 +28,7 @@ Validate.args = { ...@@ -28,7 +28,7 @@ Validate.args = {
showAlerts: true, showAlerts: true,
maxAlerts: 3, maxAlerts: 3,
readOnly: false, readOnly: false,
schema: schema, schema: schemaTwo,
theme: "monokai", theme: "monokai",
value: JSON.stringify(invalid, null, 2) value: JSON.stringify(invalid, null, 2)
}; };
......
const startup = `#
# Require module: essioc
#
require essioc
#
# Require module: vac_ctrl_mks946_937b
#
require vac_ctrl_mks946_937b
#
# Setting STREAM_PROTOCOL_PATH
#
epicsEnvSet(STREAM_PROTOCOL_PATH, "\${vac_ctrl_mks946_937b_DB}")
#
# Module: essioc
#
iocshLoad("\${essioc_DIR}/common_config.iocsh")
#
# Device: {{ essName }}
# Module: vac_ctrl_mks946_937b
#
iocshLoad("\${vac_ctrl_mks946_937b_DIR}/vac_ctrl_mks946_937b_moxa.iocsh", "DEVICENAME = {{ essName }}, BOARD_A_SERIAL_NUMBER = {{ boardASerialNumber }}, BOARD_B_SERIAL_NUMBER = {{ boardBSerialNumber}}, IPADDR = {{ moxaFQDN }}, PORT = {{ moxaPort }}")
{{#gauges}}
#
# Device: {{ essName }}
# Module: vac_ctrl_mks946_937b
#
iocshLoad("\${vac_ctrl_mks946_937b_DIR}/{{ type }}.iocsh", "DEVICENAME = {{ essName }}, CHANNEL = {{ channel }}, CONTROLLERNAME = {{ ../essName }}")
{{/gauges}}`;
const schemaJSON = JSON.stringify(
{
$defs: {
ESSName: { type: "string", title: "ESS Name", maxLength: 34 },
CSEntryHost: { type: "string" },
Gauge: {
type: "object",
required: ["essName", "channel", "type"],
properties: {
essName: { $ref: "#/$defs/ESSName", title: "ESS Name of Gauge" },
channel: { type: "string", title: "Channel" },
type: {
type: "string",
title: "Type of Gauge",
enum: [
"vac_gauge_mks_vgc",
"vac_gauge_mks_vgd",
"vac_gauge_mks_vgp",
"vac_mfc_mks_gv50a"
]
}
}
},
BoardSerialNumber: {
type: "string",
minLength: 10,
maxLength: 10
}
},
title: "Configure Vacuum Gauge Controller ",
type: "object",
required: [
"essName",
"moxaFQDN",
"moxaPort",
"boardASerialNumber",
"boardBSerialNumber",
"guages"
],
properties: {
essName: { $ref: "#/$defs/ESSName", title: "ESS Name of Controller" },
moxaFQDN: { $ref: "#/$defs/CSEntryHost", title: "Moxa FQDN" },
moxaPort: { type: "number", title: "Moxa Port" },
boardASerialNumber: {
$ref: "#/$defs/BoardSerialNumber",
title: "Board A Serial Number"
},
boardBSerialNumber: {
$ref: "#/$defs/BoardSerialNumber",
title: "Board B Serial Number"
},
gauges: {
title: "Gauges to Control",
type: "array",
minItems: 1,
uniqueItems: true,
items: { $ref: "#/$defs/Gauge" }
}
}
},
null,
2
);
const editorjs = `import React, { useEffect, useRef, useState } from "react";
import AceEditor from "react-ace";
// allows Ace to resolve location of modes, themes, etc
import 'ace-builds/webpack-resolver'
// enables autocomplete
import "ace-builds/src-noconflict/ext-language_tools.js";
// some meta info about modes and themes
import modeList from 'ace-builds/src-noconflict/ext-modelist'
import themeList from 'ace-builds/src-noconflict/ext-themelist';
export const editorModes = Object.keys(modeList.modesByName)
export const editorThemes = Object.keys(themeList.themesByName)
function getMode(modeName, fileName) {
return modeName ?? modeList.getModeForPath(fileName ?? "").name
}
export function Editor({ uniqueName, value = "null", mode, filename, theme, width = "100%", height = "100%", readOnly }) {
const [aceMode, setAceMode] = useState(getMode(mode, filename));
useEffect(() => {
setAceMode(getMode(mode, filename))
}, [filename, mode])
return (
<AceEditor
readOnly={readOnly}
mode={aceMode}
theme={theme}
name={uniqueName}
width={width}
height={height}
showPrintMargin={false}
value={value}
editorProps={{ $blockScrolling: true }}
wrapEnabled={true}
fontSize={16}
setOptions={{
useWorker: false,
displayIndentGuides: false,
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
enableSnippets: false,
showLineNumbers: true,
tabSize: 2
}}
/>
);
}`;
export const files = {
"startup.sh": startup,
"startup.mustache": startup,
"schema.json": schemaJSON,
"Editor.js": editorjs
};
export const schema = {
$defs: {
ESSName: { type: "string", title: "ESS Name", maxLength: 34 },
CSEntryHost: { type: "string", format: "hostname" },
Gauge: {
type: "object",
required: ["essName", "channel", "type"],
additionalProperties: false,
properties: {
essName: { $ref: "#/$defs/ESSName", title: "ESS Name of Gauge" },
channel: { type: "string", title: "Channel" },
type: {
type: "string",
title: "Type of Gauge",
enum: [
"vac_gauge_mks_vgc",
"vac_gauge_mks_vgd",
"vac_gauge_mks_vgp",
"vac_mfc_mks_gv50a"
]
}
}
},
BoardSerialNumber: {
type: "string",
minLength: 10,
maxLength: 10
}
},
title: "Configure Vacuum Gauge Controller ",
type: "object",
required: [
"essName",
"moxaFQDN",
"moxaPort",
"boardASerialNumber",
"boardBSerialNumber",
"gauges"
],
additionalProperties: false,
properties: {
essName: { $ref: "#/$defs/ESSName", title: "ESS Name of Controller" },
moxaFQDN: { $ref: "#/$defs/CSEntryHost", title: "Moxa FQDN" },
moxaPort: { type: "number", title: "Moxa Port" },
boardASerialNumber: {
$ref: "#/$defs/BoardSerialNumber",
title: "Board A Serial Number"
},
boardBSerialNumber: {
$ref: "#/$defs/BoardSerialNumber",
title: "Board B Serial Number"
},
gauges: {
title: "Gauges to Control",
type: "array",
minItems: 1,
uniqueItems: true,
items: { $ref: "#/$defs/Gauge" }
}
}
};
export const invalid = {
gauges: [
{
essName: "LEBT-010:Vac-VGP-00021",
channel: "A1",
type: "vac_gauge_mks_xyz",
d: "test"
}
],
essName: "LEBT-010:Vac-VEG-00011",
moxaFQDN: "apple.tn.esss.lu.se",
moxaPort: "4005",
boardASerialNumber: "150923104",
c: "1609141318"
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment