test: test case is added to Favourites

This commit is contained in:
tzhangchi
2022-12-24 23:07:19 +08:00
parent c2c272b3fe
commit 45e28d3dad
3 changed files with 119 additions and 2 deletions
@@ -44,7 +44,11 @@ const FavoriteTag = ({
toast(!favorite ? 'Removed to Favourites' : 'Added to Favourites');
}}
>
{favorite ? <FavouritedIcon /> : <FavouritesIcon />}
{favorite ? (
<FavouritedIcon data-testid="favourited-icon" />
) : (
<FavouritesIcon />
)}
</IconButton>
</Tooltip>
);
@@ -43,6 +43,7 @@ const FavoriteList = ({ showList }: { showList: boolean }) => {
const active = router.query.pageId === pageMeta.id;
return (
<StyledSubListItem
data-testid={`favorite-list-item-${pageMeta.id}`}
active={active}
key={`${pageMeta}-${index}`}
onClick={() => {
+113 -1
View File
@@ -4,7 +4,7 @@ import { loadPage } from './libs/load-page';
loadPage();
test.describe('Local first favorite page', () => {
test('New a page ,then open it and show favorite', async ({ page }) => {
test('New a page and open it ,then favorite ot', async ({ page }) => {
await page.getByText('New Page').click();
await page.getByPlaceholder('Title').click();
await page.getByPlaceholder('Title').fill('this is a new page to favorite');
@@ -29,4 +29,116 @@ test.describe('Local first favorite page', () => {
await favoriteBtn.click();
});
test('Show favorite items in sidebar', async ({ page }) => {
await page.getByText('New Page').click();
await page.getByPlaceholder('Title').click();
await page.getByPlaceholder('Title').fill('this is a new page to favorite');
const newPageId = page.url().split('/').reverse()[0];
await page.getByRole('link', { name: 'All pages' }).click();
const cell = await page.getByRole('cell', {
name: 'this is a new page to favorite',
});
expect(cell).not.toBeUndefined();
await cell.click();
await page
.getByTestId('editor-header-items')
.getByRole('button')
.nth(2)
.click();
const favoriteBtn = page.getByTestId('editor-option-menu-favorite');
await favoriteBtn.click();
const favoriteListItemInSidebar = await page.getByTestId(
'favorite-list-item-' + newPageId
);
expect(await favoriteListItemInSidebar.textContent()).toBe(
'this is a new page to favorite'
);
});
test('Show favorite items in favorite list', async ({ page }) => {
await page.getByText('New Page').click();
await page.getByPlaceholder('Title').click();
await page.getByPlaceholder('Title').fill('this is a new page to favorite');
await page.getByRole('link', { name: 'All pages' }).click();
const cell = await page.getByRole('cell', {
name: 'this is a new page to favorite',
});
expect(cell).not.toBeUndefined();
await cell.click();
await page
.getByTestId('editor-header-items')
.getByRole('button')
.nth(2)
.click();
const favoriteBtn = page.getByTestId('editor-option-menu-favorite');
await favoriteBtn.click();
await page.getByRole('link', { name: 'Favourites' }).click();
expect(
await page.getByRole('cell', { name: 'this is a new page to favorite' })
).not.toBeUndefined();
});
test('Cancel favorite', async ({ page }) => {
await page.getByText('New Page').click();
await page.getByPlaceholder('Title').click();
await page.getByPlaceholder('Title').fill('this is a new page to favorite');
await page.getByRole('link', { name: 'All pages' }).click();
const cell = await page.getByRole('cell', {
name: 'this is a new page to favorite',
});
expect(cell).not.toBeUndefined();
await cell.click();
await page
.getByTestId('editor-header-items')
.getByRole('button')
.nth(2)
.click();
const favoriteBtn = page.getByTestId('editor-option-menu-favorite');
await favoriteBtn.click();
// expect it in favorite list
await page.getByRole('link', { name: 'Favourites' }).click();
expect(
await page.getByRole('cell', { name: 'this is a new page to favorite' })
).not.toBeUndefined();
// cancel favorite
await page.getByRole('link', { name: 'All pages' }).click();
await page.getByTestId('favourited-icon').click();
//expect it not in favorite list
await page.getByRole('link', { name: 'Favourites' }).click();
expect(
await page.getByText(
'Tips: Click Add to Favourites/Trash and the page will appear here.'
)
).not.toBeUndefined();
});
});