mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
[ACS-7334] [E2E] Search filters - date - tests migrated to Playwright (#3770)
* [ACS-7334] [E2E] Search filters - date - tests migrated to Playwright * [ACS-7334] sonar cloud fix 1 * [ACS-7334] review fix 1 * [ACS-7334] review fix 2
This commit is contained in:
@@ -23,7 +23,22 @@
|
||||
*/
|
||||
|
||||
import { BaseComponent } from '../../base.component';
|
||||
import { Page } from '@playwright/test';
|
||||
import { Page, expect } from '@playwright/test';
|
||||
import { SearchPage, SearchType } from '@alfresco/playwright-shared';
|
||||
|
||||
type FilterTab = 'Created' | 'Modified';
|
||||
|
||||
interface FilterFilesByDateParams {
|
||||
searchPage: SearchPage;
|
||||
filterType: 'anytime' | 'inTheLast' | 'between';
|
||||
dateFilterTab: FilterTab;
|
||||
searchPhrase: string;
|
||||
searchType: SearchType;
|
||||
expectSearchResults: number;
|
||||
inTheLastInputValue?: string;
|
||||
startDay?: string;
|
||||
endDay?: string;
|
||||
}
|
||||
|
||||
export class SearchFiltersDate extends BaseComponent {
|
||||
private static rootElement = '.adf-search-filter-menu-card';
|
||||
@@ -34,11 +49,94 @@ export class SearchFiltersDate extends BaseComponent {
|
||||
|
||||
public createdTab = this.getChild(`[role='tab']`, { hasText: 'Created' });
|
||||
public modifiedTab = this.getChild(`[role='tab']`, { hasText: 'Modified' });
|
||||
public createdTabTitle = this.createdTab.locator(`div`);
|
||||
public modifiedTabTitle = this.modifiedTab.locator(`div`);
|
||||
public anytimeButton = this.getChild(`[data-automation-id$='date-range-anytime']`);
|
||||
public anytimeRadioButton = this.anytimeButton.locator(`input`);
|
||||
public inTheLastButton = this.getChild(`[data-automation-id$='date-range-in-last']`);
|
||||
public inTheLastInput = this.getChild(`[data-automation-id$='date-range-in-last-input']`);
|
||||
public inTheLastDropdown = this.getChild(`[data-automation-id$='date-range-in-last-dropdown']`);
|
||||
public betweenButton = this.getChild(`[data-automation-id$='date-range-between']`);
|
||||
public betweenRadioButton = this.betweenButton.locator(`input`);
|
||||
public betweenStartDate = this.getChild(`[data-automation-id$='date-range-between-start-input']`);
|
||||
public betweenEndDate = this.getChild(`[data-automation-id$='date-range-between-end-input']`);
|
||||
|
||||
async openCreatedModifiedTab(page: SearchPage, tab: FilterTab): Promise<void> {
|
||||
switch (tab) {
|
||||
case 'Created':
|
||||
await page.searchFiltersDate.createdTab.click();
|
||||
break;
|
||||
case 'Modified':
|
||||
await page.searchFiltersDate.modifiedTab.click();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
await page.page.waitForTimeout(2000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used in cases where we want to filter search results by Date
|
||||
*
|
||||
* @param searchPage page context for the test
|
||||
* @param filterType filter type for the Date filter
|
||||
* @param dateFilterTab tab in Date filter. Either Created or Modified
|
||||
* @param searchPhrase search phrase for the search
|
||||
* @param searchType type of items we want in search results e.g. files or folders
|
||||
* @param expectSearchResults expect a number of search results
|
||||
* @param inTheLastInputValue a value for 'in the last' input. e.g. in the last X days
|
||||
* @param startDay start day for time-frame search. DD-MMMM-YY
|
||||
* @param endDay end day for time-frame search. DD-MMMM-YY
|
||||
*/
|
||||
async filterFilesByDate(params: FilterFilesByDateParams) {
|
||||
const {
|
||||
searchPage,
|
||||
filterType,
|
||||
dateFilterTab,
|
||||
searchPhrase,
|
||||
searchType,
|
||||
expectSearchResults,
|
||||
inTheLastInputValue,
|
||||
startDay,
|
||||
endDay
|
||||
} = params;
|
||||
|
||||
await searchPage.searchWithin(searchPhrase, searchType);
|
||||
await searchPage.searchFilters.dateFilter.click();
|
||||
|
||||
if (dateFilterTab === 'Modified') {
|
||||
await searchPage.searchFiltersDate.openCreatedModifiedTab(searchPage, 'Modified');
|
||||
}
|
||||
|
||||
switch (filterType) {
|
||||
case 'anytime':
|
||||
await searchPage.searchFiltersDate.anytimeButton.click();
|
||||
break;
|
||||
case 'inTheLast':
|
||||
await searchPage.searchFiltersDate.inTheLastButton.click();
|
||||
await searchPage.searchFiltersDate.inTheLastInput.fill(inTheLastInputValue);
|
||||
break;
|
||||
case 'between':
|
||||
await searchPage.searchFiltersDate.betweenButton.click();
|
||||
await searchPage.searchFiltersDate.betweenStartDate.fill(startDay);
|
||||
await searchPage.searchFiltersDate.betweenEndDate.fill(endDay);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Invalid filter type');
|
||||
}
|
||||
|
||||
await searchPage.searchFilters.menuCardApply.click();
|
||||
await searchPage.dataTable.spinnerWaitForReload();
|
||||
expect(await searchPage.dataTable.getRowsCount()).toEqual(expectSearchResults);
|
||||
|
||||
let dateText: string;
|
||||
if (filterType === 'between') {
|
||||
if (dateFilterTab === 'Modified') {
|
||||
dateText = `Modified: ${startDay} - ${endDay}`;
|
||||
} else {
|
||||
dateText = `Created: ${startDay} - ${endDay}`;
|
||||
}
|
||||
await expect(searchPage.searchFilters.dateFilter).toContainText(dateText, { ignoreCase: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,11 +24,26 @@
|
||||
|
||||
import { Page } from '@playwright/test';
|
||||
import { BasePage } from './base.page';
|
||||
import { DataTableComponent, MatMenuComponent, ViewerComponent, SearchInputComponent, SearchOverlayComponent, SidenavComponent, SearchSortingPicker, SearchFilters, SearchFiltersTags, SearchFiltersCategories, SearchFiltersDate, SearchFiltersLocation, SearchFiltersLogic, SearchFiltersProperties } from '../components';
|
||||
import {
|
||||
DataTableComponent,
|
||||
MatMenuComponent,
|
||||
ViewerComponent,
|
||||
SearchInputComponent,
|
||||
SearchOverlayComponent,
|
||||
SidenavComponent,
|
||||
SearchSortingPicker,
|
||||
SearchFilters,
|
||||
SearchFiltersTags,
|
||||
SearchFiltersCategories,
|
||||
SearchFiltersDate,
|
||||
SearchFiltersLocation,
|
||||
SearchFiltersLogic,
|
||||
SearchFiltersProperties
|
||||
} from '../components';
|
||||
import { AcaHeader } from '../components/aca-header.component';
|
||||
import { AdfConfirmDialogComponent, AdfFolderDialogComponent } from '../components/dialogs';
|
||||
|
||||
type SearchType = 'files' | 'folders' | 'filesAndFolders' | 'libraries';
|
||||
export type SearchType = 'files' | 'folders' | 'filesAndFolders' | 'libraries';
|
||||
|
||||
export class SearchPage extends BasePage {
|
||||
private static pageUrl = 'search';
|
||||
|
@@ -26,6 +26,7 @@ const crypto = require('crypto');
|
||||
import * as path from 'path';
|
||||
import { LoginPage, MyLibrariesPage, PersonalFilesPage, FavoritesLibrariesPage, SearchPage, SharedPage, TrashPage } from '../';
|
||||
import { NodesApi, TrashcanApi, SitesApi } from '@alfresco/playwright-shared';
|
||||
import { format, subDays, subMonths, endOfMonth } from 'date-fns';
|
||||
|
||||
export class Utils {
|
||||
static string257Long = 'x'.repeat(257);
|
||||
@@ -105,9 +106,9 @@ export class Utils {
|
||||
errorMessage = 'reloadPageIfRowNotVisible Error '
|
||||
): Promise<void> {
|
||||
try {
|
||||
if (!await pageContext.dataTable.getRowByName(nodeName).isVisible()) {
|
||||
if (!(await pageContext.dataTable.getRowByName(nodeName).isVisible())) {
|
||||
await pageContext.page.reload({ waitUntil: 'load' });
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`${errorMessage}: ${error}`);
|
||||
}
|
||||
@@ -118,11 +119,31 @@ export class Utils {
|
||||
errorMessage = 'reloadPageIfDatatableEmpty Error '
|
||||
): Promise<void> {
|
||||
try {
|
||||
if (await pageContext.dataTable.getEmptyFolderLocator.isVisible() || await pageContext.dataTable.emptyListTitle.isVisible()) {
|
||||
if ((await pageContext.dataTable.getEmptyFolderLocator.isVisible()) || (await pageContext.dataTable.emptyListTitle.isVisible())) {
|
||||
await pageContext.page.reload({ waitUntil: 'load' });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`${errorMessage}: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
static getCurrentAndPreviousDay(currentDate = new Date()): { currentDate: string; previousDate: string } {
|
||||
let formattedDate: string;
|
||||
let formattedDate2: string;
|
||||
|
||||
const formatDate = (date: Date): string => {
|
||||
return format(date, 'dd-MMM-yy').toUpperCase();
|
||||
};
|
||||
|
||||
if (currentDate.getDate() === 1) {
|
||||
const lastDayOfPreviousMonth: Date = endOfMonth(subMonths(currentDate, 1));
|
||||
formattedDate = formatDate(lastDayOfPreviousMonth);
|
||||
formattedDate2 = formatDate(subDays(lastDayOfPreviousMonth, 1));
|
||||
} else {
|
||||
formattedDate = formatDate(currentDate);
|
||||
formattedDate2 = formatDate(subDays(currentDate, 1));
|
||||
}
|
||||
|
||||
return { currentDate: formattedDate, previousDate: formattedDate2 };
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user