# Test info

- Name: Case already exists >> CASE_033 - Add and manage businesses in case's detail
- Location: /root/code/portal-automation-test/tests/case/crud/crud.spec.ts:386:7

# Error details

```
Error: locator.click: Test timeout of 80000ms exceeded.
Call log:
  - waiting for locator('//a[contains(@class,\'logo-contact\')]').last()

    at CasePage.addBusinessInDetail (/root/code/portal-automation-test/pom/case/case.page.ts:530:57)
    at /root/code/portal-automation-test/tests/case/crud/crud.spec.ts:391:24
    at /root/code/portal-automation-test/tests/case/crud/crud.spec.ts:389: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:
    - 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: "#872135 Auto Test Duy Nhat 123"
- img
- img
- text: "DOI: 01/03/2005 - Category: Bus Accidents"
- 'link "DOB: 03/01/1999"':
  - /url: /clients/d1039da4-60db-4c39-bc98-252676268ba5
- 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"
- paragraph: Awesome! The Auto Test Duy Nhat 123 case file is ready to go!
- paragraph:
  - text: Click on "Get Started" to submit your request or inquiries for this case now!
  - link "Get Started":
    - /url: /requests/create?patient_id=d1039da4-60db-4c39-bc98-252676268ba5&doi=01/03/2005
- img
- img "Minh Phong (You)"
- img "Team Discussion"
- heading "Discussion" [level=2]
- heading "Minh Phong (You)" [level=4]
- img
- heading "Team Discussion" [level=4]
- img
```

# Test source

