feat: add permissions control E2E tests
This commit is contained in:
@@ -0,0 +1,90 @@
|
|||||||
|
import { test, expect } from '../../fixtures/base.fixture';
|
||||||
|
import { AdminLoginPage, AdminContentPage } from '../../pages/AdminPage';
|
||||||
|
import { adminTestData } from '../../data/admin-test-data';
|
||||||
|
|
||||||
|
test.describe('权限控制E2E测试', () => {
|
||||||
|
test('管理员应该能够创建所有类型的内容', async ({ page }) => {
|
||||||
|
const loginPage = new AdminLoginPage(page);
|
||||||
|
const contentPage = new AdminContentPage(page);
|
||||||
|
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.login(adminTestData.users.admin.email, adminTestData.users.admin.password);
|
||||||
|
|
||||||
|
await expect(async () => {
|
||||||
|
await page.waitForURL(/\/admin/, { timeout: 10000 });
|
||||||
|
}).toPass({ timeout: 15000 });
|
||||||
|
|
||||||
|
await page.goto('/admin/content/new');
|
||||||
|
|
||||||
|
const typeSelect = page.locator('select[name="type"]');
|
||||||
|
await expect(typeSelect).toBeVisible();
|
||||||
|
|
||||||
|
const options = await typeSelect.locator('option').allTextContents();
|
||||||
|
|
||||||
|
expect(options).toContain('新闻');
|
||||||
|
expect(options).toContain('产品');
|
||||||
|
expect(options).toContain('服务');
|
||||||
|
expect(options).toContain('案例');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('编辑者应该能够创建内容但不能删除', async ({ page }) => {
|
||||||
|
const loginPage = new AdminLoginPage(page);
|
||||||
|
const contentPage = new AdminContentPage(page);
|
||||||
|
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.login(adminTestData.users.editor.email, adminTestData.users.editor.password);
|
||||||
|
|
||||||
|
await expect(async () => {
|
||||||
|
await page.waitForURL(/\/admin/, { timeout: 10000 });
|
||||||
|
}).toPass({ timeout: 15000 });
|
||||||
|
|
||||||
|
await contentPage.goto();
|
||||||
|
|
||||||
|
const createButton = contentPage.createButton;
|
||||||
|
await expect(createButton).toBeVisible();
|
||||||
|
|
||||||
|
const deleteButtons = page.getByRole('button', { name: /删除/i });
|
||||||
|
const count = await deleteButtons.count();
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
const firstDeleteButton = deleteButtons.first();
|
||||||
|
const isDisabled = await firstDeleteButton.isDisabled();
|
||||||
|
expect(isDisabled).toBe(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('查看者应该只能查看内容', async ({ page }) => {
|
||||||
|
const loginPage = new AdminLoginPage(page);
|
||||||
|
const contentPage = new AdminContentPage(page);
|
||||||
|
|
||||||
|
await loginPage.goto();
|
||||||
|
await loginPage.login(adminTestData.users.viewer.email, adminTestData.users.viewer.password);
|
||||||
|
|
||||||
|
await expect(async () => {
|
||||||
|
await page.waitForURL(/\/admin/, { timeout: 10000 });
|
||||||
|
}).toPass({ timeout: 15000 });
|
||||||
|
|
||||||
|
await contentPage.goto();
|
||||||
|
|
||||||
|
const createButton = contentPage.createButton;
|
||||||
|
await expect(createButton).not.toBeVisible();
|
||||||
|
|
||||||
|
const deleteButtons = page.getByRole('button', { name: /删除/i });
|
||||||
|
const count = await deleteButtons.count();
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
const button = deleteButtons.nth(i);
|
||||||
|
const isDisabled = await button.isDisabled();
|
||||||
|
expect(isDisabled).toBe(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('未登录用户应该被重定向到登录页', async ({ page }) => {
|
||||||
|
await page.goto('/admin/content');
|
||||||
|
|
||||||
|
await expect(page).toHaveURL(/\/admin\/login/, { timeout: 5000 });
|
||||||
|
await expect(page.locator('text=请先登录')).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user