From 535184be0a2dfe2ff774791691cbac395f9a4484 Mon Sep 17 00:00:00 2001
From: Alex Velichko <alex@hardcoreeng.com>
Date: Sat, 10 Feb 2024 11:07:31 +0300
Subject: [PATCH] TESTS-167: feat(tests): done Check that the issue backlink
 test (#4596)

* TESTS-167: feat(tests): done Check that the issue backlink test
---------

Signed-off-by: Alex Velichko <alex@hardcoreeng.com>
---
 .../model/contacts/employee-details-page.ts   | 10 ++++++
 tests/sanity/tests/model/contacts/types.ts    |  4 +++
 .../model/tracker/common-tracker-page.ts      |  8 ++++-
 tests/sanity/tests/tracker/mentions.spec.ts   | 33 +++++++++++++++++++
 4 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 tests/sanity/tests/model/contacts/types.ts

diff --git a/tests/sanity/tests/model/contacts/employee-details-page.ts b/tests/sanity/tests/model/contacts/employee-details-page.ts
index 2f271d5f8a..e5b2f10835 100644
--- a/tests/sanity/tests/model/contacts/employee-details-page.ts
+++ b/tests/sanity/tests/model/contacts/employee-details-page.ts
@@ -1,11 +1,14 @@
 import { expect, type Locator, type Page } from '@playwright/test'
 import { CommonPage } from '../common-page'
+import { Employee } from './types'
 
 export class EmployeeDetailsPage extends CommonPage {
   readonly page: Page
   readonly pageHeader: Locator
   readonly textActivity: Locator
   readonly textActivityContent: Locator
+  readonly textEmployeeFirstName: Locator
+  readonly textEmployeeLastName: Locator
 
   constructor (page: Page) {
     super()
@@ -13,10 +16,17 @@ export class EmployeeDetailsPage extends CommonPage {
     this.pageHeader = page.locator('span[class$="title"]', { hasText: 'Employee' })
     this.textActivity = page.locator('div.header')
     this.textActivityContent = page.locator('div.activityMessage div.content div[class*="content"]')
+    this.textEmployeeFirstName = page.locator('input[placeholder="First name"]')
+    this.textEmployeeLastName = page.locator('input[placeholder="Last name"]')
   }
 
   async checkActivityExist (activityHeader: string, activityContent: string): Promise<void> {
     await expect(this.textActivity.filter({ hasText: activityHeader }).first()).toBeVisible()
     await expect(this.textActivityContent.filter({ hasText: activityContent }).first()).toBeVisible()
   }
+
+  async checkEmployee (employee: Employee): Promise<void> {
+    await expect(this.textEmployeeFirstName).toHaveValue(employee.firstName)
+    await expect(this.textEmployeeLastName).toHaveValue(employee.lastName)
+  }
 }
diff --git a/tests/sanity/tests/model/contacts/types.ts b/tests/sanity/tests/model/contacts/types.ts
new file mode 100644
index 0000000000..42de445dd8
--- /dev/null
+++ b/tests/sanity/tests/model/contacts/types.ts
@@ -0,0 +1,4 @@
+export interface Employee {
+  firstName: string
+  lastName: string
+}
diff --git a/tests/sanity/tests/model/tracker/common-tracker-page.ts b/tests/sanity/tests/model/tracker/common-tracker-page.ts
index 1c51d9da2f..f76f13f0cc 100644
--- a/tests/sanity/tests/model/tracker/common-tracker-page.ts
+++ b/tests/sanity/tests/model/tracker/common-tracker-page.ts
@@ -15,6 +15,7 @@ export class CommonTrackerPage extends CalendarPage {
   readonly inputKeepOriginalMoveIssuesModal: Locator
   readonly buttonMoreActions: Locator
   readonly textActivityContent: Locator
+  readonly linkInActivity: Locator
 
   constructor (page: Page) {
     super(page)
@@ -32,6 +33,7 @@ export class CommonTrackerPage extends CalendarPage {
     this.inputKeepOriginalMoveIssuesModal = page.locator('form[id="tracker:string:MoveIssues"] input[type="checkbox"]')
     this.buttonMoreActions = page.locator('div.popupPanel-title div.flex-row-center > button:first-child')
     this.textActivityContent = page.locator('div.activityMessage div.content div.content')
+    this.linkInActivity = page.locator('div[id="activity:string:Activity"] a')
   }
 
   async selectFilter (filter: string, filterSecondLevel?: string): Promise<void> {
@@ -154,7 +156,7 @@ export class CommonTrackerPage extends CalendarPage {
   }
 
   async addMentions (mention: string): Promise<void> {
-    await this.inputComment.fill('@')
+    await this.inputComment.fill(`@${mention}`)
     await this.selectMention(this.page, mention)
     await this.buttonSendComment.click()
   }
@@ -162,4 +164,8 @@ export class CommonTrackerPage extends CalendarPage {
   async checkActivityContentExist (activityContent: string): Promise<void> {
     await expect(this.textActivityContent.filter({ hasText: activityContent })).toBeVisible()
   }
+
+  async openLinkFromActivitiesByText (linkText: string): Promise<void> {
+    await this.linkInActivity.filter({ hasText: linkText }).click()
+  }
 }
diff --git a/tests/sanity/tests/tracker/mentions.spec.ts b/tests/sanity/tests/tracker/mentions.spec.ts
index b053ef3e14..99483f89e4 100644
--- a/tests/sanity/tests/tracker/mentions.spec.ts
+++ b/tests/sanity/tests/tracker/mentions.spec.ts
@@ -101,4 +101,37 @@ test.describe('Mentions issue tests', () => {
     const employeeDetailsPage = new EmployeeDetailsPage(page)
     await employeeDetailsPage.checkActivityExist(`mentioned ${mentionName} in`, `@${mentionName}`)
   })
+
+  test('Check that the backlink shown in the Issue activity', async ({ page }) => {
+    const mentionName = 'Dirak Kainin'
+    const backlinkIssue: NewIssue = {
+      title: `Check that the backlink shown in the Contact activity-${generateId()}`,
+      description: 'Check that the backlink shown in the Contact activity description'
+    }
+
+    const leftSideMenuPage = new LeftSideMenuPage(page)
+    await leftSideMenuPage.buttonTracker.click()
+
+    const issuesPage = new IssuesPage(page)
+    await issuesPage.modelSelectorAll.click()
+    await issuesPage.createNewIssue(backlinkIssue)
+    await issuesPage.searchIssueByName(backlinkIssue.title)
+    await issuesPage.openIssueByName(backlinkIssue.title)
+
+    const issuesDetailsPage = new IssuesDetailsPage(page)
+    await issuesDetailsPage.checkActivityExist('created issue')
+    await issuesDetailsPage.checkActivityContentExist(`New issue: ${backlinkIssue.title}`)
+    await issuesDetailsPage.openLinkFromActivitiesByText(backlinkIssue.title)
+    await issuesDetailsPage.checkIssue(backlinkIssue)
+
+    await issuesDetailsPage.addMentions(mentionName)
+    await issuesDetailsPage.checkCommentExist(`@${mentionName}`)
+    await issuesDetailsPage.openLinkFromActivitiesByText(mentionName)
+
+    const employeeDetailsPage = new EmployeeDetailsPage(page)
+    await employeeDetailsPage.checkEmployee({
+      firstName: mentionName.split(' ')[1],
+      lastName: mentionName.split(' ')[0]
+    })
+  })
 })