Skip to content

Commit

Permalink
Add test for filtering companies
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Manakov <[email protected]>
  • Loading branch information
skefir committed Nov 5, 2024
1 parent d270572 commit 61b89cb
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
15 changes: 12 additions & 3 deletions tests/sanity/tests/model/common-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ export class CommonPage {
buttonFilterApply = (): Locator => this.page.locator('div.selectPopup button[type="button"]', { hasText: 'Apply' })
buttonClearFilters = (): Locator => this.page.locator('button > span', { hasText: 'Clear filters' })
filterButton = (index: number): Locator => this.page.locator(`div.filter-section button:nth-child(${index})`)
filterRow = (): Locator => this.page.locator('div.filterbar-container')
selectFilterSection = (label: string): Locator =>
this.page.locator('div.filterbar-container div.filter-section', { hasText: label })
this.filterRow().locator('div.filter-section', { hasText: label })

filterCloseButton = (label: string): Locator => this.selectFilterSection(label).locator('button .btn-icon')

addFilterButton = (): Locator => this.filterRow().locator('div.add-filter')

selectPopupMenu = (filter: string): Locator =>
this.page.locator('div.selectPopup [class*="menu"]', { hasText: filter })
Expand Down Expand Up @@ -216,8 +221,8 @@ export class CommonPage {
await this.menuPopupItemButton(itemText).first().click()
}

async selectFilter (filter: string, filterSecondLevel?: string): Promise<void> {
await this.buttonFilter().click()
async selectFilter (filter: string, filterSecondLevel?: string, addButton: Locator = this.buttonFilter()): Promise<void> {
await addButton.click()
await this.selectPopupMenu(filter).click()

if (filterSecondLevel !== null && typeof filterSecondLevel === 'string') {
Expand Down Expand Up @@ -325,4 +330,8 @@ export class CommonPage {
async pressEscape (): Promise<void> {
await this.page.keyboard.press('Escape')
}

async removeFilterOption (label: string): Promise<void> {
await this.filterCloseButton(label).click()
}
}
16 changes: 14 additions & 2 deletions tests/sanity/tests/model/recruiting/companies-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export class CompaniesPage extends CommonRecruitingPage {
readonly inputCreateOrganizationModalCreate = (): Locator =>
this.page.locator('form[id="contact:string:CreateOrganization"] button[type="submit"]')

readonly companyByName = (companyName: string): Locator => this.page.locator('tr a', { hasText: companyName })
readonly companyPanel = (): Locator =>
this.page.locator('xpath=//div[@data-id="contentPanel" and .//button[.//text()="Company"]]')

readonly companyByName = (companyName: string): Locator =>
this.companyPanel().locator('tr a', { hasText: companyName })

async createNewCompany (data: NewCompany): Promise<void> {
await expect(this.pageHeader()).toBeVisible()
Expand All @@ -43,7 +47,15 @@ export class CompaniesPage extends CommonRecruitingPage {
await this.companyByName(companyName).click()
}

async checkCompanyRowCount (companyName: string, count: number = 0): Promise<void> {
await expect(this.companyByName(companyName)).toHaveCount(count)
}

async checkCompanyNotExist (companyName: string): Promise<void> {
await expect(this.companyByName(companyName)).toHaveCount(0)
await this.checkCompanyRowCount(companyName)
}

async checkCompanyExist (companyName: string): Promise<void> {
await this.checkCompanyRowCount(companyName, 1)
}
}
33 changes: 33 additions & 0 deletions tests/sanity/tests/recruiting/companies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NavigationMenuPage } from '../model/recruiting/navigation-menu-page'
import { CompaniesPage } from '../model/recruiting/companies-page'
import { NewCompany } from '../model/recruiting/types'
import { CompanyDetailsPage } from '../model/recruiting/company-details-page'
import { DEFAULT_USER } from '../tracker/tracker.utils'

test.use({
storageState: PlatformSetting
Expand Down Expand Up @@ -86,4 +87,36 @@ test.describe('Companies tests', () => {
await navigationMenuPage.clickButtonCompanies()
await companiesPage.checkCompanyNotExist(deleteCompany.name)
})

test('Filtering companies', async ({ page }) => {
const firstCompany: NewCompany = {
name: `Company for filtering one-${generateId()}`
}
const secondCompany: NewCompany = {
name: `Company for filtering two-${generateId()}`
}
await test.step('Create companies', async () => {
await navigationMenuPage.clickButtonCompanies()
await companiesPage.createNewCompany(firstCompany)
await companiesPage.checkCompanyExist(firstCompany.name)
await companiesPage.createNewCompany(secondCompany)
await companiesPage.checkCompanyExist(secondCompany.name)
})
await test.step('Filtering by creator', async () => {
await companiesPage.selectFilter('Created by', DEFAULT_USER)
await companiesPage.pressEscape()
await companiesPage.checkCompanyExist(firstCompany.name)
await companiesPage.checkCompanyExist(secondCompany.name)
})
await test.step('Filtering by name', async () => {
await companiesPage.selectFilter('Name', firstCompany.name, companiesPage.addFilterButton())
await companiesPage.checkCompanyExist(firstCompany.name)
await companiesPage.checkCompanyNotExist(secondCompany.name)
})
await test.step('Remove name filter', async () => {
await companiesPage.removeFilterOption('Name')
await companiesPage.checkCompanyExist(firstCompany.name)
await companiesPage.checkCompanyExist(secondCompany.name)
})
})
})

0 comments on commit 61b89cb

Please sign in to comment.