Skip to content

Commit

Permalink
Merge branch 'main' into s3-issue#13
Browse files Browse the repository at this point in the history
Signed-off-by: Shreyas <[email protected]>
  • Loading branch information
shreyass-ranganatha authored Mar 7, 2024
2 parents 266813c + a0f665b commit 436c82f
Show file tree
Hide file tree
Showing 24 changed files with 13,807 additions and 5,703 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ dist-ssr

# Binary files
*.wasm
falco.js
falco.js

#test data
cypress/downloads
8 changes: 8 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ limitations under the License.
*/

import { defineConfig } from "cypress";
import clipboardy from "clipboardy";

export default defineConfig({
e2e: {
baseUrl: "http://localhost:5173",
setupNodeEvents(on, config) {
on("task", {
// Clipboard test plugin
getClipboard: () => {
const clipboard: string = clipboardy.readSync();
return clipboard;
},
});
// implement node event listeners here
},
},
Expand Down
87 changes: 57 additions & 30 deletions cypress/e2e/home.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ describe("Page Loading and Functionality Tests", () => {

// Check that all buttons are enabled and contain the expected text
buttons.forEach((buttonText) => {
cy.get("button")
.should("be.enabled")
.contains(buttonText);
cy.get("button").should("be.enabled").contains(buttonText);
});

// Check if the terminal contains the current date
Expand Down Expand Up @@ -80,41 +78,23 @@ describe("Page Loading and Functionality Tests", () => {
// Test: Copy the correct URL to the clipboard when 'Share' is triggered and load 'Example 1'
it("copy the correct URL to the clipboard when 'Share' is triggered and load 'Example 1'", () => {
// Define the expected URL based on your component's behavior
cy.get("button:contains('Load Examples')").click();
cy.contains("Example 1").click();

// Using the example URL generated from example 1 to verify the share functionality
const example1URL = "LQAgtghgxgTg9gLhHADgUwHYH0ZogEwCgQQo4N8BLAF0vKQAo0A3agOmoE90RKMQGqTABohGCNVHpx1AEwBKEBAogW7SgGcsYnHnwBeajACuaJSoBm%2BDtzRQAFhBj6A5BZfn8IK2wzGwAHz6AAzyhISgJgA2aEgASnogAMr2aFFRIADC5BaUAObGMBJ0%2FABilDHEIPhoGlBIACJo1HbUStQtYCjUGiDUcCC4BCAaqemkOfmFxeTeFbUgAEacIBjkwKNpGSjweUVgGlVkFDQlSAFVJDpDXspEJCQMPrkx4mBmfAKb6VjHuXlYF6YCDvDSKOAwS4kHxvD78BjfKK%2FSYAoFg5CQh7Q6xUXBQfowFafBFjJF%2FfJYXGtCGUWryRR3KEMNZtHZwKC%2BEFwr6krCLPhOWlgsIkYGLGL4JAWCBRDRoKpwYzUFBK85QiAjUkTDD%2Faa0WZAkAAdwgvRuSxWGrWGA2WrZexBAmMcucAFJnWgYJz3iAPTAsFE4Hk%2BMZKAZ3S62IHg34wxMwJAKPpXWyOVAwPgonwzCgw8nU2xc14gcmYVztdQINn%2FXnXcdK9W2HHKJA8mhk%2FWqxhPU3W2g2LgUHANDQIZwRSAdnQYDROAgoQB1ACCcQAcgBJVcAcSqlbyGiQAG17MPJBWu57hHMYhpOBpOlewDRcJTNGRmJ7OFeACoARgArAALAAbGwwTBIBAC6hBAA%3D%3D";
const expectedURL = `${Cypress.config().baseUrl}#/?code=${example1URL}`;

// Stub the clipboard.writeText method to capture the copied URL
cy.stub(navigator.clipboard, "writeText").callsFake((text) => {
// Assert that the copied URL matches the expected URL
expect(text).to.equal(expectedURL);
return Promise.resolve();
});
cy.wait(4000).get("button:contains('Share')").focus().click();
const example1URL =
"LQAgtghgxgTg9gLhHADgUwHYH0ZogEwCgQQo4N8BLAF0vKQAo0A3agOmoE90RKMQGqTABohGCNVHpx1AEwBKEBAogW7SgGcsYnHnwBeajACuaJSoBm%2BDtzRQAFhBj6A5BZfn8IK2wzGwAHz6AAzyhISgJgA2aEgASnogAMr2aFFRIADC5BaUAObGMBJ0%2FABilDHEIPhoGlBIACJo1HbUStQtYCjUGiDUcCC4BCAaqemkOfmFxeTeFbUgAEacIBjkwKNpGSjweUVgGlVkFDQlSAFVJDpDXspEJCQMPrkx4mBmfAKb6VjHuXlYF6YCDvDSKOAwS4kHxvD78BjfKK%2FSYAoFg5CQh7Q6xUXBQfowFafBFjJF%2FfJYXGtCGUWryRR3KEMNZtHZwKC%2BEFwr6krCLPhOWlgsIkYGLGL4JAWCBRDRoKpwYzUFBK85QiAjUkTDD%2Faa0WZAkAAdwgvRuSxWGrWGA2WrZexBAmMcucAFJnWgYJz3iAPTAsFE4Hk%2BMZKAZ3S62IHg34wxMwJAKPpXWyOVAwPgonwzCgw8nU2xc14gcmYVztdQINn%2FXnXcdK9W2HHKJA8mhk%2FWqxhPU3W2g2LgUHANDQIZwRSAdnQYDROAgoQB1ACCcQAcgBJVcAcSqlbyGiQAG17MPJBWu57hHMYhpOBpOlewDRcJTNGRmJ7OFeACoARgArAALAAbGwwTBIBAC6hBAA%3D%3D";
const expectedURL = `${Cypress.config().baseUrl}/#/?code=${example1URL}`;

// Trigger the 'Share' functionality by clicking the "Share" button
cy.contains("Share").click();
// Check that a success message is displayed (assuming it's shown)
cy.contains("Copied URL to clipboard").should("exist");

// Check that the correct URL is copied to the clipboard
cy.window().then((win) => {
win.navigator.clipboard.readText().then((text) => {
expect(text).to.eq(expectedURL);
});
});

// Check that a success message is displayed (assuming it's shown)
cy.contains("Copied URL to clipboard").should("exist"); // Replace with your message selector
cy.task("getClipboard").should("eq", expectedURL);
});

// Test: Import a YAML file and verify that the editor is populated with the YAML content
it("import a YAML file and verify that the editor is populated", () => {

// Wait for the button to become visible and then click it
cy.get("button:contains('Import Yaml')")
.should("be.visible")
.click();
cy.get("button:contains('Import Yaml')").should("be.visible").click();

// Upload the file
cy.get("input[type='file']").as("fileUpload");
Expand All @@ -135,4 +115,51 @@ describe("Page Loading and Functionality Tests", () => {
expect(editorText).not.to.be.empty;
});
});
});

// Test: Import a scap file and verify that the editor is populated with the scap content
it("import a Scap file and run with example", () => {
// Wait for the button to become visible and then click it
cy.get("button:contains('Upload scap and run')")
.should("be.visible")
.click();

// Upload the file
cy.get("input[accept='.scap']").as("fileUpload");
cy.fixture("example.scap").then((fileContent) => {
cy.get("@fileUpload").attachFile({
fileContent: fileContent.toString(),
fileName: "example.scap",
});
});

cy.contains("Compiling with example.scap").should("be.visible");

// Wait for the editor to load and check if it's not empty
cy.get(".monaco-editor")
.should("be.visible") // Ensure the editor is visible
.then(($editor) => {
// Get the text content of the editor and assert that it's not empty
const editorText = $editor.text();
expect(editorText).not.to.be.empty;
});
});

// Test: Run with scap example Connect_localhost.scap
it("import a Scap file and run using dropdown", () => {
// Wait for the button to become visible and then click it
cy.contains("Run with scap").click();
cy.contains("Connect_localhost.scap").click();

cy.contains("Loading example").should("be.visible");
cy.contains("Compiling with connect_localhost.scap").should("be.visible");

// Wait for the editor to load and check if it's not empty
cy.get(".monaco-editor")
.should("be.visible") // Ensure the editor is visible
.then(($editor) => {
// Get the text content of the editor and assert that it's not empty
const editorText = $editor.text();
expect(editorText).not.to.be.empty;
});
});
});
Binary file added cypress/fixtures/example.scap
Binary file not shown.
24 changes: 5 additions & 19 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
import "./commands";

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
// To prevent Cypress from terminating before tests run due to an unhandled exception on the application side
Cypress.on("uncaught:exception", (err, runnable) => {
return false;
});
37 changes: 20 additions & 17 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/assets/falco-icon-color.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,400;0,500;0,600;1,400;1,500&family=Source+Code+Pro:ital,wght@0,200;0,300;0,400;0,500;1,400&display=swap"
rel="stylesheet"
/>
<title>Falco Playground</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/assets/falco-icon-color.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,400;0,500;0,600;1,400;1,500&family=Source+Code+Pro:ital,wght@0,200;0,300;0,400;0,500;1,400&display=swap"
rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<title>Falco Playground</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>

</html>
Loading

0 comments on commit 436c82f

Please sign in to comment.