Skip to content

Commit

Permalink
ui: add e2e test for save/publish draft validation
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Garcia Garcia <miguel.garcia.garcia@cern.ch>
  • Loading branch information
miguelgrc committed Jul 19, 2024
1 parent 600accb commit 3e3d5fd
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ui/cap-react/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { defineConfig } = require("cypress");
import { defineConfig } from "cypress";

module.exports = defineConfig({
export default defineConfig({
projectId: "4mpnou",
video: false,
downloadsFolder: "cypress/downloads",
Expand Down
19 changes: 19 additions & 0 deletions ui/cap-react/cypress/e2e/drafts/create_draft_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,23 @@ describe("Create Draft", function () {

cy.url().should("not.include", DRAFTS);
});

it("Save a draft with an empty required field", () => {
cy.loginUrl("info@inveniosoftware.org", "infoinfo");

// navigate to the draft
cy.get("[data-cy=DraftDocuments-list] a").first().click();

// navigate to edit tab
cy.get("[data-cy=itemNavEdit]").click();

// type in a normal field but leave the required field empty
cy.get("textarea#root\\!basic_info\\!abstract").type("whatever");

// save the draft
cy.get("[data-cy=draft-save-btn]").click();

// validate save
cy.get("div.ant-notification-notice-message").contains("Draft saved");
});
});
60 changes: 59 additions & 1 deletion ui/cap-react/cypress/e2e/published/published_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ describe("Published Tests", function () {

cy.get("[data-cy=DraftDocuments-list] a").first().click();

// navigate to edit tab
cy.get("[data-cy=itemNavEdit]").click();

// fill in the required field
cy.get("input#root\\!basic_info\\!cadi_id").type("JME-10-107");

//save the draft
cy.get("[data-cy=draft-save-btn]").click();

// navigate to settings tab
cy.get("[data-cy=itemNavSettings]").click();

Expand Down Expand Up @@ -45,6 +54,55 @@ describe("Published Tests", function () {

cy.get("[data-cy=changeToDraftButton]").click();

cy.get("[ data-cy=sidebarStatus]").contains("draft");
cy.get("[data-cy=sidebarStatus]").contains("draft");
});

it("Does not allow publishing a draft with an empty required field", () => {
cy.createDraft("CMS Analysis", "empty-required", "cms");

cy.visit("/");

cy.get("[data-cy=DraftDocuments-list] a").first().click();

// 1. Check that the validation works without modifying the form data

// navigate to settings tab
cy.get("[data-cy=itemNavSettings]").click();

// click publish button
cy.get("[data-cy=draftSettingsRecidButton]").click();

// confirm publish action
cy.get("[data-cy=draftSettingsPublish]").click();

// verify that it throws an error
cy.get("div.ant-notification-notice-message").contains(
"Validation Error while publishing"
);

// 2. Check the that the validation works after modifying the form data

// navigate to edit tab
cy.get("[data-cy=itemNavEdit]").click();

// type in a normal field but leave the required field empty
cy.get("textarea#root\\!basic_info\\!abstract").type("asd");

// save the draft
cy.get("[data-cy=draft-save-btn]").click();

// navigate to settings tab
cy.get("[data-cy=itemNavSettings]").click();

// click publish button
cy.get("[data-cy=draftSettingsRecidButton]").click();

// confirm publish action
cy.get("[data-cy=draftSettingsPublish]").click();

// verify that it throws an error
cy.get("div.ant-notification-notice-message").contains(
"Validation Error while publishing"
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ const NavMenu = ({ match, history, formErrors }) => {
},
{
key: "edit",
label: <Link to={`/drafts/${match.params.draft_id}/edit`}>Edit</Link>,
label: (
<Link
data-cy="itemNavEdit"
to={`/drafts/${match.params.draft_id}/edit`}
>
Edit
</Link>
),
icon: <TagOutlined />,
danger: formErrors && formErrors.size > 0,
},
Expand Down
1 change: 1 addition & 0 deletions ui/cap-react/src/antd/drafts/components/Editor/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ const Header = ({
disabled={mode != "edit" || !canEdit(canAdmin, canUpdate)}
loading={loading}
onClick={_saveData}
data-cy="draft-save-btn"
>
Save
</Button>
Expand Down

0 comments on commit 3e3d5fd

Please sign in to comment.