Skip to content

Commit 098497d

Browse files
authored
Add undo/redo to ASN field (#1304)
* Refactor cypress tests for editing ASN * Add support for undo/redo in ASN input field
1 parent 3f8b651 commit 098497d

File tree

8 files changed

+592
-539
lines changed

8 files changed

+592
-539
lines changed

packages/ui/cypress/e2e/case-details/handle-triggers-and-exceptions/edit-fields-with-exceptions/edit-asn.cy.ts

-537
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import HO100321 from "../../../../../../test/test-data/HO100321.json"
2+
import { clickTab, loginAndVisit } from "../../../../../support/helpers"
3+
4+
describe("ASN auto divide", () => {
5+
beforeEach(() => {
6+
cy.task("clearCourtCases")
7+
cy.task("insertCourtCasesWithFields", [
8+
{
9+
orgForPoliceFilter: "01",
10+
hearingOutcome: HO100321.hearingOutcomeXml,
11+
updatedHearingOutcome: HO100321.hearingOutcomeXml,
12+
errorCount: 1,
13+
errorLockedByUsername: "GeneralHandler"
14+
}
15+
])
16+
})
17+
18+
it("Should keep the cursor in right place in the input field when the character from the middle is deleted", () => {
19+
loginAndVisit("/bichard/court-cases/0")
20+
21+
cy.get("input#asn").clear()
22+
cy.get("input#asn").type("1101ZD01448754K")
23+
cy.get("input#asn").should("have.value", "11/01ZD/01/448754K")
24+
cy.get("input#asn").then(($el) => ($el[0] as unknown as HTMLInputElement).setSelectionRange(5, 5))
25+
cy.get("input#asn").type("{backspace}")
26+
cy.get("input#asn").should("have.prop", "selectionStart", 4)
27+
})
28+
29+
it("Should keep the cursor in right place in the input field when the character is added in the middle", () => {
30+
loginAndVisit("/bichard/court-cases/0")
31+
32+
cy.get("input#asn").clear()
33+
cy.get("input#asn").type("1101Z01448754K")
34+
cy.get("input#asn").should("have.value", "11/01Z0/14/48754K")
35+
cy.get("input#asn").then(($el) => ($el[0] as unknown as HTMLInputElement).setSelectionRange(5, 5))
36+
cy.get("input#asn").type("D")
37+
cy.get("input#asn").should("have.prop", "selectionStart", 6)
38+
})
39+
40+
it("Should divide ASN into sections when user types or pastes asn into the input field ", () => {
41+
loginAndVisit("/bichard/court-cases/0")
42+
43+
cy.get("#asn").clear()
44+
cy.get("#asn").type("1101ZD0100000448754K")
45+
46+
cy.get("#asn").should("have.value", "11/01ZD/01/00000448754K")
47+
})
48+
49+
it("Should divide ASN into sections when user types or pastes asn into the input field ", () => {
50+
const asnWithoutSlashes = "1101ZD0100000448754K"
51+
const asnWithSlashes = "11/01ZD/01/00000448754K"
52+
53+
loginAndVisit("/bichard/court-cases/0")
54+
55+
cy.intercept("PUT", `/bichard/api/court-cases/0/update`).as("update")
56+
57+
cy.get("input#asn").clear()
58+
cy.get("input#asn").type(asnWithoutSlashes)
59+
cy.get("input#asn").should("have.value", asnWithSlashes)
60+
61+
cy.wait("@update")
62+
cy.get(".asn-row .success-message").contains("Input saved").should("exist")
63+
64+
clickTab("Notes")
65+
cy.get(".notes-table")
66+
.find(
67+
`td:contains("GeneralHandler: Portal Action: Update Applied. Element: asn. New Value: ${asnWithoutSlashes}")`
68+
)
69+
.should("have.length", 1)
70+
71+
clickTab("Defendant")
72+
73+
cy.get("input#asn").type("{backspace}")
74+
cy.get("input#asn").type("K")
75+
76+
cy.get("@update.all").then((interceptions) => expect(interceptions).to.have.length(1))
77+
78+
clickTab("Notes")
79+
cy.get(".notes-table")
80+
.find(`td:contains("GeneralHandler: Portal Action: Update Applied. Element: asn. New Value: ${asnWithSlashes}")`)
81+
.should("have.length", 0)
82+
})
83+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import HO100206 from "../../../../../../test/test-data/HO100206.json"
2+
import { clickTab, loginAndVisit, verifyUpdatedMessage } from "../../../../../support/helpers"
3+
4+
describe("ASN auto saves", () => {
5+
beforeEach(() => {
6+
cy.task("clearCourtCases")
7+
cy.task("insertCourtCasesWithFields", [
8+
{
9+
orgForPoliceFilter: "01",
10+
hearingOutcome: HO100206.hearingOutcomeXml,
11+
updatedHearingOutcome: HO100206.hearingOutcomeXml,
12+
errorCount: 1,
13+
errorLockedByUsername: "GeneralHandler"
14+
}
15+
])
16+
})
17+
18+
it("Should display an error message when auto-save fails", () => {
19+
cy.intercept("PUT", "/bichard/api/court-cases/0/update", {
20+
statusCode: 500
21+
})
22+
23+
loginAndVisit("/bichard/court-cases/0")
24+
25+
cy.get("#asn").clear()
26+
cy.get("#asn").type("1101ZD0100000410836V")
27+
cy.get(".asn-row .error-message").contains("Autosave has failed, please refresh").should("exist")
28+
cy.get(".asn-row .success-message").should("not.exist")
29+
})
30+
31+
it("Should validate and auto-save the ASN correction", () => {
32+
cy.intercept("PUT", "/bichard/api/court-cases/0/update").as("save")
33+
34+
loginAndVisit("/bichard/court-cases/0")
35+
36+
cy.get("#asn").type("AAAAAAAAAAAAAAAAAAAA")
37+
cy.get(".asn-row .error-message").should("exist")
38+
39+
cy.get("button").contains("Submit exception(s)").should("be.enabled")
40+
cy.get("#asn").clear()
41+
42+
cy.get("#asn").type("1101ZD0100000410836V")
43+
cy.get(".asn-row .success-message").contains("Input saved").should("exist")
44+
cy.get("button").contains("Submit exception(s)").should("be.enabled")
45+
46+
cy.wait("@save")
47+
verifyUpdatedMessage({
48+
expectedCourtCase: { errorId: 0, errorStatus: "Unresolved" },
49+
updatedMessageNotHaveContent: ["<br7:ArrestSummonsNumber>1101ZD0100000448754K</br7:ArrestSummonsNumber>"],
50+
updatedMessageHaveContent: ["<br7:ArrestSummonsNumber>1101ZD0100000410836V</br7:ArrestSummonsNumber>"]
51+
})
52+
})
53+
54+
it("Should validate and auto-save the ASN correction and update notes", () => {
55+
const errorId = 0
56+
const updatedAsn = "1101ZD0100000410836V"
57+
58+
cy.intercept("PUT", `/bichard/api/court-cases/${errorId}/update`).as("save")
59+
60+
loginAndVisit(`/bichard/court-cases/${errorId}`)
61+
62+
cy.get("#asn").type("AAAAAAAAAAAAAAAAAAAA")
63+
cy.get(".asn-row .error-message").should("exist")
64+
cy.get(".asn-row .error-message").contains("Enter ASN in the correct format")
65+
66+
cy.get("button").contains("Submit exception(s)").should("be.enabled")
67+
cy.get("#asn").clear()
68+
69+
cy.get("#asn").type(updatedAsn)
70+
71+
cy.wait("@save")
72+
73+
cy.get(".asn-row .success-message").contains("Input saved").should("exist")
74+
cy.get("button").contains("Submit exception(s)").should("be.enabled")
75+
76+
cy.get("@save").its("response.body.courtCase.errorId").should("eq", errorId)
77+
cy.get("@save")
78+
.its(
79+
"response.body.courtCase.updatedHearingOutcome.AnnotatedHearingOutcome.HearingOutcome.Case.HearingDefendant.ArrestSummonsNumber"
80+
)
81+
.should("eq", updatedAsn)
82+
83+
clickTab("Notes")
84+
cy.get("td").contains(`GeneralHandler: Portal Action: Update Applied. Element: asn. New Value: ${updatedAsn}`)
85+
})
86+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import HO100206 from "../../../../../../test/test-data/HO100206.json"
2+
import HO100300 from "../../../../../../test/test-data/HO100300.json"
3+
import HO100301 from "../../../../../../test/test-data/HO100301.json"
4+
import HO100314 from "../../../../../../test/test-data/HO100314.json"
5+
import HO100321 from "../../../../../../test/test-data/HO100321.json"
6+
import { loginAndVisit, verifyUpdatedMessage } from "../../../../../support/helpers"
7+
8+
describe("exceptions", () => {
9+
function submitEditableAsnExceptionAmendment(exception: { hearingOutcomeXml: string }, asn: string) {
10+
cy.task("clearCourtCases")
11+
cy.task("insertCourtCasesWithFields", [
12+
{
13+
orgForPoliceFilter: "01",
14+
hearingOutcome: exception.hearingOutcomeXml,
15+
updatedHearingOutcome: exception.hearingOutcomeXml,
16+
errorCount: 1,
17+
errorLockedByUsername: "GeneralHandler"
18+
}
19+
])
20+
21+
loginAndVisit("/bichard/court-cases/0")
22+
23+
cy.get("#asn").clear()
24+
cy.get("#asn").type(asn)
25+
26+
cy.get("button").contains("Submit exception(s)").click()
27+
28+
cy.contains(
29+
"Are you sure you want to submit the amended details to the PNC and mark the exception(s) as resolved?"
30+
).should("exist")
31+
cy.get("button").contains("Submit exception(s)").click()
32+
33+
cy.contains(`GeneralHandler: Portal Action: Update Applied. Element: asn. New Value: ${asn}`)
34+
cy.contains("GeneralHandler: Portal Action: Resubmitted Message.")
35+
}
36+
37+
it("Should be able to edit ASN field if HO100206 is raised", () => {
38+
submitEditableAsnExceptionAmendment(HO100206, "1101ZD0100000448754K")
39+
40+
verifyUpdatedMessage({
41+
expectedCourtCase: { errorId: 0, errorStatus: "Submitted" },
42+
updatedMessageNotHaveContent: ["<br7:ArrestSummonsNumber>AAAAAAAAAAAAAAAAAAAA</br7:ArrestSummonsNumber>"],
43+
updatedMessageHaveContent: ["<br7:ArrestSummonsNumber>1101ZD0100000448754K</br7:ArrestSummonsNumber>"]
44+
})
45+
})
46+
47+
it("Should be able to edit ASN field if HO100300 is raised", () => {
48+
submitEditableAsnExceptionAmendment(HO100300, "1101ZD0100000448754K")
49+
50+
verifyUpdatedMessage({
51+
expectedCourtCase: { errorId: 0, errorStatus: "Submitted" },
52+
updatedMessageNotHaveContent: ["<br7:ArrestSummonsNumber>2006MM0600000003131B</br7:ArrestSummonsNumber>"],
53+
updatedMessageHaveContent: ["<br7:ArrestSummonsNumber>1101ZD0100000448754K</br7:ArrestSummonsNumber>"]
54+
})
55+
})
56+
57+
it("Should be able to edit ASN field if HO100301 is raised", () => {
58+
submitEditableAsnExceptionAmendment(HO100301, "1101ZD0100000448754K")
59+
60+
verifyUpdatedMessage({
61+
expectedCourtCase: { errorId: 0, errorStatus: "Submitted" },
62+
updatedMessageNotHaveContent: ["<br7:ArrestSummonsNumber>2006MM0600000003131B</br7:ArrestSummonsNumber>"],
63+
updatedMessageHaveContent: ["<br7:ArrestSummonsNumber>1101ZD0100000448754K</br7:ArrestSummonsNumber>"]
64+
})
65+
})
66+
67+
it("Should be able to edit ASN field if HO100314 is raised", () => {
68+
submitEditableAsnExceptionAmendment(HO100314, "1101ZD0100000448754K")
69+
70+
verifyUpdatedMessage({
71+
expectedCourtCase: { errorId: 0, errorStatus: "Submitted" },
72+
updatedMessageNotHaveContent: ["<br7:ArrestSummonsNumber>AAAAAAAAAAAAAAAAAAAA</br7:ArrestSummonsNumber>"],
73+
updatedMessageHaveContent: ["<br7:ArrestSummonsNumber>1101ZD0100000448754K</br7:ArrestSummonsNumber>"]
74+
})
75+
})
76+
77+
it("Should be able to edit ASN field if HO100321 is raised", () => {
78+
submitEditableAsnExceptionAmendment(HO100321, "1101ZD0100000448754K")
79+
80+
verifyUpdatedMessage({
81+
expectedCourtCase: { errorId: 0, errorStatus: "Submitted" },
82+
updatedMessageNotHaveContent: ["<br7:ArrestSummonsNumber>AAAAAAAAAAAAAAAAAAAA</br7:ArrestSummonsNumber>"],
83+
updatedMessageHaveContent: ["<br7:ArrestSummonsNumber>1101ZD0100000448754K</br7:ArrestSummonsNumber>"]
84+
})
85+
})
86+
})

0 commit comments

Comments
 (0)