Skip to content

Commit

Permalink
Adding batches 3 and 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Asmaloth committed Oct 29, 2023
1 parent 9013c2c commit 0b621cb
Show file tree
Hide file tree
Showing 25 changed files with 1,640 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
import uniqid from "uniqid";

/**
* Sometimes file details drawer gets hidden due the race condition in "showFileDetails" and "hideFileDetails" dispatch-actions.
* That's why we make sure the drawer in visible.
*/
const openFileDetails = index => {
cy.waitUntil(
() =>
cy
.findByTestId("fm-list-wrapper")
.within(() => {
cy.findAllByTestId("fm-list-wrapper-file")
.eq(index)
.within(() => {
cy.findByTestId("fm-file-wrapper-file-info-icon").click({
force: true
});
});
})
.then(() =>
cy.findByTestId("fm.file-details.drawer").then($el => {
const [aside] = $el;
return aside.classList.contains("mdc-drawer--open");
})
),
{
description: `Wait until "File Details" model is visible`
}
);
};

const deleteFile = () => {
openFileDetails(0);
// Delete file
cy.findByTestId("fm-delete-file-button").click();
cy.findByTestId("fm-delete-file-confirmation-dialog").within(() => {
cy.findByText("Confirm").click();
});
cy.findByText("File deleted successfully.");

cy.waitUntil(
() =>
cy.findByTestId("fm.file-details.drawer").then($el => {
const [aside] = $el;
return !aside.classList.contains("mdc-drawer--open");
}),
{
description: "wait until file details is hidden"
}
);
};

const updateFileName = newName => {
// Edit the name and save it
cy.findByTestId("fm.file-details.drawer").within(() => {
cy.findByPlaceholderText("Enter name").clear().type(newName).blur();
});
cy.findByText("Name successfully updated.").should("exist");
// Exit file details view
cy.get("body").click();

cy.waitUntil(
() =>
cy.findByTestId("fm.file-details.drawer").then($el => {
const [aside] = $el;
return !aside.classList.contains("mdc-drawer--open");
}),
{
description: "wait until file details is hidden"
}
);
};

const addTagsToFile = (tags, map) => {
// Edit tag and save it
cy.findByTestId("fm.file-details.drawer").within(() => {
// Save name value for later
cy.findByPlaceholderText(/Enter name/i).then($input => {
tags.forEach(tag => {
map[tag] = $input.attr("value");
});
});

cy.findByText(/Add tags.../i).click();
// Add tags
tags.forEach(tag => {
cy.findByPlaceholderText(/homepage asset/i)
.clear()
.type(tag);
cy.wait(1000);
cy.findByText(tag).click();
});
// Save changes
cy.findByTestId("fm.tags.submit").click();
});
// Verify success message
cy.findByText("Tags successfully updated.").should("exist");
// Exit file details view
cy.get("body").click();
// Check tags in list
cy.findByTestId("fm.left-drawer.tag-list").within(() => {
tags.forEach(tag => {
cy.findByText(tag).should("exist");
});
});
cy.waitUntil(
() =>
cy.findByTestId("fm.file-details.drawer").then($el => {
const [aside] = $el;
return !aside.classList.contains("mdc-drawer--open");
}),
{
description: "wait until file details is hidden"
}
);
};