```ts
  430 |     async getSortedData(columnIndex: number, isAscending: boolean): Promise<string[]> {
  431 |         const data = await this.getTableData(columnIndex);
  432 |         const sorted = [...data].sort((a, b) => a.localeCompare(b));
  433 |         if (isAscending) {
  434 |             return sorted
  435 |         } else {
  436 |             return sorted.reverse();
  437 |         }
  438 |     }
  439 |
  440 |     async gotoArchive(caseID: string): Promise<void> {
  441 |         await this.go(`cases/${caseID}?view_participant_archived=true`)
  442 |     }
  443 |
  444 |     async fillDataCreateClient(infoClient: { birthday: string, phone: string, address: string }, email: string): Promise<void> {
  445 |         await this.caseLoc.create.detail.inputCreateClientName("birthday").fill(infoClient.birthday);
  446 |         await this.caseLoc.create.detail.inputCreateClientName("phone_number").first().fill(infoClient.phone);
  447 |         await this.caseLoc.create.detail.inputCreateClientName("email_address").first().fill(email);
  448 |         await this.caseLoc.create.detail.inputCreateClientName("address_1").first().fill(infoClient.address);
  449 |
  450 |         await this.caseLoc.create.btnCreate.first().click();
  451 |     }
  452 |
  453 |     async fillCaseDetail(detail: { business: string, category: string, description: string }, clientName: string, doi?: string, createNewBusiness?: boolean): Promise<void> {
  454 |         await this.caseLoc.create.detail.doi.fill(doi || "");
  455 |
  456 |         if (!createNewBusiness) {
  457 |             await this.caseLoc.create.detail.bussiness.type(detail.business);
  458 |             await this.caseLoc.create.detail.boxTextBusiness.click();
  459 |             await this.dashboardLoc.modal.headerModalh2("Preview").click();
  460 |         }
  461 |
  462 |         await this.caseLoc.create.detail.categoryInput.clear();
  463 |         await this.caseLoc.create.detail.categoryInput.type(detail.category, { delay: 50 });
  464 |         await this.caseLoc.create.detail.optionCategory(detail.category).waitFor({ state: "visible" });
  465 |         await this.caseLoc.create.detail.optionCategory(detail.category).click();
  466 |         await this.caseLoc.create.detail.description.fill(detail.description);
  467 |
  468 |         await this.caseLoc.create.detail.inputByPlaceHolder("Select or type a name").first().click();
  469 |         await this.caseLoc.create.detail.inputByPlaceHolder("Select or type a name").first().type(clientName, { delay: 100 });
  470 |     }
  471 |
  472 |     async fillLegalContact(business: string, userRecive: string) {
  473 |         await this.waitForSecond(2);
  474 |         await this.caseLoc.detail.noLegal.click({ force: true });
  475 |         await this.caseLoc.detail.addLegalModal.btnAddSuggest(business).click();
  476 |         await this.caseLoc.detail.addLegalModal.inputByPlaceholder("Enter the attorney's name.").click();
  477 |         await this.caseLoc.detail.addLegalModal.inputByPlaceholder("Enter the attorney's name.").fill(userRecive);
  478 |         await this.caseLoc.detail.addLegalModal.counselAdd(userRecive).click();
  479 |         await this.caseLoc.detail.addLegalModal.inputByPlaceholder("Enter the case manager's name.").click();
  480 |         await this.caseLoc.detail.addLegalModal.inputByPlaceholder("Enter the case manager's name.").fill(userRecive);
  481 |         await this.caseLoc.detail.addLegalModal.counselAdd(userRecive).click();
  482 |     }
  483 |
  484 |     async getNewestActivity(): Promise<string> {
  485 |         await this.waitForSecond(2);
  486 |         await this.caseLoc.detail.buttonActivity.waitFor({ state: 'visible' });
  487 |         await this.caseLoc.detail.buttonActivity.click({ force: true });
  488 |         const textActivity = await this.caseLoc.detail.activity.listActivity.first().innerText();
  489 |         await this.caseLoc.detail.activity.buttonClose.click();
  490 |         return textActivity.replace(/\s+/g, ' ').trim();
  491 |     }
  492 |
  493 |     async changeStarFocus(caseID: string): Promise<void> {
  494 |         await this.caseLoc.detail.keyFocus("Medical Bill").scrollIntoViewIfNeeded();
  495 |         await this.caseLoc.detail.keyFocus("Medical Bill").hover({ force: true, timeout: 3000 });
  496 |         await this.caseLoc.detail.keyFocus("Medical Bill").locator("//div[@class='edit-request open-modal-verify cursor-pointer']").click();
  497 |         await this.caseLoc.detail.btnStarItInModalFocus(caseID).click();
  498 |         await this.dashboardLoc.buttonByText("Confirm").click();
  499 |         await this.dashboardLoc.msgSuccess.waitFor({ state: 'visible' });
  500 |         await this.dashboardLoc.btnClosePopupNotification.click();
  501 |     }
  502 |
  503 |     async clickButtonDropdownSelect(dropdown: string): Promise<void> {
  504 |         await this.caseLoc.detail.btnDropdownBusiness.waitFor({ state: 'visible' });
  505 |         await this.waitForSecond(2);
  506 |         await this.caseLoc.detail.btnDropdownBusiness.click({ force: true });
  507 |         await this.caseLoc.detail.btnInDropdownBusiness(dropdown).click();
  508 |     }
  509 |
  510 |     async tearDownMoveToOldCase(caseID: string): Promise<void> {
  511 |         await this.clickButtonDropdownSelect("BTN_SHOW_MOVE_REQUEST_OF_BUSINESS_MODAL");
  512 |         await this.caseLoc.detail.inputMoveRequest.click();
  513 |         await this.caseLoc.detail.inputMoveRequest.type(caseID, { delay: 100 });
  514 |         await this.caseLoc.detail.transfer.boxOption(caseID).click();
  515 |         await this.caseLoc.buttonByText("Move").click();
  516 |     }
  517 |
  518 |     // Login as another user in a new browser context and return the new RequestPage
  519 |     async loginInAnotherBrowser(browser: Browser, username: string, password: string): Promise<{ context: BrowserContext; page: Page; casePage: CasePage }> {
  520 |         const context = await browser.newContext();
  521 |         const page = await context.newPage();
  522 |         const loginPage = new LoginPage(page);
  523 |         await loginPage.open();
  524 |         await loginPage.login(username, password);
  525 |         await expect(loginPage.baseLoc.dashboardContainer).toBeVisible();
  526 |         return { context, page, casePage: new CasePage(page) };
  527 |     }
  528 |
  529 |     async addBusinessInDetail(businessName: string): Promise<void> {
> 530 |         await this.caseLoc.detail.listBusinesses.last().click();
      |                                                         ^ Error: locator.click: Test timeout of 80000ms exceeded.
  531 |         await this.dashboardLoc.modal.headerModal("Business").waitFor({ state: 'visible' });
  532 |         await this.dashboardLoc.modal.inputByID("autocomplete_business_provider_id").type(businessName, { delay: 100 });
  533 |         await this.caseLoc.create.detail.boxTextBusinessByName(businessName).waitFor({ state: 'visible' });
  534 |         await this.caseLoc.create.detail.boxTextBusinessByName(businessName).click();
  535 |         await this.dashboardLoc.buttonByText("Save").first().click();
  536 |         await this.dashboardLoc.msgAddBusinessInDetail.waitFor({ state: 'visible' });
  537 |         await this.dashboardLoc.btnClosePopupNotification.click();
  538 |     }
  539 |
  540 |     async removeBusiness(businessName: string): Promise<void> {
  541 |         const businessBtn = this.caseLoc.detail.btnDropDownActionBySingleBusiness(businessName);
  542 |         await businessBtn.click();
  543 |         await businessBtn.waitFor({ state: 'visible' });
  544 |         // Wait for active class to be applied
  545 |         await this.page.waitForSelector(`[class*="active"]`);
  546 |         await this.caseLoc.detail.btnDropdownBusiness.click();
  547 |         await this.caseLoc.detail.dropdownOption("Remove").click();
  548 |         await this.dashboardLoc.msgRemoveBussinessSuccess.waitFor({ state: 'visible' });
  549 |         await this.dashboardLoc.btnClosePopupNotification.click();
  550 |         await businessBtn.waitFor({ state: 'hidden' });
  551 |     }
  552 | }
```