diff --git a/tests/cypress/cypress.json b/tests/cypress/cypress.json index 740b0f01b..5ab0bdac6 100644 --- a/tests/cypress/cypress.json +++ b/tests/cypress/cypress.json @@ -6,5 +6,6 @@ "pluginsFile": "plugins/index.js", "supportFile": "support/index.js", "screenshotsFolder": "screenshots", - "videosFolder": "videos" + "videosFolder": "videos", + "modifyObstructiveCode": false } diff --git a/tests/cypress/integration/upload.js b/tests/cypress/integration/upload.js index 5cc82517f..70f5b40b0 100644 --- a/tests/cypress/integration/upload.js +++ b/tests/cypress/integration/upload.js @@ -1,8 +1,9 @@ -import {prepare_server, login, await_coreui} from "../util/util"; +import {prepare_server, login, ensure_file_unknown, await_coreui} from "../util/util"; context("Upload tests", () => { const username = "admin"; const password = "test"; + const upload = "e2e-test.gcode"; beforeEach(() => { prepare_server(); @@ -10,13 +11,16 @@ context("Upload tests", () => { // login login(username, password); + // clean up file if needed + ensure_file_unknown("local", upload); + cy.visit("/"); await_coreui(); }); it("uploads file to local via button", () => { - cy.get("[data-test-id=upload-local]").attachFile("e2e-test.gcode"); + cy.get("[data-test-id=upload-local]").attachFile(upload); cy.wait("@files"); - cy.get("[data-test-id=files-list]").contains("e2e-test.gcode"); + cy.get("[data-test-id=files-list]").contains(upload); }); }); diff --git a/tests/cypress/util/util.js b/tests/cypress/util/util.js index 346b5a6dd..81e769ad8 100644 --- a/tests/cypress/util/util.js +++ b/tests/cypress/util/util.js @@ -1,13 +1,12 @@ export const prepare_server = () => { - cy.server(); - cy.route("POST", "/api/login").as("login"); - cy.route("POST", "/api/logout").as("logout"); - cy.route("GET", "/api/settings").as("settings"); - cy.route("GET", "/api/files?recursive=true").as("files"); - cy.route("GET", "/plugin/softwareupdate/check").as("softwareupdate"); - cy.route("GET", "/plugin/pluginmanager/plugins").as("pluginmanager"); - cy.route("POST", "/api/connection").as("connectionCommand"); - cy.route("GET", "/api/connection").as("connectionDetails"); + cy.intercept("POST", "/api/login").as("login"); + cy.intercept("POST", "/api/logout").as("logout"); + cy.intercept("GET", "/api/settings").as("settings"); + cy.intercept("GET", "/api/files?recursive=true").as("files"); + cy.intercept("GET", "/plugin/softwareupdate/check").as("softwareupdate"); + cy.intercept("GET", "/plugin/pluginmanager/plugins").as("pluginmanager"); + cy.intercept("POST", "/api/connection").as("connectionCommand"); + cy.intercept("GET", "/api/connection").as("connectionDetails"); }; export const await_loginui = () => { @@ -63,3 +62,11 @@ export const disconnect = () => { } }); }; + +export const ensure_file_unknown = (location, name) => { + cy.request({ + method: "DELETE", + url: `/api/files/${location}/${name}`, + failOnStatusCode: false + }); +};