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, clearMinDate, clearMaxDate, TestDateRanges } from '../helpers/date-picker.helper'; import { addProfitCenter, addProfitCenters, profitCenterConfig, TestAutocompleteData, getAutocompleteItemCount } from '../helpers/autocomplete.helper'; import { uploadFile, itemNumberConfig, getTestFile, TestFiles, getUploadedItemCount } from '../helpers/file-upload.helper'; import { assertNoErrorNotification, waitForNotification } from '../helpers/radzen.helper'; import { hasValidationErrors, submitAndExpectError, ValidationMessages } from '../helpers/validation.helper'; /** * Test suite for Search Type 60: Time Span + Profit Center + Item Number * * This search type allows users to find work orders within a specified date range, * filtered by profit center (branch code) and item number. * * Filters Enabled: * - Timespan (Min Date, Max Date) * - Profit Center * - Item Number (via file upload) */ test.describe('Search Type 60: Time Span + Profit Center + Item Number', () => { test.beforeEach(async ({ page }) => { await navigateToSearchPage(page); await selectSearchType(page, SearchTypes.TIMESPAN_PC_ITEM); }); test.describe('Positive Test Cases', () => { test('TC-060-P01: Single Profit Center and Single Item Number', async ({ page }) => { // Enter search name await enterSearchName(page, 'Type60 Single PC and Item Test'); // Set date range await setDateRange(page, '2018-01-01', '2019-12-31'); // Add profit center await addProfitCenter(page, '1PM'); // Upload item numbers file await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.SINGLE_ITEM)); // Verify no error notification await assertNoErrorNotification(page); // Verify item was uploaded const itemCount = await getUploadedItemCount(page, itemNumberConfig); expect(itemCount).toBeGreaterThan(0); // Submit search await clickSubmitSearch(page); await confirmSubmitSearch(page); // Verify success notification await waitForNotification(page, 'success', 10000); }); test('TC-060-P02: Multiple Profit Centers with Single Item Number', async ({ page }) => { await enterSearchName(page, 'Type60 Multiple PC Test'); await setDateRange(page, '2018-01-01', '2020-09-01'); // Add multiple profit centers await addProfitCenters(page, ['1AM', '1BM', '1CM']); // Upload single item file await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.SINGLE_ITEM)); // 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-060-P03: Single Profit Center with Multiple Item Numbers', async ({ page }) => { await enterSearchName(page, 'Type60 Multiple Items Test'); await setDateRange(page, '2019-01-01', '2019-12-31'); await addProfitCenter(page, '2DM'); // Upload multiple items file await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.MULTIPLE_ITEMS)); const itemCount = await getUploadedItemCount(page, itemNumberConfig); expect(itemCount).toBeGreaterThan(1); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); test('TC-060-P04: Multiple Profit Centers with Multiple Item Numbers', async ({ page }) => { await enterSearchName(page, 'Type60 Multiple PC and Items Test'); await setDateRange(page, '2018-01-01', '2020-09-01'); // Add multiple profit centers await addProfitCenters(page, ['1PM', '2SM', '3TM']); // Upload multiple items file await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.MULTIPLE_ITEMS)); const pcCount = await getAutocompleteItemCount(page, profitCenterConfig); expect(pcCount).toBe(3); const itemCount = await getUploadedItemCount(page, itemNumberConfig); expect(itemCount).toBeGreaterThan(1); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); test('TC-060-P05: Recent Date Range', async ({ page }) => { await enterSearchName(page, 'Type60 Recent Range Test'); await setDateRange(page, TestDateRanges.RECENT.min, TestDateRanges.RECENT.max); await addProfitCenter(page, '4IM'); await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.SINGLE_ITEM)); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); test('TC-060-P06: Historical Date Range', async ({ page }) => { await enterSearchName(page, 'Type60 Historical Range Test'); await setDateRange(page, TestDateRanges.HISTORICAL.min, TestDateRanges.HISTORICAL.max); await addProfitCenter(page, '5SM'); await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.SINGLE_ITEM)); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); test('TC-060-P07: Same Day Date Range', async ({ page }) => { await enterSearchName(page, 'Type60 Same Day Test'); await setDateRange(page, '2019-06-15', '2019-06-15'); await addProfitCenter(page, '1AM'); await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.SINGLE_ITEM)); await assertNoErrorNotification(page); await clickSubmitSearch(page); await confirmSubmitSearch(page); await waitForNotification(page, 'success', 10000); }); test('TC-060-P08: All Profit Centers', async ({ page }) => { await enterSearchName(page, 'Type60 All Profit Centers Test'); await setDateRange(page, '2018-01-01', '2020-09-01'); // Add all profit centers await addProfitCenters(page, TestAutocompleteData.profitCenters); await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.SINGLE_ITEM)); // 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.describe('Negative Test Cases', () => { test('TC-060-N01: Missing Search Name', async ({ page }) => { // Leave search name empty await setDateRange(page, '2018-01-01', '2019-12-31'); await addProfitCenter(page, '1PM'); await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.SINGLE_ITEM)); await submitAndExpectError(page); }); test('TC-060-N02: Missing Profit Center', async ({ page }) => { await enterSearchName(page, 'Type60 Missing PC Test'); await setDateRange(page, '2018-01-01', '2019-12-31'); // Do not add any profit centers await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.SINGLE_ITEM)); await submitAndExpectError(page); }); test('TC-060-N03: Missing Item Number', async ({ page }) => { await enterSearchName(page, 'Type60 Missing Item Test'); await setDateRange(page, '2018-01-01', '2019-12-31'); await addProfitCenter(page, '1PM'); // Do not upload any item numbers await submitAndExpectError(page); }); test('TC-060-N04: Missing Minimum Date', async ({ page }) => { await enterSearchName(page, 'Type60 Missing Min Date Test'); // Only set max date await setMaxDate(page, '2019-12-31'); await addProfitCenter(page, '1PM'); await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.SINGLE_ITEM)); await submitAndExpectError(page); }); test('TC-060-N05: Missing Maximum Date', async ({ page }) => { await enterSearchName(page, 'Type60 Missing Max Date Test'); // Only set min date await setMinDate(page, '2018-01-01'); await addProfitCenter(page, '1PM'); await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.SINGLE_ITEM)); await submitAndExpectError(page); }); test('TC-060-N06: Invalid Date Range (Min > Max)', async ({ page }) => { await enterSearchName(page, 'Type60 Invalid Date Range Test'); await setDateRange(page, TestDateRanges.INVALID_REVERSED.min, TestDateRanges.INVALID_REVERSED.max); await addProfitCenter(page, '1PM'); await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.SINGLE_ITEM)); await submitAndExpectError(page); }); test('TC-060-N07: Whitespace-Only Search Name', async ({ page }) => { await enterSearchName(page, ' '); await setDateRange(page, '2018-01-01', '2019-12-31'); await addProfitCenter(page, '1PM'); await uploadFile(page, itemNumberConfig, getTestFile(TestFiles.SINGLE_ITEM)); await submitAndExpectError(page); }); test('TC-060-N08: Missing All Required Filters', async ({ page }) => { await enterSearchName(page, 'Type60 No Filters Test'); // Leave minimum date empty // Leave maximum date empty // Do not add any profit centers // Do not add any item numbers await clickSubmitSearch(page); await page.waitForTimeout(1000); // Should have validation errors expect(await hasValidationErrors(page)).toBe(true); }); }); });