context("File Manager - Update file details", () => {
const files = [
{ fileName: "sample.jpeg", type: "image/jpeg" },
{ fileName: "sample_2.jpeg", type: "image/jpeg" }
];

beforeEach(() => {
cy.login();
cy.visit("/");
// Open drawer
cy.findByTestId("apps-menu").click();
// Open "File Manage" view
cy.findByTestId("admin-drawer-footer-menu-file-manager").click();

// Check if there are existing file and delete them
cy.fmListFiles({}).then(files => {
for (let i = 0; i < files.length; i++) {
deleteFile();
}
});
// Add files
files.forEach(({ fileName, type }) => {
cy.findByTestId("fm-list-wrapper").dropFile(fileName, type);
});
cy.findByText("File upload complete.").should("exist");
// All files should be there
cy.findByTestId("fm-list-wrapper").within(() => {
cy.findAllByTestId("fm-list-wrapper-file").should("have.length", files.length);
});
});

// TODO - fix this test
it.skip("should update file's name and search by name", () => {
// Edit files name one by one
const newFileName1 = uniqid("File ");
const newFileName2 = uniqid("File ");

// Select a file and open its details
openFileDetails(0);

updateFileName(newFileName1);

// Check file name is there in the list
cy.findByTestId("fm-list-wrapper").within(() => {
cy.findAllByTestId("fm-list-wrapper-file")
.first()
.within(() => {
cy.findByText(newFileName1).should("exist");
});
});

// Select a file and open its details
openFileDetails(1);
updateFileName(newFileName2);
// Check file name is there in the list
cy.findByTestId("fm-list-wrapper").within(() => {
cy.findAllByTestId("fm-list-wrapper-file")
.first()
.next()
.within(() => {
cy.findByText(newFileName2).should("exist");
});
});
/**
* The search input is not responding to the first couple of clicks(interactions) while running the Cypress test.
* So, at the moment we forcefully "awake" the sleeping input element before continuing with the search.
*/

cy.get(`[data-testid="file-manager.search-input"]`).as("search-input");
cy.get("@search-input").dblclick();
cy.get("@search-input").dblclick();
cy.get("@search-input").should("be.focused");

// Search files by name
cy.get("@search-input").type(newFileName1);
cy.get(".react-spinner-material").should("not.exist");
// File should be in list
cy.findByTestId("fm-list-wrapper").within(() => {
cy.findByText(newFileName1).should("exist");
});
cy.get("@search-input").clear().type(newFileName2);
cy.get(".react-spinner-material").should("not.exist");
// File should be in list
cy.findByTestId("fm-list-wrapper").within(() => {
cy.findByText(newFileName2).should("exist");
});

// Clear search
cy.get("@search-input").clear();
});

// TODO - fix this test
it.skip("should add tags, search and by tags", () => {
// Add tags one by one
const tagNew = "new";
const tagOld = "old";
const tagCommon = "common";

const map = {};

openFileDetails(0);
// Add tags to first file
addTagsToFile([tagNew, tagCommon], map);
/**
* Make sure tags are indexed in elastic search before continue.
*/
cy.waitUntil(() => cy.fmListTags().then(tags => tags.length === 2), {
description: `Wait until tags are indexed`,
timeout: 2000,
interval: 2000
});

openFileDetails(1);
// Add tags to second file
addTagsToFile([tagOld, tagCommon], map);
/**
* Make sure tags are indexed in elastic search before continue.
*/
cy.waitUntil(() => cy.fmListTags().then(tags => tags.length === 3), {
description: `Wait until tags are indexed`,
timeout: 2000,
interval: 2000
});

/**
* The search input is not responding to the first couple of clicks(interactions) while running the Cypress test.
* So, at the moment we forcefully "awake" the sleeping input element before continuing with the search.
*/
cy.findByPlaceholderText("Search by filename or tags").as("search-input");
cy.get("@search-input").dblclick();
cy.get("@search-input").dblclick();
cy.get("@search-input").should("be.focused");

// Search files by tags
cy.get("@search-input").type(tagNew);
cy.get(".react-spinner-material").should("not.exist");
// File should be in list
cy.findByTestId("fm-list-wrapper").within(() => {
cy.findByText(map[tagNew]).should("exist");
});

cy.get("@search-input").clear().type(tagOld);
cy.get(".react-spinner-material").should("not.exist");
// File should be in list
cy.findByTestId("fm-list-wrapper").within(() => {
cy.findByText(map[tagOld]).should("exist");
});

// Search file for common tag
cy.get("@search-input").clear().type(tagCommon);
cy.get(".react-spinner-material").should("not.exist");
// Both files should be in list
cy.findByTestId("fm-list-wrapper").within(() => {
cy.findByText(map[tagOld]).should("exist");
cy.findByText(map[tagNew]).should("exist");
});

// Clear search
cy.get("@search-input").clear();
cy.get(".react-spinner-material").should("not.exist");

// Filter files by selecting a tag
cy.findByTestId("fm.left-drawer.tag-list").within(() => {
cy.findByText(tagNew).click();
});
cy.get(".react-spinner-material").should("not.exist");
// File should be in list
cy.findByTestId("fm-list-wrapper").within(() => {
cy.findByText(map[tagNew]).should("exist");
});
// Clear filter
cy.findByTestId("fm.left-drawer.tag-list").within(() => {
cy.findByText(tagNew).click();
});
});
});
99 changes: 99 additions & 0 deletions cypress-tests/cypress/e2e/admin/formBuilder/forms/createForm.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import uniqid from "uniqid";

