Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e JS tests for file upload and block creation #968

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion webapp/cypress/e2e/editPage.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ describe("Edit Page", () => {
it("Add some blocks to the sample and checks unsaved warning behavior", () => {
cy.get('[data-testid="search-input"]').type("editable_sample");
cy.findByText("editable_sample").click();
cy.findByLabelText("Name").should("have.value", "This is a sample name");

cy.findByText("Add a block").click();
cy.get(".dropdown-menu").findByText("Comment").click();
Expand Down Expand Up @@ -246,4 +245,34 @@ describe("Edit Page", () => {
cy.get('[data-testid="search-input"]').type("editable_sample");
cy.get("[data-testid=sample-table] tr:nth-of-type(1) > td:nth-of-type(9)").contains(2); // 2 blocks are present
});

it("Clicks the upload buttons and checks that the modals are shown", () => {
cy.get('[data-testid="search-input"]').type("editable_sample");
cy.findByText("editable_sample").click();

cy.findByText("Upload files...").click();
cy.get(".uppy-Dashboard-AddFiles-title").should("contain.text", "Drop files here,");
cy.get(".uppy-Dashboard-AddFiles-title").should("contain.text", "browse files");
cy.get(".uppy-Dashboard-AddFiles-title").should("contain.text", "or import from:");
cy.findByLabelText("Close Modal").click();

cy.findByText("Add files from server...").click();
cy.findByText("Select files to add").should("exist");
cy.findAllByLabelText("Close").eq(1).click();
});

it("Uploads an XRD file, makes an XRD block and checks that the plot works", () => {
cy.uploadFileViaAPI("editable_sample", "example_data/XRD/example_bmb.xye");

cy.get('[data-testid="search-input"]').type("editable_sample");
cy.findByText("editable_sample").click();

cy.findByText("Add a block").click();
cy.get(".dropdown-menu").findByText("Powder XRD").click();

cy.findByText("Select a file:").should("exist");
cy.get("select.file-select-dropdown").select("example_data_XRD_example_bmb.xye");
cy.contains("label", "X axis").should("exist");
cy.contains("label", "Y axis").should("exist");
});
});
1 change: 1 addition & 0 deletions webapp/cypress/fixtures/example_data
24 changes: 24 additions & 0 deletions webapp/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,30 @@ Cypress.Commands.add("deleteSampleViaAPI", (item_id) => {
});
});

Cypress.Commands.add("uploadFileViaAPI", (itemId, path) => {
cy.log("Upload a test file via the API: " + path);
cy.fixture(path, "binary")
.then(Cypress.Blob.binaryStringToBlob)
.then((blob) => {
const formData = new FormData();
formData.append("relativePath", "null");
formData.append("name", path);
formData.append("type", "application/octet-stream");
formData.append("size", blob.size.toString());
formData.append("item_id", itemId);
formData.append("replace_file", "null");
formData.append("files[]", blob, path);

return cy.request({
method: "POST",
url: API_URL + "/upload-file/",
body: formData,
headers: { "Content-Type": "multipart/form-data" },
form: false,
});
});
});

Cypress.Commands.add("searchAndSelectItem", (search_text, selector, clickPlus = false) => {
// searches in the dropdown for the first real item with the given name, looking for a badge
// if clickPlus, then also click the add row button before looking for the search bar
Expand Down