08ea5fbe98
添加用户管理视图、API和状态管理文件
235 lines
7.6 KiB
TypeScript
235 lines
7.6 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
import { MiniProgramSearchPage } from '../pages/SearchPage';
|
|
|
|
test.describe('小程序搜索测试', () => {
|
|
let searchPage: MiniProgramSearchPage;
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
searchPage = new MiniProgramSearchPage(page);
|
|
await searchPage.navigate();
|
|
});
|
|
|
|
test('应该显示搜索输入框', async () => {
|
|
const searchInput = await page.$('.search-input input');
|
|
const isVisible = await searchInput?.isVisible();
|
|
expect(isVisible).toBe(true);
|
|
});
|
|
|
|
test('应该允许搜索', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.search(keyword);
|
|
const hasResults = await searchPage.hasResults();
|
|
expect(hasResults).toBe(true);
|
|
});
|
|
|
|
test('应该允许清除搜索', async () => {
|
|
await searchPage.search('test');
|
|
await searchPage.clearSearch();
|
|
const hasResults = await searchPage.hasResults();
|
|
expect(hasResults).toBe(false);
|
|
});
|
|
|
|
test('应该显示搜索结果', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.search(keyword);
|
|
const results = await searchPage.getSearchResults();
|
|
expect(Array.isArray(results)).toBe(true);
|
|
expect(results.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('应该显示结果数量', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.search(keyword);
|
|
const count = await searchPage.getResultCount();
|
|
expect(count).toBeGreaterThan(0);
|
|
});
|
|
|
|
test('应该显示无结果提示', async () => {
|
|
const keyword = 'xyz123';
|
|
await searchPage.search(keyword);
|
|
const noResults = await searchPage.noResults();
|
|
expect(noResults).toBe(true);
|
|
});
|
|
|
|
test('应该允许点击结果', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.search(keyword);
|
|
await searchPage.tapResult(0);
|
|
await page.waitForTimeout(1000);
|
|
const resultTitle = await searchPage.getResultTitle(0);
|
|
expect(resultTitle).toBeTruthy();
|
|
});
|
|
|
|
test('应该允许长按结果', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.search(keyword);
|
|
await searchPage.longPressResult(0);
|
|
await page.waitForTimeout(1000);
|
|
const resultTitle = await searchPage.getResultTitle(0);
|
|
expect(resultTitle).toBeTruthy();
|
|
});
|
|
|
|
test('应该显示结果标题', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.search(keyword);
|
|
const title = await searchPage.getResultTitle(0);
|
|
expect(title).toBeTruthy();
|
|
});
|
|
|
|
test('应该显示结果描述', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.search(keyword);
|
|
const description = await searchPage.getResultDescription(0);
|
|
expect(description).toBeTruthy();
|
|
});
|
|
|
|
test('应该显示结果日期', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.search(keyword);
|
|
const date = await searchPage.getResultDate(0);
|
|
expect(date).toBeTruthy();
|
|
});
|
|
|
|
test('应该允许按类型筛选', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.search(keyword);
|
|
await searchPage.filterByType('holiday');
|
|
const results = await searchPage.getSearchResults();
|
|
expect(Array.isArray(results)).toBe(true);
|
|
});
|
|
|
|
test('应该允许按日期范围筛选', async () => {
|
|
const startDate = '2026-01-01';
|
|
const endDate = '2026-12-31';
|
|
await searchPage.filterByDate(startDate, endDate);
|
|
const results = await searchPage.getSearchResults();
|
|
expect(Array.isArray(results)).toBe(true);
|
|
});
|
|
|
|
test('应该允许排序', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.search(keyword);
|
|
await searchPage.sortBy('date');
|
|
const currentSort = await searchPage.getCurrentSort();
|
|
expect(currentSort).toContain('date');
|
|
});
|
|
|
|
test('应该显示活动筛选器', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.search(keyword);
|
|
await searchPage.filterByType('holiday');
|
|
const activeFilters = await searchPage.getActiveFilters();
|
|
expect(Array.isArray(activeFilters)).toBe(true);
|
|
});
|
|
|
|
test('应该允许清除筛选器', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.search(keyword);
|
|
await searchPage.filterByType('holiday');
|
|
await searchPage.clearFilters();
|
|
const activeFilters = await searchPage.getActiveFilters();
|
|
expect(activeFilters.length).toBe(0);
|
|
});
|
|
|
|
test('应该允许保存搜索', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.saveSearch(keyword);
|
|
const savedSearches = await searchPage.getSavedSearches();
|
|
expect(savedSearches).toContain(keyword);
|
|
});
|
|
|
|
test('应该显示保存的搜索', async () => {
|
|
const savedSearches = await searchPage.getSavedSearches();
|
|
expect(Array.isArray(savedSearches)).toBe(true);
|
|
});
|
|
|
|
test('应该允许删除保存的搜索', async () => {
|
|
const keyword = '春节';
|
|
await searchPage.saveSearch(keyword);
|
|
await searchPage.deleteSavedSearch(keyword);
|
|
const savedSearches = await searchPage.getSavedSearches();
|
|
expect(savedSearches).not.toContain(keyword);
|
|
});
|
|
|
|
test('应该显示最近搜索', async () => {
|
|
const keyword = 'test';
|
|
await searchPage.search(keyword);
|
|
const recentSearches = await searchPage.getRecentSearches();
|
|
expect(Array.isArray(recentSearches)).toBe(true);
|
|
});
|
|
|
|
test('应该允许清除最近搜索', async () => {
|
|
await searchPage.clearRecentSearches();
|
|
const recentSearches = await searchPage.getRecentSearches();
|
|
expect(recentSearches.length).toBe(0);
|
|
});
|
|
|
|
test('应该显示搜索建议', async () => {
|
|
const keyword = '春';
|
|
const suggestions = await searchPage.getSearchSuggestions(keyword);
|
|
expect(Array.isArray(suggestions)).toBe(true);
|
|
});
|
|
|
|
test('应该允许选择建议', async () => {
|
|
const keyword = '春';
|
|
await searchPage.selectSuggestion(0);
|
|
const hasResults = await searchPage.hasResults();
|
|
expect(hasResults).toBe(true);
|
|
});
|
|
|
|
test('应该允许左滑', async ({ page }) => {
|
|
await searchPage.swipeLeft();
|
|
await page.waitForTimeout(500);
|
|
const searchInput = await page.$('.search-input input');
|
|
const isVisible = await searchInput?.isVisible();
|
|
expect(isVisible).toBe(true);
|
|
});
|
|
|
|
test('应该允许右滑', async ({ page }) => {
|
|
await searchPage.swipeRight();
|
|
await page.waitForTimeout(500);
|
|
const searchInput = await page.$('.search-input input');
|
|
const isVisible = await searchInput?.isVisible();
|
|
expect(isVisible).toBe(true);
|
|
});
|
|
|
|
test('应该允许上滑', async ({ page }) => {
|
|
await searchPage.swipeUp();
|
|
await page.waitForTimeout(500);
|
|
const searchInput = await page.$('.search-input input');
|
|
const isVisible = await searchInput?.isVisible();
|
|
expect(isVisible).toBe(true);
|
|
});
|
|
|
|
test('应该允许下滑', async ({ page }) => {
|
|
await searchPage.swipeDown();
|
|
await page.waitForTimeout(500);
|
|
const searchInput = await page.$('.search-input input');
|
|
const isVisible = await searchInput?.isVisible();
|
|
expect(isVisible).toBe(true);
|
|
});
|
|
|
|
test('应该显示搜索历史', async () => {
|
|
const searchHistory = await searchPage.getSearchHistory();
|
|
expect(Array.isArray(searchHistory)).toBe(true);
|
|
});
|
|
|
|
test('应该允许清除搜索历史', async () => {
|
|
await searchPage.clearSearchHistory();
|
|
const searchHistory = await searchPage.getSearchHistory();
|
|
expect(searchHistory.length).toBe(0);
|
|
});
|
|
|
|
test('应该显示热门搜索', async () => {
|
|
const hotSearches = await searchPage.getHotSearches();
|
|
expect(Array.isArray(hotSearches)).toBe(true);
|
|
});
|
|
|
|
test('应该允许点击热门搜索', async () => {
|
|
await searchPage.tapHotSearch(0);
|
|
await page.waitForTimeout(500);
|
|
const hasResults = await searchPage.hasResults();
|
|
expect(hasResults).toBe(true);
|
|
});
|
|
});
|