{"version":3,"file":"Code.min.js","sources":["EncompassWebServices/includes/DashboardItemTypes/Code.js"],"sourcesContent":["\"use strict\";\r\n\r\nconst DashboardDocumentType = {\r\n 0: \"HTML\",\r\n 1: \"Javascript\",\r\n 2: \"CSS\",\r\n 3: \"ConvertedJs\",\r\n 4: \"TestScript\",\r\n 5: \"Markdown\",\r\n 6: \"CompiledJavascript\",\r\n 7: \"CompiledCss\",\r\n HTML: 0,\r\n Javascript: 1,\r\n CSS: 2,\r\n ConvertedJs: 3,\r\n TestScript: 4,\r\n Markdown: 5,\r\n CompiledJavascript: 6,\r\n CompiledCss: 7\r\n};\r\n\r\n(function () {\r\n const Deferred = function () {\r\n const deferred = {};\r\n const promise = new Promise(((resolve, reject) => {\r\n deferred.resolve = resolve;\r\n deferred.reject = reject;\r\n }));\r\n\r\n deferred.then = function (onFulfilled, onRejected) {\r\n promise.then(onFulfilled, onRejected);\r\n };\r\n\r\n return deferred;\r\n };\r\n\r\n let args;\r\n\r\n const runTestFunction = (resolve, reject) => {\r\n ECP.Dialog.ShowLoading(\"Testing......\", args.loadingCover ? args.loadingCover : \"\");\r\n\r\n const iFrames = document.querySelectorAll(\".test-code-iframe\");\r\n\r\n for (let index = 0; index < iFrames.length; index++) {\r\n document.body.removeChild(iFrames[index]);\r\n }\r\n\r\n const iframe = document.createElement(\"frame\");\r\n\r\n iframe.classList.add(\"test-code-iframe\");\r\n iframe.style.display = \"none\";\r\n iframe.style.height = \"100%\";\r\n iframe.style.width = \"100%\";\r\n\r\n iframe.onload = function () {\r\n iframe.contentWindow.onbeforeunload = function () {\r\n if (iframe.contentWindow.__coverage__ && iframe.contentWindow.ProcessTestScriptResult) {\r\n iframe.contentWindow.ProcessTestScriptResult(iframe.contentWindow.__coverage__, iframe.contentWindow.document, true);\r\n } else {\r\n clearInterval(timer);\r\n\r\n const errorDialog = ECP.Dialog.ShowDialog(\"Test Scripts Failed\", \"
Test Scripts are required to release any Dashboard with a Code Block that contains JavaScript.
`\r\n + `Test Scripts must hit a minimum of 80% Statement coverage.
`\r\n + `<script>
tag in the HTML tab<input>
tags with built-in onclick/onchange/etc. eventsdocument.querySelector
or document.getElementById
to get the element then call element.addEventListener
console.log
to see data during the test (make sure to remove once done)console.log
can only be used in the Test Script tab, it cannot be in the JavaScript tab otherwise the test won't run due to an errorEC_Fmt.TriggerEvent
to trigger specific events on elements during testing`\r\n + `assert
call`\r\n + `done
are an exceptionassert
the changes you expect those elements to havedescribe
- Function called to describe a set of test scripts`\r\n + `it
- Function called to perform a particular test`\r\n + `describe
calls but can be by themselvesassert
- Used to confirm test script values are expected`\r\n + `const assert = chai.assert;
`\r\n + `
`\r\n + `describe(\"Some Function\", () => {
`\r\n + ` it(\"will do this\", () => {
`\r\n + ` const TestData = {
`\r\n + ` Test: \"abc\"
`\r\n + ` };
`\r\n + `
`\r\n + ` const result = SomeFunction(TestData);
`\r\n + `
`\r\n + ` assert.equal(result, \"cba\", \"result should be reversed\");
`\r\n + ` });
`\r\n + `});
`\r\n + `;
`\r\n + `
JavaScript tab
`\r\n + `// At the top
`\r\n + `let TestsAreRunning = false;
`\r\n + `
`\r\n + `function Enable_Testing() {
`\r\n + ` TestsAreRunning = true;
`\r\n + `}
`\r\n + `
`\r\n + `[...]
`\r\n + `
`\r\n + `// inside a function that redirects or calls an API
`\r\n + `const myRequest = new EC_Request(\"SomeAPICommand\")
`\r\n + `
`\r\n + `if (!TestsAreRunning) {
`\r\n + ` myRequest.submit()
`\r\n + `}
`\r\n + `
Test Script tab
`\r\n + `const assert = chai.assert;
`\r\n + `
`\r\n + `before(() => {
`\r\n + ` Enable_Testing();
`\r\n + `});
`\r\n + `
`\r\n + `describe(\"Some Function\", () => {
`\r\n + ` it(\"will do this\", () => {
`\r\n + ` const TestData = {
`\r\n + ` Test: \"abc\"
`\r\n + ` };
`\r\n + `
`\r\n + ` const result = SomeFunction(TestData);
`\r\n + `
`\r\n + ` assert.equal(result, \"cba\", \"result should be reversed\");
`\r\n + ` });
`\r\n + `});
`\r\n + `
`\r\n + `
This is typically used when waiting for a UI action to occur and checking results of that action
`\r\n + `const assert = chai.assert;
`\r\n + `
`\r\n + `describe(\"Some Function\", () => {
`\r\n + ` it(\"will open a dialog\", async () => {
`\r\n + ` // FAST = slow/2
`\r\n + ` // We are waiting 1 seconds always, default is 75ms
`\r\n + ` this.slow(2075);
`\r\n + `
`\r\n + ` const TestData = {
`\r\n + ` Test: \"abc\"
`\r\n + ` };
`\r\n + `
`\r\n + ` SomeFunction(TestData);
`\r\n + `
`\r\n + ` // Wait 1 second to make sure dialog has time to popup
`\r\n + ` await delay(1000);
`\r\n + `
`\r\n + ` assert.isTrue(Dialog_IsShowing(), \"dialog should be showing\");
`\r\n + ` assert.equal(Get_OnScreen_Dialog_Title(), TestData.Test, \"dialog title should match passed in data\");
`\r\n + ` });
`\r\n + `
`\r\n + ` after(() => {
`\r\n + ` // Cleanup any open dialogs after the test
`\r\n + ` Click_CloseButton_On_ShowingDialogs();
`\r\n + ` })
`\r\n + `});
`\r\n + `
const assert = chai.assert;
`\r\n + `
`\r\n + `describe(\"Clicking the open dialog button\", () => {
`\r\n + ` it(\"will open a dialog when valid data set\", async () => {
`\r\n + ` // FAST = slow/2
`\r\n + ` // We are waiting 1 seconds always, default is 75ms
`\r\n + ` this.slow(2075);
`\r\n + `
`\r\n + ` const ValidData = {
`\r\n + ` Test: \"abc\"
`\r\n + ` };
`\r\n + `
`\r\n + ` UpdateFormData(ValidData);
`\r\n + `
`\r\n + ` EC_Fmt.TriggerEvent(document.getElementById(\"my-button\"), \"click\", { bubbles: true });
`\r\n + `
`\r\n + ` // Wait 1 second to make sure dialog has time to popup
`\r\n + ` await delay(1000);
`\r\n + `
`\r\n + ` assert.isTrue(Dialog_IsShowing(), \"dialog should be showing\");
`\r\n + ` assert.equal(Get_OnScreen_Dialog_Title(), ValidData.Test, \"dialog title should match passed in data\");
`\r\n + ` });
`\r\n + `
`\r\n + ` it(\"will not open a dialog with inputs when valid data set\", async () => {
`\r\n + ` // FAST = slow/2
`\r\n + ` // We are waiting 1 seconds always, default is 75ms
`\r\n + ` this.slow(2075);
`\r\n + `
`\r\n + ` const InvalidData;
`\r\n + `
`\r\n + ` UpdateFormData(InvalidData);
`\r\n + `
`\r\n + ` EC_Fmt.TriggerEvent(document.getElementById(\"my-button\"), \"click\", { bubbles: true });
`\r\n + `
`\r\n + ` // Wait 1 second to make sure dialog has time to popup
`\r\n + ` await delay(1000);
`\r\n + `
`\r\n + ` assert.isFalse(Dialog_IsShowing(), \"dialog should not be showing\");
`\r\n + ` assert.isTrue(document.querySelector(\"input[name=my-input]\").hasAttribute(\"error\"), \"input should be in error\");
`\r\n + ` });
`\r\n + `
`\r\n + ` after(() => {
`\r\n + ` // Cleanup any open dialogs after the test
`\r\n + ` Click_CloseButton_On_ShowingDialogs();
`\r\n + ` })
`\r\n + `});;
`\r\n + `
See Mocha's Asynchronous Code for more information about done
const assert = chai.assert;
`\r\n + `
`\r\n + `describe(\"Async Functions\", () => {
`\r\n + ` // passing in a callback
`\r\n + ` // testing will wait until done() is called
`\r\n + ` it(\"will work without failing\", (done) => {
`\r\n + ` SomeFunction((error) => {
`\r\n + ` if (error) {
`\r\n + ` done(error);
`\r\n + ` } else {
`\r\n + ` done();
`\r\n + ` }
`\r\n + ` });
`\r\n + ` });
`\r\n + `
`\r\n + ` // Asserting with a returned Promise
`\r\n + ` it(\"will return a promise with the correct results\", (done) => {
`\r\n + ` return SomeFunction().then((data) => {
`\r\n + ` assert.equal(data.value, \"1234\", \"function returns 1234\");
`\r\n + ` });
`\r\n + ` });
`\r\n + `
`\r\n + ` // Awaiting a promise
`\r\n + ` it(\"will return correct results\", async (done) => {
`\r\n + ` const Data = await SomeFunction();
`\r\n + `
`\r\n + ` assert.equal(Data.value, \"1234\", \"function returns 1234\");
`\r\n + ` });
`\r\n + `});
`\r\n + `
`\r\n + `
delay(milliseconds)
Halts execution for the specified milliseconds
milliseconds: number
Number of milliseconds to wait forfunction delay(milliseconds) {
`\r\n + ` return new Promise(res => setTimeout(res, milliseconds));
`\r\n + `};
`\r\n + `
Example
`\r\n + `// wait for 1 second
`\r\n + `await delay(1000);
`\r\n + `
Click_ConfirmButton_On_ShowingDialogs()
Click the confirm button on all showing dialogs
`\r\n + `function Click_ConfirmButton_On_ShowingDialogs() {
`\r\n + ` const dialogs = document.querySelectorAll(\".ecp-dialog\");
`\r\n + ` for (let i = 0; i < dialogs.length; ++i) {
`\r\n + ` // Find dialogs that are still showing
`\r\n + ` if (dialogs[i].style.display !== \"none\") {
`\r\n + ` EC_Fmt.TriggerEvent(dialogs[i].querySelector(\".ecp-dialog-confirm-button\"), \"click\", { bubbles: true });
`\r\n + ` }
`\r\n + ` }
`\r\n + `}
`\r\n + `
Example
`\r\n + `SomeFunctionThatOpenDialog();
`\r\n + `// wait for the dialog to show up
`\r\n + `await delay(1000);
`\r\n + `
`\r\n + `// Click confirm to test the confirm action on a dialog
`\r\n + `Click_ConfirmButton_On_ShowingDialogs();`\r\n + `
Click_CloseButton_On_ShowingDialogs()
Click the close button (top-right X button) on all showing dialogs
`\r\n + `function Click_CloseButton_On_ShowingDialogs() {
`\r\n + ` const Dialogs = document.querySelectorAll(\".ecp-dialog\");
`\r\n + `
`\r\n + ` for (let i = 0; i < Dialogs.length; ++i) {
`\r\n + ` // Find dialogs that are still showing
`\r\n + ` if (Dialogs[i].style.display !== \"none\") {
`\r\n + ` EC_Fmt.TriggerEvent(Dialogs[i].querySelector(\".ecp-dialog-close\"), \"click\", { bubbles: true });
`\r\n + ` }
`\r\n + ` }
`\r\n + `}`\r\n + `
Example
`\r\n + `// close all opened dialogs after test cases run before the next set
`\r\n + `after(() => {
`\r\n + ` // Click confirm to test the confirm action on a dialog
`\r\n + ` Click_CloseButton_On_ShowingDialogs();
`\r\n + `});`\r\n + `
Dialog_IsShowing()
Determines if there is a dialog currently displayed during tests
`\r\n + `boolean
true
if a dialog is on screen, false
if no dialog is showingfunction Dialog_IsShowing() {
`\r\n + ` const dialogs = document.querySelectorAll(\".ecp-dialog\");
`\r\n + ` for (let i = 0; i < dialogs.length; ++i) {
`\r\n + ` // Find dialogs that are still showing
`\r\n + ` if (dialogs[i].style.display !== \"none\") {
`\r\n + ` return true;
`\r\n + ` }
`\r\n + ` }
`\r\n + ` return false;
`\r\n + `}`\r\n + `
Example
`\r\n + `SomeFunctionThatOpenDialog();
`\r\n + `// wait for the dialog to show up
`\r\n + `await delay(1000);
`\r\n + `
`\r\n + `assert.isTrue(Dialog_IsShowing(), \"dialog should be showing\");`\r\n + `
Get_OnScreen_Dialog()
Gets the first showing dialog and returns the whole Element
Element
The first showing dialog element, containing header, contents, and buttons; null
otherwisefunction Get_OnScreen_Dialog() {
`\r\n + ` const dialogs = document.querySelectorAll(\".ecp-dialog\");
`\r\n + ` for (let i = 0; i < dialogs.length; ++i) {
`\r\n + ` // Find dialogs that are still showing
`\r\n + ` if (dialogs[i].style.display !== \"none\") {
`\r\n + ` return dialogs[i];
`\r\n + ` }
`\r\n + ` }
`\r\n + ` return null;
`\r\n + `}`\r\n + `
Example
`\r\n + `SomeFunctionThatOpenDialog();
`\r\n + `// wait for the dialog to show up
`\r\n + `await delay(1000);
`\r\n + `
`\r\n + `const OpenDialog = Get_OnScreen_Dialog();
`\r\n + `
`\r\n + `assert.exists(OpenDialog.querySelector(\"[name=SomeName]\"), \"dialog should be open\");`\r\n + `
Get_OnScreen_Dialog_Title()
Returns the title string of the first showing dialog
`\r\n + `string
The title of first found open dialog; \"\" (empty string) returned if no Dialog foundfunction Get_OnScreen_Dialog_Title() {
`\r\n + ` const dialogs = document.querySelectorAll(\".ecp-dialog\");
`\r\n + ` for (let i = 0; i < dialogs.length; ++i) {
`\r\n + ` // Find dialogs that are still showing
`\r\n + ` if (dialogs[i].style.display !== \"none\") {
`\r\n + ` return dialogs[i].querySelector(\".ecp-dialog-title\").innerText;
`\r\n + ` }
`\r\n + ` }
`\r\n + ` return \"\";
`\r\n + `}
`\r\n + ``\r\n + `
Example
`\r\n + `SomeFunctionThatOpenDialog();
`\r\n + `// wait for the dialog to show up
`\r\n + `await delay(1000);
`\r\n + `
`\r\n + `assert.equal(Get_OnScreen_Dialog_Title(), \"My Dialog Title\", \"title should match\");`\r\n + `
Get_OnScreen_Dialog_Content()
Returns the innerHTML string of the content of the first open dialog
`\r\n + `Used for simple dialog content checking
string
The innerHTML of the found dialogfunction Get_OnScreen_Dialog_Content() {
`\r\n + ` const dialogs = document.querySelectorAll(\".ecp-dialog\");
`\r\n + ` for (let i = 0; i < dialogs.length; ++i) {
`\r\n + ` // Find dialogs that are still showing
`\r\n + ` if (dialogs[i].style.display !== \"none\") {
`\r\n + ` return dialogs[i].querySelector(\".ecp-dialog-content div\").innerHTML;
`\r\n + ` }
`\r\n + ` }
`\r\n + ` return \"\";
`\r\n + `}`\r\n + `
Example
`\r\n + `SomeFunctionThatOpenDialog();
`\r\n + `// wait for the dialog to show up
`\r\n + `await delay(1000);
`\r\n + `
`\r\n + `assert.equal(Get_OnScreen_Dialog_Content(), \"Are you sure you want to do this action?\", \"contents should match\");`\r\n + `
`\r\n + `Type | `\r\n + `Syntax | `\r\n + `Example | `;\r\n for (let j = 0; j < section.examples.length; j++) {\r\n const example = section.examples[j];\r\n htmlB += `|
---|---|---|---|
${example.type} | `\r\n + `${example.example} | `\r\n + ``\r\n + ` |
\"\r\n + \" | Commit | \"\r\n + \"Author | \"\r\n + \"Date | \"\r\n + \"Message | \"\r\n + \"Revert | \"\r\n + \"
---|---|---|---|---|---|
`\r\n + ` | ${log.LogNUM} | `\r\n + `${author} | `\r\n + `${EC_Fmt.DateTimeParseFormat(log.Time)} | `\r\n + `${message} | `\r\n + ``\r\n + \" |