Browse Source

add e2e test

Mega Yu 1 year ago
parent
commit
3a93799958
1 changed files with 90 additions and 10 deletions
  1. 90 10
      e2e-tests/basic.spec.ts

+ 90 - 10
e2e-tests/basic.spec.ts

@@ -85,33 +85,113 @@ test('delete and backspace', async ({ page, block }) => {
 })
 })
 
 
 
 
-test('selection', async ({ page, block }) => {
+test('block selection', async ({ page, block }) => {
   await createRandomPage(page)
   await createRandomPage(page)
 
 
-  // add 5 blocks
-  await block.mustFill('line 1')
+  await block.mustFill('1')
   await block.enterNext()
   await block.enterNext()
-  await block.mustFill('line 2')
+  await block.mustFill('2')
+  expect(await block.indent()).toBe(true)
+  await block.enterNext()
+  await block.mustFill('3')
+  await block.enterNext()
+  await block.mustFill('4')
+  expect(await block.unindent()).toBe(true)
   await block.enterNext()
   await block.enterNext()
+  await block.mustFill('5')
   expect(await block.indent()).toBe(true)
   expect(await block.indent()).toBe(true)
-  await block.mustFill('line 3')
   await block.enterNext()
   await block.enterNext()
-  await block.mustFill('line 4')
+  await block.mustFill('6')
+  await block.enterNext()
+  await block.mustFill('7')
+  expect(await block.unindent()).toBe(true)
+  await block.enterNext()
+  await block.mustFill('8')
   expect(await block.indent()).toBe(true)
   expect(await block.indent()).toBe(true)
   await block.enterNext()
   await block.enterNext()
-  await block.mustFill('line 5')
+  await block.mustFill('9')
+  expect(await block.unindent()).toBe(true)
 
 
-  // shift+up select 3 blocks
+  // shift+up/down
   await page.keyboard.down('Shift')
   await page.keyboard.down('Shift')
   await page.keyboard.press('ArrowUp')
   await page.keyboard.press('ArrowUp')
+  await block.waitForSelectedBlocks(1)
+  var locator = page.locator('.ls-block >> nth=8')
+  await expect(locator).toHaveAttribute('level', '1')
+  await expect(locator).toHaveCSS('border-radius', '2px')
   await page.keyboard.press('ArrowUp')
   await page.keyboard.press('ArrowUp')
+  await block.waitForSelectedBlocks(2)
+  locator = page.locator('.ls-block >> nth=7')
+  await expect(locator).toHaveAttribute('level', '2')
+  await expect(locator).toHaveCSS('border-radius', '2px')
   await page.keyboard.press('ArrowUp')
   await page.keyboard.press('ArrowUp')
+  await block.waitForSelectedBlocks(3)
+  locator = page.locator('.ls-block >> nth=6')
+  await expect(locator).toHaveAttribute('level', '1')
+  locator = page.locator('.block-main-container >> nth=6')
+  await expect(locator).toHaveCSS('border-radius', '2px')
+  await page.keyboard.press('ArrowDown')
+  await block.waitForSelectedBlocks(2)
+  locator = page.locator('.block-main-container >> nth=6')
+  await expect(locator).toHaveCSS('border-radius', '0px')
   await page.keyboard.up('Shift')
   await page.keyboard.up('Shift')
 
 
+  // mod+click select or deselect
+  await page.keyboard.down(modKey)
+  await page.click('.ls-block >> nth=7')
+  await block.waitForSelectedBlocks(1)
+  locator = page.locator('.ls-block >> nth=7')
+  await expect(locator).toHaveCSS('border-radius', '0px')
+  await page.click('.block-main-container >> nth=6')
+  await block.waitForSelectedBlocks(2)
+  locator = page.locator('.block-main-container >> nth=6')
+  await expect(locator).toHaveCSS('border-radius', '2px')
+
+  // mod+shift+click
+  await page.click('.ls-block >> nth=4')
   await block.waitForSelectedBlocks(3)
   await block.waitForSelectedBlocks(3)
-  await page.keyboard.press('Backspace')
+  locator = page.locator('.ls-block >> nth=4')
+  await expect(locator).toHaveAttribute('level', '2')
+  await expect(locator).toHaveCSS('border-radius', '2px')
+  await page.keyboard.down('Shift')
+  await page.click('.ls-block >> nth=1')
+  await block.waitForSelectedBlocks(6)
+  locator = page.locator('.ls-block >> nth=3')
+  await expect(locator).toHaveAttribute('level', '1')
+  locator = page.locator('.block-main-container >> nth=3')
+  await expect(locator).toHaveCSS('border-radius', '2px')
+  locator = page.locator('.ls-block >> nth=2')
+  await expect(locator).toHaveAttribute('level', '2')
+  await expect(locator).toHaveCSS('border-radius', '2px')
+  locator = page.locator('.ls-block >> nth=1')
+  await expect(locator).toHaveAttribute('level', '2')
+  await expect(locator).toHaveCSS('border-radius', '2px')
+  await page.keyboard.up('Shift')
+  await page.keyboard.up(modKey)
+  await page.keyboard.press('Escape')
 
 
-  await block.waitForBlocks(2)
+  // shift+click
+  await page.keyboard.down('Shift')
+  await page.click('.block-main-container >> nth=0')
+  await expect(page.locator('.block-main-container >> nth=0')).toHaveCSS('border-radius', '0px')
+  await page.click('.block-main-container >> nth=3')
+  await block.waitForSelectedBlocks(4)
+  await expect(page.locator('.block-main-container >> nth=0')).toHaveCSS('border-radius', '2px')
+  await expect(page.locator('.ls-block >> nth=1')).toHaveCSS('border-radius', '2px')
+  await expect(page.locator('.ls-block >> nth=2')).toHaveCSS('border-radius', '2px')
+  await expect(page.locator('.block-main-container >> nth=3')).toHaveCSS('border-radius', '2px')
+  await page.click('.ls-block >> nth=8')
+  await block.waitForSelectedBlocks(9)
+  await expect(page.locator('.ls-block >> nth=4')).toHaveCSS('border-radius', '2px')
+  await expect(page.locator('.ls-block >> nth=5')).toHaveCSS('border-radius', '2px')
+  await expect(page.locator('.block-main-container >> nth=6')).toHaveCSS('border-radius', '2px')
+  await expect(page.locator('.ls-block >> nth=7')).toHaveCSS('border-radius', '2px')
+  await expect(page.locator('.ls-block >> nth=8')).toHaveCSS('border-radius', '2px')
+  await page.click('.ls-block >> nth=5')
+  await block.waitForSelectedBlocks(6)
+  await expect(page.locator('.block-main-container >> nth=6')).toHaveCSS('border-radius', '0px')
+  await expect(page.locator('.ls-block >> nth=7')).toHaveCSS('border-radius', '0px')
+  await expect(page.locator('.ls-block >> nth=8')).toHaveCSS('border-radius', '0px')
 })
 })
 
 
 test('template', async ({ page, block }) => {
 test('template', async ({ page, block }) => {