Skip to content

Commit

Permalink
Improve nested code
Browse files Browse the repository at this point in the history
  • Loading branch information
MiraGeowerkstatt committed Dec 17, 2024
1 parent 9a0ffd7 commit 6b5af50
Showing 1 changed file with 48 additions and 49 deletions.
97 changes: 48 additions & 49 deletions src/client/cypress/e2e/mainPage/export.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,63 +261,62 @@ describe("Test for exporting boreholes.", () => {

cy.get("@borehole_id").then(id => {
goToRouteAndAcceptTerms(`/${id}`);
startBoreholeEditing();

// set two custom identifiers
addItem("addIdentifier");
setSelect("boreholeCodelists.0.codelistId", 1);
setInput("boreholeCodelists.0.value", "w1");
});
startBoreholeEditing();

addItem("addIdentifier");
setSelect("boreholeCodelists.1.codelistId", 2);
setInput("boreholeCodelists.1.value", "w2");
// set two custom identifiers
addItem("addIdentifier");
setSelect("boreholeCodelists.0.codelistId", 1);
setInput("boreholeCodelists.0.value", "w1");

// add coordinates
cy.get('[data-cy="locationX-formCoordinate"] input').type("2646000 ");
cy.get('[data-cy="locationY-formCoordinate"] input').type("1247000 ");
cy.wait("@location");
cy.wait(4000);
saveWithSaveBar();
addItem("addIdentifier");
setSelect("boreholeCodelists.1.codelistId", 2);
setInput("boreholeCodelists.1.value", "w2");

// add coordinates
cy.get('[data-cy="locationX-formCoordinate"] input').type("2646000 ");
cy.get('[data-cy="locationY-formCoordinate"] input').type("1247000 ");
cy.wait("@location");
cy.wait(4000);
saveWithSaveBar();

exportItem();
exportCSVItem();
exportItem();
exportCSVItem();

const downloadedFilePath = prepareDownloadPath(`${boreholeName}.csv`);
cy.readFile(downloadedFilePath).should("exist");

returnToOverview();
showTableAndWaitForData();
checkRowWithText(boreholeName);
deleteItem();
handlePrompt("Do you really want to delete this borehole? This cannot be undone.", "Delete");
getElementByDataCy("import-borehole-button").click();
cy.contains(boreholeName).should("not.exist");

cy.readFile(downloadedFilePath, "utf-8").then(fileContent => {
// Create a DataTransfer and a File from the downloaded content
const boreholeFile = new DataTransfer();
const file = new File([fileContent], "AAA_WALRUS.csv", {
type: "text/csv",
});
boreholeFile.items.add(file);
const downloadedFilePath = prepareDownloadPath(`${boreholeName}.csv`);
cy.readFile(downloadedFilePath).should("exist");

cy.get('[data-cy="import-boreholeFile-input"]').within(() => {
cy.get("input[type=file]", { force: true }).then(input => {
input[0].files = boreholeFile.files; // Attach the file
input[0].dispatchEvent(new Event("change", { bubbles: true }));
});
});
returnToOverview();
showTableAndWaitForData();
checkRowWithText(boreholeName);
deleteItem();
handlePrompt("Do you really want to delete this borehole? This cannot be undone.", "Delete");
getElementByDataCy("import-borehole-button").click();
cy.contains(boreholeName).should("not.exist");

cy.get('[data-cy="import-button"]').click();
cy.wait("@borehole-upload");
cy.readFile(downloadedFilePath, "utf-8").then(fileContent => {
// Create a DataTransfer and a File from the downloaded content
const boreholeFile = new DataTransfer();
const file = new File([fileContent], `${boreholeName}.csv`, {
type: "text/csv",
});
boreholeFile.items.add(file);

clickOnRowWithText(boreholeName);
evaluateInput("name", boreholeName);
evaluateInput("boreholeCodelists.1.value", "w1");
evaluateInput("boreholeCodelists.0.value", "w2");
cy.get('[data-cy="locationX-formCoordinate"] input').should("have.value", `2'646'000`);
cy.get('[data-cy="locationY-formCoordinate"] input').should("have.value", `1'247'000`);
cy.get('[data-cy="import-boreholeFile-input"]').within(() => {
cy.get("input[type=file]", { force: true }).then(input => {
input[0].files = boreholeFile.files; // Attach the file
input[0].dispatchEvent(new Event("change", { bubbles: true }));
});
});
cy.get('[data-cy="import-button"]').click();
cy.wait("@borehole-upload");
});

clickOnRowWithText(boreholeName);
evaluateInput("name", boreholeName);
evaluateInput("boreholeCodelists.1.value", "w1");
evaluateInput("boreholeCodelists.0.value", "w2");
cy.get('[data-cy="locationX-formCoordinate"] input').should("have.value", `2'646'000`);
cy.get('[data-cy="locationY-formCoordinate"] input').should("have.value", `1'247'000`);
});
});

0 comments on commit 6b5af50

Please sign in to comment.