chore: add test for all collection and all tag (#7687)

This commit is contained in:
JimmFly
2024-08-13 08:19:54 +00:00
parent d4065fee78
commit ba5ba71f35
6 changed files with 92 additions and 7 deletions

View File

@@ -19,7 +19,11 @@ export const CollectionListHeader = ({
<div className={styles.collectionListHeaderTitle}> <div className={styles.collectionListHeaderTitle}>
{t['com.affine.collections.header']()} {t['com.affine.collections.header']()}
</div> </div>
<Button className={styles.newCollectionButton} onClick={onCreate}> <Button
className={styles.newCollectionButton}
onClick={onCreate}
data-testid="all-collection-new-button"
>
{t['com.affine.collections.empty.new-collection-button']()} {t['com.affine.collections.empty.new-collection-button']()}
</Button> </Button>
</div> </div>

View File

@@ -481,6 +481,7 @@ export const CollectionOperationCell = ({
</MenuIcon> </MenuIcon>
} }
type="danger" type="danger"
data-testid="delete-collection"
> >
{t['Delete']()} {t['Delete']()}
</MenuItem> </MenuItem>
@@ -490,7 +491,7 @@ export const CollectionOperationCell = ({
align: 'end', align: 'end',
}} }}
> >
<IconButton> <IconButton data-testid="collection-item-operation-button">
<MoreVerticalIcon /> <MoreVerticalIcon />
</IconButton> </IconButton>
</Menu> </Menu>
@@ -560,6 +561,7 @@ export const TagOperationCell = ({
} }
type="danger" type="danger"
onSelect={handleDelete} onSelect={handleDelete}
data-testid="delete-tag"
> >
{t['Delete']()} {t['Delete']()}
</MenuItem> </MenuItem>
@@ -568,7 +570,7 @@ export const TagOperationCell = ({
align: 'end', align: 'end',
}} }}
> >
<IconButton> <IconButton data-testid="tag-item-operation-button">
<MoreVerticalIcon /> <MoreVerticalIcon />
</IconButton> </IconButton>
</Menu> </Menu>

View File

@@ -134,7 +134,11 @@ export const CreateOrEditTag = ({
} }
return ( return (
<div className={styles.createTagWrapper} data-show={open}> <div
className={styles.createTagWrapper}
data-show={open}
data-testid="edit-tag-modal"
>
<Menu <Menu
rootOptions={{ rootOptions={{
open: menuOpen, open: menuOpen,
@@ -154,11 +158,17 @@ export const CreateOrEditTag = ({
value={tagName} value={tagName}
onChange={handleChangeName} onChange={handleChangeName}
autoFocus autoFocus
data-testid="edit-tag-input"
/> />
<Button className={styles.cancelBtn} onClick={onClose}> <Button className={styles.cancelBtn} onClick={onClose}>
{t['Cancel']()} {t['Cancel']()}
</Button> </Button>
<Button variant="primary" onClick={onConfirm} disabled={!tagName}> <Button
variant="primary"
onClick={onConfirm}
disabled={!tagName}
data-testid="save-tag"
>
{tagMeta ? t['Save']() : t['Create']()} {tagMeta ? t['Save']() : t['Create']()}
</Button> </Button>
</div> </div>

View File

@@ -8,7 +8,11 @@ export const TagListHeader = ({ onOpen }: { onOpen: () => void }) => {
return ( return (
<div className={styles.tagListHeader}> <div className={styles.tagListHeader}>
<div className={styles.tagListHeaderTitle}>{t['Tags']()}</div> <div className={styles.tagListHeaderTitle}>{t['Tags']()}</div>
<Button className={styles.newTagButton} onClick={onOpen}> <Button
className={styles.newTagButton}
onClick={onOpen}
data-testid="all-tags-new-button"
>
{t['com.affine.tags.empty.new-tag-button']()} {t['com.affine.tags.empty.new-tag-button']()}
</Button> </Button>
</div> </div>

View File

@@ -88,7 +88,7 @@ export const CreateCollection = ({
[isNameEmpty] [isNameEmpty]
); );
return ( return (
<div> <div data-testid="edit-collection-modal">
<div className={styles.content}> <div className={styles.content}>
<div className={styles.label}> <div className={styles.label}>
{t['com.affine.editCollectionName.name']()} {t['com.affine.editCollectionName.name']()}

View File

@@ -404,3 +404,68 @@ test('select three pages with shiftKey and delete', async ({ page }) => {
expect(await getPagesCount(page)).toBe(pageCount - 3); expect(await getPagesCount(page)).toBe(pageCount - 3);
}); });
test('create a collection and delete it', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await clickNewPageButton(page);
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
await page.getByTestId('workspace-collections-button').click();
// create a collection
await page.getByTestId('all-collection-new-button').click();
await expect(page.getByTestId('edit-collection-modal')).toBeVisible();
await page.getByTestId('input-collection-title').fill('test collection');
await page.getByTestId('save-collection').click();
// check the collection is created
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
await page.getByTestId('workspace-collections-button').click();
const cell = page
.getByTestId('collection-list-item')
.getByText('test collection');
await expect(cell).toBeVisible();
// delete the collection
await page.getByTestId('collection-item-operation-button').click();
await page.getByTestId('delete-collection').click();
await page.waitForURL(url => url.pathname.endsWith('collection'));
const newCell = page
.getByTestId('collection-list-item')
.getByText('test collection');
await expect(newCell).not.toBeVisible();
});
test('create a tag and delete it', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await clickNewPageButton(page);
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
await page.getByTestId('workspace-tags-button').click();
// create a tag
await page.getByTestId('all-tags-new-button').click();
await expect(page.getByTestId('edit-tag-modal')).toBeVisible();
await page.getByTestId('edit-tag-input').fill('test-tag');
await page.getByTestId('save-tag').click();
// check the tag is created
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
await page.getByTestId('workspace-tags-button').click();
const cell = page.getByTestId('tag-list-item').getByText('test-tag');
await expect(cell).toBeVisible();
// delete the tag
await page.getByTestId('tag-item-operation-button').click();
await page.getByTestId('delete-tag').click();
await page.getByTestId('confirm-modal-confirm').getByText('Delete').click();
await page.waitForURL(url => url.pathname.endsWith('tag'));
const newCell = page.getByTestId('tag-list-item').getByText('test-tag');
await expect(newCell).not.toBeVisible();
});