# Test info

- Name: Case already exists >> CASE_017 - Verify when archived/unArchived case has request and transfer to another case
- Location: /root/code/portal-automation-test/tests/case/crud/crud.spec.ts:260:7

# Error details

```
Error: expect(received).toBe(expected) // Object.is equality

Expected: 2
Received: 1
    at /root/code/portal-automation-test/tests/case/crud/crud.spec.ts:292:24
    at /root/code/portal-automation-test/tests/case/crud/crud.spec.ts:287:5
```

# Page snapshot

```yaml
- complementary:
  - img
  - link "WellCare Pharmacy12321@@@@ Portal QA":
    - /url: /
    - paragraph: WellCare Pharmacy12321@@@@
    - paragraph: Portal QA
  - list:
    - listitem:
      - link "Home":
        - /url: https://qa.loprx.com
        - img
        - text: Home
    - listitem:
      - link "Case":
        - /url: https://qa.loprx.com/cases
        - img
        - text: Case
    - listitem:
      - link "Request":
        - /url: https://qa.loprx.com/requests
        - img
        - text: Request
    - listitem:
      - link "Patient":
        - /url: https://qa.loprx.com/clients
        - img
        - text: Patient
    - listitem:
      - button "Business/Contact":
        - img
        - text: Business/Contact
    - listitem:
      - button "Inbox/Sent":
        - img
        - text: Inbox/Sent
    - listitem:
      - button "Settings":
        - img
        - text: Settings
  - list:
    - listitem:
      - button "Shared with me":
        - img
        - text: Shared with me
- banner:
  - button [disabled]:
    - img
  - button:
    - img
  - img
  - text: Tri01 Duc shared details regarding Auto_YXQ Test Letter of Protection. Read it now. 10 hours ago
  - img
  - text: Son HaiBon Phan assigned a request to you 10 hours ago
  - img
  - text: Son HaiBon Phan assigned a case to you 11 hours ago
  - img
  - img
  - img
  - paragraph: No notifications yet
  - paragraph: When you get notifications, they'll show up here
  - button "Refresh"
  - list:
    - listitem:
      - img
      - paragraph: Pause notifications...
      - list:
        - listitem: For 30 minutes
        - listitem: For 1 hour
        - listitem: For 2 hours
        - listitem: Until tomorrow
    - listitem:
      - img
    - listitem:
      - img
    - listitem:
      - img
    - listitem:
      - img
    - listitem:
      - img
    - listitem:
      - img
  - img
  - button "0 Cart":
    - img
    - text: 0 Cart
  - text: Feedback
  - img
  - link "Open user menu":
    - /url: "#"
    - text: Minh
- text: "#951463 Test123123 Hẹ Hẹ"
- img
- img
- text: "DOI: 03/03/2001 - Category: Other Injuries"
- 'link "DOB: 03/02/1998"':
  - /url: /clients/1ff99a81-ad02-4858-b76a-f91917bdd9a5
- text: Tag
- img
- img
- 'button "Status: Open"'
- button:
  - listbox:
    - listitem:
      - text: "Status Details: Open"
      - img
- 'button "Service Date: --"'
- 'button "Assignee: --"':
  - text: "Assignee: --"
  - img
- button "New Request"
- button "Activity":
  - img
  - text: Activity
- button "Update Case"
- heading "Quick summary at your fingertips" [level=2]
- img
- paragraph: Letter of Protection
- heading "Activity" [level=2]
- table:
  - rowgroup:
    - 'row "Starred # Status Details Latest Comment From To"':
      - cell "Starred"
      - cell "#"
      - cell "Status Details"
      - cell "Latest Comment"
      - cell "From"
      - cell "To"
  - rowgroup:
    - row "582064 Awaiting WellCare Pharmacy12321@@@@ Son35 Pharmacy":
      - cell:
        - img
      - cell "582064":
        - link "582064":
          - /url: /requests/582064
      - cell "Awaiting":
        - link "Awaiting":
          - /url: /requests/582064
      - cell:
        - link:
          - /url: /requests/582064
      - cell "WellCare Pharmacy12321@@@@":
        - link "WellCare Pharmacy12321@@@@":
          - /url: /requests/582064
      - cell "Son35 Pharmacy":
        - link "Son35 Pharmacy":
          - /url: /requests/582064
    - row "557414 Awaiting WellCare Pharmacy12321@@@@ Business New76232611":
      - cell:
        - img
      - cell "557414":
        - link "557414":
          - /url: /requests/557414
      - cell "Awaiting":
        - link "Awaiting":
          - /url: /requests/557414
      - cell:
        - link:
          - /url: /requests/557414
      - cell "WellCare Pharmacy12321@@@@":
        - link "WellCare Pharmacy12321@@@@":
          - /url: /requests/557414
      - cell "Business New76232611":
        - link "Business New76232611":
          - /url: /requests/557414
- heading "Dive deeper" [level=2]
- paragraph: beyond the summary
- img
- img
- paragraph: Business New76232611
- img
- link "New Request":
  - /url: /requests/create?patient_id=1ff99a81-ad02-4858-b76a-f91917bdd9a5&doi=03/03/2001&business_id=ac3027b1-4310-40cc-955e-fb4d31bc7897
- heading "Key Focus" [level=2]
- link "Letter of Protection Status Open Status Details Awaiting":
  - /url: /requests/557414
  - paragraph: Letter of Protection
  - img
  - paragraph: Status
  - paragraph: Open
  - paragraph: Status Details
  - paragraph: Awaiting
- heading "Request" [level=2]
- img
- text: Show
- textbox: "10"
- text: entries
- table:
  - rowgroup:
    - row "#  Request  Status  Status Details  Star It  From  Directed To  Actions":
      - cell "# "
      - cell "Request "
      - cell "Status "
      - cell "Status Details "
      - cell "Star It "
      - cell "From "
      - cell "Directed To "
      - cell "Actions"
  - rowgroup:
    - row "557414 Letter of Protection Open Awaiting WellCare Pharmacy12321@@@@ Business New76232611":
      - cell "557414":
        - link "557414":
          - /url: /requests/557414
      - cell "Letter of Protection":
        - link "Letter of Protection":
          - /url: /requests/557414
          - img
          - text: Letter of Protection
      - cell "Open":
        - link "Open":
          - /url: /requests/557414
      - cell "Awaiting":
        - link "Awaiting":
          - /url: /requests/557414
      - cell:
        - link:
          - /url: /requests/557414
          - img
      - cell "WellCare Pharmacy12321@@@@":
        - link "WellCare Pharmacy12321@@@@":
          - /url: /requests/557414
      - cell "Business New76232611":
        - link "Business New76232611":
          - /url: /requests/557414
      - cell:
        - img
        - img
- paragraph: Showing 1 to 1 of 1 entries
- img
- img "Team Discussion"
- img "Minh Phong (You)"
- heading "Discussion" [level=2]
- heading "Team Discussion" [level=4]
- text: hi there 07/10/2025
- img
- heading "Minh Phong (You)" [level=4]
- img
```

