import { test, expect } from '@playwright/test'; import { navigateToSearchPage } from '../helpers/navigation.helper'; import { selectSearchType, SearchTypes, enterSearchName, clickSubmitSearch, confirmSubmitSearch } from '../helpers/search-type.helper'; import { setDateRange, setMinDate, setMaxDate, TestDateRanges } from '../helpers/date-picker.helper'; import { addProfitCenter, addProfitCenters, addOperator, addOperators, profitCenterConfig, operatorConfig, TestAutocompleteData, getAutocompleteItemCount } from '../helpers/autocomplete.helper'; import { assertNoErrorNotification, waitForNotification } from '../helpers/radzen.helper'; import { hasValidationErrors, submitAndExpectError } from '../helpers/validation.helper'; /** * Test suite for Search Type 160: Time Span + Profit Center + Operator * * This search type combines Time Span, Profit Center, and Operator filters. * It allows users to search for work order data within a specific date range, * filtered by profit center (branch code) and operator (user ID). * * Filters Enabled: * - Timespan (Start Date, End Date) * - Profit Center (via autocomplete) * - Operator (via autocomplete) */ test.describe('Search Type 160: Time Span + Profit Center + Operator', () => { test.beforeEach(async ({ page }) => { await navigateToSearchPage(page); await selectSearchType(page, SearchTypes.TIMESPAN_PC_OPERATOR); }); test.describe('Positive Test Cases', () => { test('TC-160-P01: Single Profit Center and Single Operator', async ({ page }) => { // Enter search name await enterSearchName(page, 'TC-160-P01 Single Values'); // Set date range await setDateRange(page, '2019-01-01', '2019-12-31'); // Add profit center await addProfitCenter(page, '1CM'); // Add operator await addOperator(page, 'ALEXIUCG'); // Verify no error notification await assertNoErrorNotification(page); // Verify items were added const pcCount = await getAutocompleteItemCount(page, profitCenterConfig); expect(pcCount).toBe(1); const opCount = await getAutocompleteItemCount(page, operatorConfig); expect(opCount).toBe(1); // Submit search await clickSubmitSearch(page); await confirmSubmitSearch(page); // Verify success notification await waitForNotification(page, 'success', 10000); }); test('TC-160-P02: Multiple Profit Centers with Single Operator', async ({ page }) => { await enterSearchName(page, 'TC-160-P02 Multiple Profit Centers'); await setDateRange(page, '2018-01-01', '2019-12-31'); // Add multiple profit centers await addProfitCenters(page, ['1AM', '1BM', '1CM']); // Add single operator await addOperator(page, 'ADAMSSN'); // Verify all profit centers were added const pcCount = await getAutocompleteItemCount(page, profitCenterConfig); expect(pcCount).toBe(3); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); test('TC-160-P03: Single Profit Center with Multiple Operators', async ({ page }) => { await enterSearchName(page, 'TC-160-P03 Multiple Operators'); await setDateRange(page, '2019-01-01', '2020-09-01'); await addProfitCenter(page, '1PM'); // Add multiple operators await addOperators(page, ['AGNEWA', 'AGNEWL', 'ALASMARB']); // Verify all operators were added const opCount = await getAutocompleteItemCount(page, operatorConfig); expect(opCount).toBe(3); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); test('TC-160-P04: Multiple Profit Centers and Multiple Operators', async ({ page }) => { await enterSearchName(page, 'TC-160-P04 Multiple All'); await setDateRange(page, '2018-01-01', '2020-09-01'); // Add multiple profit centers await addProfitCenters(page, ['2DM', '2SM']); // Add multiple operators await addOperators(page, ['ALLENHY', 'ALLENNI']); const pcCount = await getAutocompleteItemCount(page, profitCenterConfig); expect(pcCount).toBe(2); const opCount = await getAutocompleteItemCount(page, operatorConfig); expect(opCount).toBe(2); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); test('TC-160-P05: Recent Date Range', async ({ page }) => { await enterSearchName(page, 'TC-160-P05 Recent Range'); await setDateRange(page, TestDateRanges.RECENT.min, TestDateRanges.RECENT.max); await addProfitCenter(page, '3TM'); await addOperator(page, 'ALURUM'); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); test('TC-160-P06: Historical Date Range', async ({ page }) => { await enterSearchName(page, 'TC-160-P06 Historical Range'); await setDateRange(page, TestDateRanges.HISTORICAL.min, TestDateRanges.HISTORICAL.max); await addProfitCenter(page, '4IM'); await addOperator(page, 'ALVESM1'); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); test('TC-160-P07: Narrow Date Range (Single Month)', async ({ page }) => { await enterSearchName(page, 'TC-160-P07 Single Month'); await setDateRange(page, '2019-06-01', '2019-06-30'); await addProfitCenter(page, '5SM'); await addOperator(page, 'APONTEVE'); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); test('TC-160-P08: All Profit Centers', async ({ page }) => { await enterSearchName(page, 'TC-160-P08 All Profit Centers'); await setDateRange(page, '2019-01-01', '2019-12-31'); // Add all profit centers await addProfitCenters(page, TestAutocompleteData.profitCenters); await addOperator(page, 'ADAMSSN'); // Verify all 9 profit centers were added const pcCount = await getAutocompleteItemCount(page, profitCenterConfig); expect(pcCount).toBe(9); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); test('TC-160-P09: Many Operators', async ({ page }) => { await enterSearchName(page, 'TC-160-P09 Many Operators'); await setDateRange(page, '2018-01-01', '2020-09-01'); await addProfitCenter(page, '1CM'); // Add multiple operators await addOperators(page, ['ADAMSSN', 'AGNEWA', 'AGNEWL', 'ALASMARB', 'ALEXIUCG']); // Verify all 5 operators were added const opCount = await getAutocompleteItemCount(page, operatorConfig); expect(opCount).toBe(5); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); test('TC-160-P10: Same Start and End Date', async ({ page }) => { await enterSearchName(page, 'TC-160-P10 Same Day'); await setDateRange(page, '2019-07-15', '2019-07-15'); await addProfitCenter(page, '1PM'); await addOperator(page, 'ADAMSSN'); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); }); test.describe('Negative Test Cases', () => { test('TC-160-N01: Missing Date Range', async ({ page }) => { await enterSearchName(page, 'TC-160-N01 No Dates'); // Leave minimum date empty // Leave maximum date empty await addProfitCenter(page, '1CM'); await addOperator(page, 'ALEXIUCG'); await submitAndExpectError(page); }); test('TC-160-N02: Missing Profit Center', async ({ page }) => { await enterSearchName(page, 'TC-160-N02 No Profit Center'); await setDateRange(page, '2019-01-01', '2019-12-31'); // Do not add any profit center await addOperator(page, 'ALEXIUCG'); await submitAndExpectError(page); }); test('TC-160-N03: Missing Operator', async ({ page }) => { await enterSearchName(page, 'TC-160-N03 No Operator'); await setDateRange(page, '2019-01-01', '2019-12-31'); await addProfitCenter(page, '1CM'); // Do not add any operator await submitAndExpectError(page); }); test('TC-160-N04: Start Date After End Date', async ({ page }) => { await enterSearchName(page, 'TC-160-N04 Invalid Date Range'); await setDateRange(page, TestDateRanges.INVALID_REVERSED.min, TestDateRanges.INVALID_REVERSED.max); await addProfitCenter(page, '1CM'); await addOperator(page, 'ALEXIUCG'); await submitAndExpectError(page); }); test('TC-160-N05: Missing Search Name', async ({ page }) => { // Leave search name empty await setDateRange(page, '2019-01-01', '2019-12-31'); await addProfitCenter(page, '1CM'); await addOperator(page, 'ALEXIUCG'); await submitAndExpectError(page); }); test('TC-160-N06: Missing Start Date Only', async ({ page }) => { await enterSearchName(page, 'TC-160-N06 No Start Date'); // Leave minimum date empty await setMaxDate(page, '2019-12-31'); await addProfitCenter(page, '1CM'); await addOperator(page, 'ALEXIUCG'); await submitAndExpectError(page); }); test('TC-160-N07: Missing End Date Only', async ({ page }) => { await enterSearchName(page, 'TC-160-N07 No End Date'); await setMinDate(page, '2019-01-01'); // Leave maximum date empty await addProfitCenter(page, '1CM'); await addOperator(page, 'ALEXIUCG'); await submitAndExpectError(page); }); test('TC-160-N08: Whitespace-Only Search Name', async ({ page }) => { await enterSearchName(page, ' '); await setDateRange(page, '2019-01-01', '2019-12-31'); await addProfitCenter(page, '1CM'); await addOperator(page, 'ALEXIUCG'); await submitAndExpectError(page); }); test('TC-160-N09: Missing Profit Center and Operator', async ({ page }) => { await enterSearchName(page, 'TC-160-N09 No PC or Operator'); await setDateRange(page, '2019-01-01', '2019-12-31'); // Do not add any profit center // Do not add any operator await clickSubmitSearch(page); await page.waitForTimeout(1000); // Should have validation errors expect(await hasValidationErrors(page)).toBe(true); }); test('TC-160-N10: Missing All Required Filters', async ({ page }) => { await enterSearchName(page, 'TC-160-N10 No Filters'); // Leave minimum date empty // Leave maximum date empty // Do not add any profit centers // Do not add any operators await clickSubmitSearch(page); await page.waitForTimeout(1000); // Should have validation errors expect(await hasValidationErrors(page)).toBe(true); }); }); });