test(e2e): add simple flashcards check

pull/6015/head
Andelf 2022-07-11 10:23:23 +08:00
parent 961fde743e
commit 53c0e79483
1 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,51 @@
import { expect } from '@playwright/test'
import { test } from './fixtures'
import { createRandomPage } from './utils'
test('flashcard demo', async ({ page, block }) => {
await createRandomPage(page)
await block.mustFill('Why do you add cards? #card #logseq')
await block.enterNext()
expect(await block.indent()).toBe(true)
await block.mustFill('To augment our minds')
await block.enterNext()
expect(await block.unindent()).toBe(true)
expect(await block.unindent()).toBe(false)
await block.mustFill('How do you create clozes? #card #logseq')
await block.enterNext()
expect(await block.indent()).toBe(true)
await block.mustType('/clo')
const popupMenuItem = page.locator('.absolute >> text=Cloze')
await popupMenuItem.waitFor({ timeout: 1000 }) // wait for electric-input
await popupMenuItem.click({ delay: 10 })
await page.waitForTimeout(500)
await page.type('textarea >> nth=0', 'Something')
await page.keyboard.press('ArrowRight')
await page.keyboard.press('ArrowRight')
await page.type('textarea >> nth=0', ' like this')
await block.enterNext()
expect(await block.unindent()).toBe(true)
// navigate to another page, query cards
await createRandomPage(page)
await block.mustFill('{{cards [[logseq]]}}')
await page.keyboard.press('Enter')
const queryCards = page.locator('text="No matched cards"')
await queryCards.waitFor({ state: 'hidden', timeout: 1000 })
const numberLabel = page.locator('.cards-title')
await numberLabel.waitFor({ state: 'visible' })
expect(await numberLabel.innerText()).toMatch(/\[\[logseq\]\]\s+2\/2/)
const cardsNum = page.locator('.flashcards-nav span >> nth=1')
expect(await cardsNum.innerText()).toBe('2')
})