# Test source

```ts
  192 |       await casePage.caseLoc.detail.update.selectLawFirm("autocomplete_lawyer_id").first().click();
  193 |       await casePage.caseLoc.detail.update.selectLawFirm("autocomplete_case_manager_id").first().click();
  194 |       await casePage.dashboardLoc.buttonByText("Update").first().click();
  195 |
  196 |       await expect(casePage.caseLoc.detail.addLegalModal.msgSuccess.first()).toBeVisible();
  197 |       await expect(casePage.dashboardLoc.modal.headerModal("Case Detail")).not.toBeVisible();
  198 |       await expect(casePage.caseLoc.detail.noLegal).toBeVisible();
  199 |     })
  200 |
  201 |     await test.step("Teardown data", async () => {
  202 |       await casePage.fillLegalContact(conf.data.business, conf.data.user_recive_case);
  203 |       await casePage.dashboardLoc.buttonByText("Submit").nth(2).click();
  204 |       await expect(casePage.caseLoc.detail.addLegalModal.msgSuccess.first()).toBeVisible();
  205 |       await expect(casePage.caseLoc.detail.noLegal).not.toBeVisible();
  206 |     })
  207 |   })
  208 |
  209 |   test("CASE_016 - Verify when archived/unArchived case has no request yet", {
  210 |     tag: ['@CASE_016', '@case', '@function']
  211 |   }, async ({ conf, casePage16 }) => {
  212 |     test.setTimeout(150_000);
  213 |     await test.step("Verify when archive case", async () => {
  214 |       await expect(casePage16.caseLoc.detail.buttonUpdateCase).toBeVisible();
  215 |       await casePage16.caseLoc.detail.buttonUpdateCase.click({ force: true });
  216 |       await casePage16.dashboardLoc.buttonByText("Archive").first().click();
  217 |       await expect(casePage16.caseLoc.detail.update.msgArchive).toBeVisible();
  218 |       await casePage.dashboardLoc.btnClosePopupNotification.click();
  219 |
  220 |       await expect(casePage16.dashboardLoc.modal.headerModalh2("Case Detail")).not.toBeVisible();
  221 |       await expect(casePage16.caseLoc.detail.update.boxHeaderArchive).toBeVisible();
  222 |       await casePage16.page.reload();// Sau khi client update tự reload cần bỏ
  223 |
  224 |       // Verify activity
  225 |       const newestActivity = await casePage16.getNewestActivity();
  226 |       expect(newestActivity).toContain(`archive case ${await getTodayInTimeZone()}`);
  227 |
  228 |       //Verify not show in table
  229 |       await casePage16.open();
  230 |       await casePage16.dashboardLoc.search.inputSearch.fill(conf.data.case);
  231 |       await expect(casePage16.caseLoc.msgNoResultFound).toBeVisible();
  232 |     })
  233 |
  234 |     await test.step("Verify when unArchive case", async () => {
  235 |       //Verify data show in archived table
  236 |       await casePage16.dashboardLoc.search.filter.btn.click();
  237 |       await casePage16.caseLoc.inputArchive.fill("Yes");
  238 |       await casePage16.caseLoc.boxSelectArchive.click();
  239 |       await casePage16.dashboardLoc.search.filter.popup.btnApply.click();
  240 |       await expect(casePage16.dashboardLoc.table.itemInRow(conf.data.case)).toBeVisible();
  241 |
  242 |       //Verify when unArchive case
  243 |       await casePage16.dashboardLoc.table.itemInRow(conf.data.case).click();
  244 |       await casePage16.caseLoc.detail.update.btnUnArchive.click();
  245 |       await expect(casePage16.caseLoc.detail.update.msgUnArchive.first()).toBeVisible();
  246 |       await expect(casePage16.caseLoc.detail.update.boxHeaderArchive).not.toBeVisible();
  247 |       await casePage16.page.reload(); // Sau khi client update tự reload cần bỏ
  248 |
  249 |       // Verify change activity
  250 |       const newestActivity = await casePage16.getNewestActivity();
  251 |       expect(newestActivity).toContain(`unarchive case ${await getTodayInTimeZone()}`);
  252 |
  253 |       //Verify case exist in table
  254 |       await casePage16.open();
  255 |       await casePage16.dashboardLoc.search.inputSearch.fill(conf.data.case);
  256 |       await expect(casePage16.dashboardLoc.table.itemInRow(conf.data.case)).toBeVisible();
  257 |     })
  258 |   })
  259 |
  260 |   test("CASE_017 - Verify when archived/unArchived case has request and transfer to another case", {
  261 |     tag: ['@CASE_017', '@case', '@function']
  262 |   }, async ({ conf, casePage17 }) => {
  263 |     await test.step("Verify when archive case and transfer case", async () => {
  264 |       await expect(casePage17.dashboardLoc.buttonByText("Archive").first()).toBeVisible();
  265 |       await casePage17.dashboardLoc.buttonByText("Archive").first().click();
  266 |
  267 |       await expect(casePage17.dashboardLoc.modal.headerModal("Archive")).toBeVisible();
  268 |       await casePage17.caseLoc.detail.transfer.inputTransfer.click();
  269 |       await casePage17.caseLoc.detail.transfer.inputTransfer.type(conf.data.case_transfer_to, { delay: 100 });
  270 |       await casePage17.caseLoc.detail.transfer.boxOption(conf.data.case_transfer_to).click();
  271 |       await casePage17.dashboardLoc.buttonByText("Archive").nth(1).click();
  272 |
  273 |       await expect(casePage17.caseLoc.detail.update.btnUnArchive).toBeVisible();
  274 |
  275 |       // Verify activity 
  276 |       await casePage17.waitForSecond(3); // Load for update new activity
  277 |       const newestActivity = await casePage17.getNewestActivity();
  278 |       expect(newestActivity).toContain(`archive case and moved request Case: #${conf.data.case_transfer} #${conf.data.case_transfer_to}`);
  279 |     });
  280 |
  281 |     await test.step("Verify when unarchive case", async () => {
  282 |       await casePage17.caseLoc.detail.update.btnUnArchive.click();
  283 |       await expect(casePage17.caseLoc.detail.update.msgUnArchive.first()).toBeVisible();
  284 |       await expect(casePage17.caseLoc.detail.update.boxHeaderArchive).not.toBeVisible();
  285 |     })
  286 |
  287 |     await test.step("Verify case have request had transfered", async () => {
  288 |       await casePage17.open();
  289 |       await casePage17.getDetailCase(conf.data.case_transfer_to);
  290 |       await casePage17.waitForSecond(2);
  291 |       const requests = (await casePage17.caseLoc.detail.requestExist(conf.data.request_id_exist).all()).length;
> 292 |       expect(requests).toBe(2);
      |                        ^ Error: expect(received).toBe(expected) // Object.is equality
  293 |     })
  294 |
  295 |     await test.step("Transfer teardown data", async () => {
  296 |       //Transfer again to old case
  297 |       await casePage17.clickButtonDropdownSelect("BTN_SHOW_MOVE_REQUEST_OF_BUSINESS_MODAL");
  298 |       await expect(casePage17.dashboardLoc.modal.headerModal("Move Requests")).toBeVisible();
  299 |       await casePage17.caseLoc.detail.inputMoveRequest.click();
  300 |       await casePage17.caseLoc.detail.inputMoveRequest.type(conf.data.case_transfer, { delay: 100 });
  301 |       await casePage17.caseLoc.detail.transfer.boxOption(conf.data.case_transfer).click();
  302 |       await casePage17.caseLoc.buttonByText("Move").click();
  303 |     })
  304 |   })
  305 |
  306 |   test("CASE_018 - Verify when archived/unArchived case has been requested and not transferred to another case", {
  307 |     tag: ['@CASE_018', '@case', '@function']
  308 |   }, async ({ conf, casePage18 }) => {
  309 |     test.setTimeout(180_000);
  310 |     let numberRequest: number;
  311 |
  312 |     await test.step("Go to get number requests in dashboard", async () => {
  313 |       await casePage18.page.goto("")
  314 |       await expect(casePage18.dashboardLoc.common.pText("My Requests")).toBeVisible();
  315 |       await casePage18.dashboardLoc.common.pText("My Requests").click();
  316 |
  317 |       await expect(casePage18.dashboardLoc.filterMonitor.requestTypeNumber.first()).toBeVisible();
  318 |       await casePage18.waitForSecond(2);
  319 |       const textRequest = await casePage18.dashboardLoc.filterMonitor.requestTypeNumber.first().innerText();
  320 |       numberRequest = parseInt(textRequest);
  321 |     });
  322 |
  323 |     await test.step("Verify archive and not transferred to another case", async () => {
  324 |       // Get detail case
  325 |       await casePage18.open();
  326 |       await casePage18.getDetailCase(conf.data.case);
  327 |       await expect(casePage18.caseLoc.detail.buttonUpdateCase).toBeVisible();
  328 |
  329 |       // Archive case
  330 |       await casePage18.caseLoc.detail.buttonUpdateCase.click({ force: true });
  331 |       await casePage.dashboardLoc.buttonByText("Archive").first().click();
  332 |       await expect(casePage18.dashboardLoc.modal.headerModal("Archive")).toBeVisible();
  333 |
  334 |       await casePage18.caseLoc.detail.transfer.radioCheckArchive.click();
  335 |       await casePage.dashboardLoc.buttonByText("Archive").nth(1).click();
  336 |       await expect(casePage18.caseLoc.detail.transfer.msgArchive).toBeVisible();
  337 |       await casePage18.dashboardLoc.btnClosePopupNotification.click();
  338 |     });
  339 |
  340 |     await test.step("Verify requests archive in table", async () => {
  341 |       await casePage18.page.reload();
  342 |       await expect(casePage18.caseLoc.detail.dataIntable("Archived Request", conf.data.request_id_exist)).toBeVisible();
  343 |       await expect(casePage18.caseLoc.detail.requestTableNoResult).toBeVisible();
  344 |
  345 |       // unArchive case
  346 |       await casePage18.caseLoc.detail.update.btnUnArchive.click();
  347 |       await expect(casePage18.caseLoc.detail.update.msgUnArchive.first()).toBeVisible();
  348 |       await casePage18.dashboardLoc.btnClosePopupNotification.click();
  349 |     });
  350 |
  351 |     await test.step("Verify requests change number in dashboard", async () => {
  352 |       await casePage18.page.goto("")
  353 |       await expect(casePage18.dashboardLoc.common.pText("My Requests")).toBeVisible();
  354 |       await casePage18.dashboardLoc.common.pText("My Requests").click();
  355 |       await casePage18.waitForSecond(2);
  356 |       const textRequestAfter = await casePage18.dashboardLoc.filterMonitor.requestTypeNumber.first().innerText();
  357 |       const numberRequestAfter = parseInt(textRequestAfter);
  358 |       expect(numberRequestAfter).toBe(numberRequest - 1);
  359 |     });
  360 |
  361 |     await test.step("Verify requests back to request table", async () => {
  362 |       await casePage18.open();
  363 |       await casePage18.getDetailCase(conf.data.case);
  364 |       await expect(casePage18.caseLoc.detail.requestExist(conf.data.request_id_exist).first()).toBeVisible();
  365 |       await casePage18.waitForSecond(1);
  366 |       await casePage18.caseLoc.detail.requestExist(conf.data.request_id_exist).first().click({ force: true });
  367 |       await casePage18.caseLoc.detail.update.btnUnArchive.click();
  368 |       await casePage.dashboardLoc.buttonByText("Unarchive").click()
  369 |       await casePage.caseLoc.btnCloseModal.click();
  370 |       await casePage18.caseLoc.linkToCase(conf.data.case).click();
  371 |       await casePage18.waitForSecond(2);
  372 |       await expect(casePage18.caseLoc.detail.requestTableNoResult).not.toBeVisible();
  373 |     });
  374 |
  375 |     await test.step("Verify requests number in dashboard back to initial", async () => {
  376 |       await casePage18.page.goto("");
  377 |       await expect(casePage18.dashboardLoc.common.pText("My Requests")).toBeVisible();
  378 |       await casePage18.dashboardLoc.common.pText("My Requests").click();
  379 |       await casePage18.waitForSecond(2);
  380 |       const textRequestFinal = await casePage18.dashboardLoc.filterMonitor.requestTypeNumber.first().innerText();
  381 |       const numberRequestFinal = parseInt(textRequestFinal);
  382 |       expect(numberRequestFinal).toBe(numberRequest);
  383 |     });
  384 |   });
  385 |
  386 |   test("CASE_033 - Add and manage businesses in case's detail", {
  387 |     tag: ['@CASE_033', '@case', '@function']
  388 |   }, async ({ conf }) => {
  389 |     await test.step("Setup and verify initial business state", async () => {
  390 |       if (!await casePage.caseLoc.detail.singleBusinesses(conf.data.business_no_request_1).isVisible({ timeout: 3_000 })) {
  391 |         await casePage.addBusinessInDetail(conf.data.business_no_request_1);
  392 |       }
```