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

ui: add e2e test for save/publish draft validation #2896

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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("[email protected]", "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
Loading