From 53c0e79483c89fcf0ced9506817d49463530deaa Mon Sep 17 00:00:00 2001 From: Andelf Date: Mon, 11 Jul 2022 10:23:23 +0800 Subject: [PATCH] test(e2e): add simple flashcards check --- e2e-tests/flashcards.spec.ts | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 e2e-tests/flashcards.spec.ts diff --git a/e2e-tests/flashcards.spec.ts b/e2e-tests/flashcards.spec.ts new file mode 100644 index 000000000..e07a30168 --- /dev/null +++ b/e2e-tests/flashcards.spec.ts @@ -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') +})