|
| 1 | +import type { Article } from 'src/services/api.ts' |
| 2 | +import { Route } from '../constant.ts' |
| 3 | +import { expect, test } from '../extends' |
| 4 | +import { formatHTML } from '../utils/formatHTML.ts' |
| 5 | + |
| 6 | +test.describe('article', () => { |
| 7 | + test.beforeEach(async ({ conduct }) => { |
| 8 | + await conduct.intercept('GET', /articles\?limit/, { fixture: 'articles.json' }) |
| 9 | + await conduct.intercept('GET', /tags/, { fixture: 'articles-of-tag.json' }) |
| 10 | + await conduct.intercept('GET', /profiles\/.+/, { fixture: 'profile.json' }) |
| 11 | + |
| 12 | + await conduct.login() |
| 13 | + }) |
| 14 | + |
| 15 | + test.describe('post article', () => { |
| 16 | + test('jump to post detail page when submit create article form', async ({ page, conduct }) => { |
| 17 | + await conduct.goto(Route.ArticleCreate) |
| 18 | + |
| 19 | + const articleFixture = await conduct.getFixture<{ article: Article }>('article.json') |
| 20 | + const waitForPostArticle = await conduct.intercept('POST', /articles$/, { body: articleFixture }) |
| 21 | + |
| 22 | + await page.getByPlaceholder('Article Title').fill(articleFixture.article.title) |
| 23 | + await page.getByPlaceholder("What's this article about?").fill(articleFixture.article.description) |
| 24 | + await page.getByPlaceholder('Write your article (in markdown)').fill(articleFixture.article.body) |
| 25 | + for (const tag of articleFixture.article.tagList) { |
| 26 | + await page.getByPlaceholder('Enter tags').fill(tag) |
| 27 | + await page.getByPlaceholder('Enter tags').press('Enter') |
| 28 | + } |
| 29 | + |
| 30 | + await page.getByRole('button', { name: 'Publish Article' }).dispatchEvent('click') |
| 31 | + await waitForPostArticle() |
| 32 | + |
| 33 | + await conduct.intercept('GET', /articles\/.+/, { fixture: 'article.json' }) |
| 34 | + await page.waitForURL(/article\/article-title/) |
| 35 | + await expect (page.getByRole('heading', { name: 'Article title' })).toContainText('Article title') |
| 36 | + }) |
| 37 | + |
| 38 | + test('should render markdown correctly', async ({ browserName, page, conduct }) => { |
| 39 | + test.skip(browserName !== 'chromium') |
| 40 | + await conduct.goto(Route.ArticleDetail) |
| 41 | + |
| 42 | + const waitForArticle = await conduct.intercept('GET', /articles\/.+/, { fixture: 'article.json' }) |
| 43 | + await waitForArticle() |
| 44 | + const innerHTML = await page.locator('.article-content').innerHTML() |
| 45 | + expect(formatHTML(innerHTML)).toMatchSnapshot('markdown-render.html') |
| 46 | + }) |
| 47 | + }) |
| 48 | + |
| 49 | + test.describe('delete article', () => { |
| 50 | + for (const [index, position] of ['banner', 'article footer'].entries()) { |
| 51 | + test(`delete article from ${position}`, async ({ page, conduct }) => { |
| 52 | + const waitForArticle = await conduct.intercept('GET', /articles\/.+/, { fixture: 'article.json' }) |
| 53 | + await conduct.goto(Route.ArticleDetail) |
| 54 | + await waitForArticle() |
| 55 | + |
| 56 | + await conduct.intercept('DELETE', /articles\/.+/) |
| 57 | + await page.getByRole('button', { name: 'Delete Article' }).nth(index).click() |
| 58 | + |
| 59 | + await expect(page).toHaveURL(Route.Home) |
| 60 | + }) |
| 61 | + } |
| 62 | + }) |
| 63 | +}) |
0 commit comments