diff --git a/tests/sanity/tests/files/cat2.jpeg b/tests/sanity/tests/files/cat2.jpeg new file mode 100644 index 00000000000..6899f24339e Binary files /dev/null and b/tests/sanity/tests/files/cat2.jpeg differ diff --git a/tests/sanity/tests/files/cat3.jpeg b/tests/sanity/tests/files/cat3.jpeg new file mode 100644 index 00000000000..afd1fcbe047 Binary files /dev/null and b/tests/sanity/tests/files/cat3.jpeg differ diff --git a/tests/sanity/tests/model/tracker/issues-details-page.ts b/tests/sanity/tests/model/tracker/issues-details-page.ts index cba99b59120..38233d5441b 100644 --- a/tests/sanity/tests/model/tracker/issues-details-page.ts +++ b/tests/sanity/tests/model/tracker/issues-details-page.ts @@ -122,4 +122,8 @@ export class IssuesDetailsPage extends CommonTrackerPage { async openSubIssueByName (issueName: string): Promise { await this.page.locator('div.main div.listGrid a', { hasText: issueName }).click() } + + async checkIssueContainsAttachment (fileName: string): Promise { + await this.page.locator('div.attachment-grid div.name', { hasText: fileName }).click() + } } diff --git a/tests/sanity/tests/model/tracker/issues-page.ts b/tests/sanity/tests/model/tracker/issues-page.ts index 1d76c33422c..e4567500533 100644 --- a/tests/sanity/tests/model/tracker/issues-page.ts +++ b/tests/sanity/tests/model/tracker/issues-page.ts @@ -30,6 +30,8 @@ export class IssuesPage extends CommonTrackerPage { readonly issuesList: Locator readonly buttonPopupCreateNewIssueParent: Locator readonly buttonPopupCreateNewIssueTemplate: Locator + readonly inputPopupAddAttachmentsFile: Locator + readonly textPopupAddAttachmentsFile: Locator constructor (page: Page) { super(page) @@ -72,6 +74,8 @@ export class IssuesPage extends CommonTrackerPage { this.buttonPopupCreateNewIssueTemplate = page.locator( 'form[id="tracker:string:NewIssue"] div[class*="title"] > div > button' ) + this.inputPopupAddAttachmentsFile = page.locator('div.popup-tooltip input#file') + this.textPopupAddAttachmentsFile = page.locator('div.popup-tooltip div.item div.name') } async createNewIssue (data: NewIssue, closeNotification: boolean = false): Promise { @@ -128,8 +132,7 @@ export class IssuesPage extends CommonTrackerPage { } } if (data.filePath != null) { - await this.inputPopupCreateNewIssueFile.setInputFiles(path.join(__dirname, `../../files/${data.filePath}`)) - await expect(this.textPopupCreateNewIssueFile.filter({ hasText: data.filePath })).toBeVisible() + await this.attachFileToNewIssueForm(data.filePath) } if (data.parentIssue != null) { await this.buttonPopupCreateNewIssueParent.click() @@ -204,4 +207,40 @@ export class IssuesPage extends CommonTrackerPage { await this.buttonPopupCreateNewIssueTemplate.click() await this.selectMenuItem(this.page, templateName) } + + async attachFileToNewIssueForm (filePath: string): Promise { + await this.inputPopupCreateNewIssueFile.setInputFiles(path.join(__dirname, `../../files/${filePath}`)) + await expect(this.textPopupCreateNewIssueFile.filter({ hasText: filePath })).toBeVisible() + } + + async checkAttachmentsCount (issueName: string, count: string): Promise { + await expect( + this.page + .locator('div.row span', { hasText: issueName }) + .locator('xpath=..') + .locator('a > button > div[slot="content"]') + ).toHaveText(count) + } + + async addAttachmentToIssue (issueName: string, filePath: string): Promise { + await this.page.locator('div.row span', { hasText: issueName }).locator('xpath=..').locator('a > button').click() + await this.inputPopupAddAttachmentsFile.setInputFiles(path.join(__dirname, `../../files/${filePath}`)) + await expect(this.textPopupAddAttachmentsFile.filter({ hasText: filePath })).toBeVisible() + } + + async deleteAttachmentToIssue (issueName: string, filePath: string): Promise { + await this.page.locator('div.row span', { hasText: issueName }).locator('xpath=..').locator('a > button').click() + await this.page.locator(`div.popup-tooltip div.item div.name a[download="${filePath}"]`).hover() + await this.page + .locator(`div.popup-tooltip div.item div.name a[download="${filePath}"]`) + .locator('xpath=../..') + .locator('span.remove-link') + .click() + await expect(this.textPopupAddAttachmentsFile.filter({ hasText: filePath })).toBeVisible({ visible: false }) + } + + async checkAddAttachmentPopupContainsFile (issueName: string, filePath: string): Promise { + await this.page.locator('div.row span', { hasText: issueName }).locator('xpath=..').locator('a > button').click() + await expect(this.textPopupAddAttachmentsFile.filter({ hasText: filePath })).toBeVisible() + } } diff --git a/tests/sanity/tests/tracker/attachments.spec.ts b/tests/sanity/tests/tracker/attachments.spec.ts new file mode 100644 index 00000000000..47700420e60 --- /dev/null +++ b/tests/sanity/tests/tracker/attachments.spec.ts @@ -0,0 +1,69 @@ +import { test } from '@playwright/test' +import { allure } from 'allure-playwright' +import { IssuesPage } from '../model/tracker/issues-page' +import { generateId, PlatformSetting, PlatformURI } from '../utils' +import { TrackerNavigationMenuPage } from '../model/tracker/tracker-navigation-menu-page' +import { IssuesDetailsPage } from '../model/tracker/issues-details-page' +import { NewIssue } from '../model/tracker/types' +import { LeftSideMenuPage } from '../model/left-side-menu-page' + +test.use({ + storageState: PlatformSetting +}) + +test.describe('Attachments tests', () => { + test.beforeEach(async ({ page }) => { + await allure.parentSuite('Attachments tests') + await (await page.goto(`${PlatformURI}/workbench/sanity-ws`))?.finished() + }) + + test('Create issue with several attachment test', async ({ page }) => { + const newIssue: NewIssue = { + title: `Create issue with several attachment tests-${generateId()}`, + description: 'Create issue with several attachment tests description' + } + + const leftSideMenuPage = new LeftSideMenuPage(page) + await leftSideMenuPage.buttonTracker.click() + + const trackerNavigationMenuPage = new TrackerNavigationMenuPage(page) + await trackerNavigationMenuPage.openIssuesForProject('Default') + + const issuesPage = new IssuesPage(page) + await issuesPage.modelSelectorAll.click() + + await issuesPage.buttonCreateNewIssue.click() + await issuesPage.fillNewIssueForm(newIssue) + await issuesPage.attachFileToNewIssueForm('cat.jpeg') + await issuesPage.attachFileToNewIssueForm('cat2.jpeg') + await issuesPage.buttonCreateIssue.click() + + await issuesPage.searchIssueByName(newIssue.title) + await issuesPage.checkAttachmentsCount(newIssue.title, '2') + + await test.step('Add attachments in the popup', async () => { + await issuesPage.checkAddAttachmentPopupContainsFile(newIssue.title, 'cat.jpeg') + await issuesPage.checkAddAttachmentPopupContainsFile(newIssue.title, 'cat2.jpeg') + + await issuesPage.addAttachmentToIssue(newIssue.title, 'cat3.jpeg') + await issuesPage.checkAddAttachmentPopupContainsFile(newIssue.title, 'cat.jpeg') + await issuesPage.checkAddAttachmentPopupContainsFile(newIssue.title, 'cat2.jpeg') + + await issuesPage.checkAttachmentsCount(newIssue.title, '3') + }) + + await test.step('Delete attachments in the popup', async () => { + await issuesPage.deleteAttachmentToIssue(newIssue.title, 'cat2.jpeg') + await issuesPage.checkAddAttachmentPopupContainsFile(newIssue.title, 'cat.jpeg') + await issuesPage.checkAddAttachmentPopupContainsFile(newIssue.title, 'cat3.jpeg') + + await issuesPage.checkAttachmentsCount(newIssue.title, '2') + }) + + await issuesPage.openIssueByName(newIssue.title) + + const issuesDetailsPage = new IssuesDetailsPage(page) + await issuesDetailsPage.checkIssueContainsAttachment('cat.jpeg') + await issuesDetailsPage.checkIssueContainsAttachment('cat3.jpeg') + }) +})