context("Forms Creation", () => {
beforeEach(() => cy.login());

describe("Create Form", () => {
const newFormTitle = `Test form 1 ${uniqid()}`;
const newFormTitle2 = `Test form 2 ${uniqid()}`;

it("should be able to create form, rename it, publish it, create new revision and delete it", () => {
cy.visit("/form-builder/forms");

// Creating new form.
// After creating new form we should be redirected to the form editing page.
cy.findAllByTestId("new-record-button").first().click();
cy.findByTestId("fb-new-form-modal").within(() => {
cy.findByPlaceholderText("Enter a name for your new form").type(newFormTitle);
cy.findByTestId("fb.form.create").click();
});

// Check if we got redirected on form editor page.
cy.findByTestId("add-step-action", { timeout: 15000 });

// Renaming Form.
cy.findByTestId("fb-editor-form-title").click({ force: true });
cy.get(`input[value="${newFormTitle}"]`).clear().type(newFormTitle2).blur();

// Publishing form after we changed name of it.
cy.findByTestId("fb.editor.default-bar.publish").click({ force: true });
// Confirming publishing operation in the confirmation dialog.
cy.findByTestId("fb.editor.default-bar.publish-dialog").within(() => {
cy.findByTestId("confirmationdialog-confirm-action").click();
});
// Should see this text if publishing operation was successfull.
cy.findByText("Your form was published successfully!");

// Check if we have renamed form in the list of forms.
cy.findByTestId("default-data-list").within(() => {
cy.findAllByTestId("default-data-list-element")
.first()
.within(() => {
cy.findByText(newFormTitle2);
});
});

// Should open form edit page for the form with title "newFormTitle2".
cy.findByTestId("default-data-list").within(() => {
cy.findAllByTestId("default-data-list-element")
.first()
.within(() => {
cy.findByText(newFormTitle2).should("be.visible");
cy.findByTestId("edit-form-action").click({ force: true });
});
});

// Check if we got redirected on form editor page.
cy.findByTestId("add-step-action", { timeout: 15000 }).click({ force: true });

// Confirm that we have added a new step.
cy.findAllByTestId("form-step-element").should("have.length", "2");

// Publishing form after we added a new step.
cy.findByTestId("fb.editor.default-bar.publish").click({ force: true });
// Confirming publishing operation in the confirmation dialog.
cy.findByTestId("fb.editor.default-bar.publish-dialog").within(() => {
cy.findByTestId("confirmationdialog-confirm-action").click();
});
// Should see this text if publishing operation was successfull.
cy.findByText("Your form was published successfully!");

// Check that revision version is 2.
cy.findByTestId("default-data-list").within(() => {
cy.findAllByTestId("default-data-list-element")
.first()
.within(() => {
cy.findByText(newFormTitle2).should("be.visible");
cy.findByTestId("fb.form.status").within(() => {
cy.findByText("Published (v2)");
});
});
});

// Deleting form.
cy.findByTestId("default-data-list").within(() => {
cy.findAllByTestId("default-data-list-element")
.first()
.within(() => {
cy.findByTestId("delete-form-action").click({ force: true });
});
});

cy.findAllByTestId("form-deletion-confirmation-dialog", { timeout: 15000 })
.first()
.within(() => {
cy.findByTestId("confirmationdialog-confirm-action").click({ force: true });
});
});
});
});

0 comments on commit 0b621cb

Please sign in to comment.