mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-01 17:39:55 +08:00
test: test case is added to Favourites
This commit is contained in:
@@ -44,7 +44,11 @@ const FavoriteTag = ({
|
|||||||
toast(!favorite ? 'Removed to Favourites' : 'Added to Favourites');
|
toast(!favorite ? 'Removed to Favourites' : 'Added to Favourites');
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{favorite ? <FavouritedIcon /> : <FavouritesIcon />}
|
{favorite ? (
|
||||||
|
<FavouritedIcon data-testid="favourited-icon" />
|
||||||
|
) : (
|
||||||
|
<FavouritesIcon />
|
||||||
|
)}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ const FavoriteList = ({ showList }: { showList: boolean }) => {
|
|||||||
const active = router.query.pageId === pageMeta.id;
|
const active = router.query.pageId === pageMeta.id;
|
||||||
return (
|
return (
|
||||||
<StyledSubListItem
|
<StyledSubListItem
|
||||||
|
data-testid={`favorite-list-item-${pageMeta.id}`}
|
||||||
active={active}
|
active={active}
|
||||||
key={`${pageMeta}-${index}`}
|
key={`${pageMeta}-${index}`}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { loadPage } from './libs/load-page';
|
|||||||
loadPage();
|
loadPage();
|
||||||
|
|
||||||
test.describe('Local first favorite page', () => {
|
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.getByText('New Page').click();
|
||||||
await page.getByPlaceholder('Title').click();
|
await page.getByPlaceholder('Title').click();
|
||||||
await page.getByPlaceholder('Title').fill('this is a new page to favorite');
|
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();
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user