Skip to content

Commit

Permalink
Fixing multiple bugs (merge commit)
Browse files Browse the repository at this point in the history
Merge branch 'bugfix/multiple-bugs' into 'main'
* Fix allowing one object, MUI data table not showing correctly

Closes #1001, #1003, and #998
See merge request https://gitlab.ci.csc.fi/sds-dev/sd-submit/metadata-submitter-frontend/-/merge_requests/1053

Approved-by: Liisa Lado-Villar <[email protected]>
Merged by Hang Le <[email protected]>
  • Loading branch information
Hang Le committed Jan 10, 2025
2 parents e797999 + 4fc6fc1 commit 44f7ab7
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 119 deletions.
4 changes: 2 additions & 2 deletions playwright/tests/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ test.describe("Basic application flow", () => {
await formActions("form-ready")

// Test DAC form update
await page.getByTestId("dac-objects-list").filter({ hasText: "Test title" }).click()
await expect(page.getByTestId("title")).toBeVisible()
await page.getByTestId("submitted-dac-list-item").filter({ hasText: "Test title" }).click()
await expect(page.getByTestId("title")).toHaveValue("Test title")
await page.getByTestId("title").fill("Test title edited")
await expect(page.getByTestId("title")).toHaveValue("Test title edited")
await formActions("form-ready")
Expand Down
2 changes: 1 addition & 1 deletion playwright/tests/draft.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ test.describe("Draft operations", () => {
).toBeVisible()

// Submit second form draft
await continueLatestForm(ObjectTypes.policy, ObjectStatus.draft)
await page.getByTestId("draft-policy-list-item").filter({ hasText: "Test title" }).click()
await expect(page.getByTestId("policy")).toBeVisible()
await page.getByTestId("policy").selectOption({ label: "Policy Text" })
await page.getByTestId("policy.policyText").fill("Test policy text")
Expand Down
59 changes: 59 additions & 0 deletions playwright/tests/oneObjectAllowed.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { expect } from "@playwright/test"

import test from "../fixtures/commands"

import { ObjectTypes } from "constants/wizardObject"

test.describe("One draft or submitted object is allowed", () => {
test.beforeEach(async ({ login, resetDB, newSubmission }) => {
await resetDB()
await login()

// Add submission name & description
await newSubmission()
})

test("should be able to save only one draft or submit one version for Study", async ({
page,
clickAddObject,
formActions,
}) => {
test.slow()

// Add Study form
await clickAddObject(ObjectTypes.study)
await page.getByTestId("descriptor.studyTitle").fill("Test study")
await page.getByTestId("descriptor.studyType").selectOption("Epigenetics")
await page.getByTestId("descriptor.studyAbstract").fill("Study abstract")

// Save Study as draft
await formActions("form-draft")
await page.getByRole("alert").filter({ hasText: "Draft saved successfully" })
await expect(page.getByTestId("draft-study-list-item")).toHaveCount(1)
// Assert that button "Save as draft" should be changed to "Update draft"
await expect(page.getByTestId("form-draft")).toHaveText("Update draft")

// Update Study draft
await page.getByTestId("descriptor.studyTitle").fill("Test study 2")
await formActions("form-draft")
await page.getByRole("alert").filter({ hasText: "Draft saved successfully" })
// Assert that the Study draft is saved again with new title, no new draft is created
await expect(page.getByTestId("draft-study-list-item")).toHaveCount(1)
await expect(page.getByTestId("draft-study-list-item")).toHaveText("Test study 2")

// Mark Study as ready
await formActions("form-ready")
await page.getByRole("alert").filter({ hasText: "Submitted successfully" })
/* Assert that "Save as draft" and "Mark as ready" button are now disabled because there is one Study object submitted,
* user cannot Add a new study
*/
await expect(page.getByTestId("form-draft")).toBeDisabled()
await expect(page.getByTestId("Add study")).toBeDisabled()

// Click the submitted Study to edit, assert that user can only "Update" the submitted Study
await page.getByTestId("draft-study-list-item").click()
await expect(await page.getByTestId("form-ready")).toHaveText("Update")
})
})

export {}
6 changes: 2 additions & 4 deletions src/components/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ const Table = styled(DataGrid)(({ theme }) => ({
color: theme.palette.primary.main,
backgroundColor: theme.palette.primary.lighter,
},
flex: "1 1 auto",
},
"& .MuiDataGrid-columnHeaderTitle": {
fontWeight: 700,
},
"& .MuiDataGrid-columnHeadersInner, .MuiDataGrid-columnHeader, .MuiDataGrid-virtualScrollerRenderZone, .MuiDataGrid-cell, .MuiDataGrid-cell--withRenderer":
{
width: "100% !important",
},
"& .MuiDataGrid-columnHeaderTitleContainer": {
padding: 0,
justifyContent: "left",
"& .MuiDataGrid-sortIcon": {
color: theme.palette.secondary.main,
fontSize: "2rem",
Expand Down
25 changes: 6 additions & 19 deletions src/components/StatusMessageHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,47 +195,35 @@ const SuccessHandler = forwardRef(function SuccessHandler(
case "/v1/drafts": {
switch (response?.config.method) {
case "patch": {
message = t("snackbarMessages.success.drafts.updated", {
accessionId: response.data.accessionId,
})
message = t("snackbarMessages.success.drafts.updated")
break
}
default: {
message = t("snackbarMessages.success.drafts.saved", {
accessionId: response.data.accessionId,
})
message = t("snackbarMessages.success.drafts.saved")
}
}
break
}
case "/v1/objects": {
switch (response.config.method) {
case "patch": {
message = t("snackbarMessages.success.objects.updated", {
accessionId: response.data.accessionId,
})
message = t("snackbarMessages.success.objects.updated")
break
}
case "put": {
message = t("snackbarMessages.success.objects.replaced", {
accessionId: response.data.accessionId,
})
message = t("snackbarMessages.success.objects.replaced")
break
}
default: {
message = t("snackbarMessages.success.objects.submitted", {
accessionId: response.data.accessionId,
})
message = t("snackbarMessages.success.objects.submitted")
}
}
break
}
case "/v1/templates": {
switch (response.config.method) {
default: {
message = t("snackbarMessages.success.templates.updated", {
accessionId: response.data.accessionId,
})
message = t("snackbarMessages.success.templates.updated")
}
}
}
Expand Down Expand Up @@ -318,7 +306,6 @@ const Message = (props: StatusMessageProps) => {

const StatusMessageHandler: React.FC = () => {
const statusDetails = useAppSelector(state => state.statusDetails)

return (
<React.Fragment>
{statusDetails?.status && !Array.isArray(statusDetails.response) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { resetCurrentObject } from "features/wizardCurrentObjectSlice"
import { useAppSelector, useAppDispatch } from "hooks"
import objectAPIService from "services/objectAPI"
import type { ObjectInsideSubmissionWithTags } from "types"
import { getStudyStatus } from "utils"
import { checkObjectStatus } from "utils"

const CustomDialog = styled(Dialog)(({ theme }) => ({
"& .MuiDialog-paper": {
Expand All @@ -42,7 +42,7 @@ const CustomDialog = styled(Dialog)(({ theme }) => ({
flexDirection: "column",
justifyContent: "flex-start",
alignItems: "center",
minWidth:"65rem"
minWidth: "65rem",
},
}))

Expand Down Expand Up @@ -113,7 +113,7 @@ const CancelFormDialog = ({
const [errorMessage, setErrorMessage] = useState("")
const dispatch = useAppDispatch()

const submittedStudy: boolean = getStudyStatus(submission.metadataObjects)
const { hasSubmittedObject } = checkObjectStatus(submission, ObjectTypes.study)

// Draft save logic
const saveDraft = async () => {
Expand Down Expand Up @@ -184,7 +184,7 @@ const CancelFormDialog = ({
saveDraft()
}}
color="primary"
disabled={submittedStudy && objectType === ObjectTypes.study}
disabled={hasSubmittedObject && objectType === ObjectTypes.study}
>
{t("alerts.actions.saveDraft")}
</Button>
Expand Down
Loading

0 comments on commit 44f7ab7

Please sign in to comment.