Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: adding tests (playwright) #48

Merged
merged 15 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"preview": "vite preview",
"test-ct": "playwright test -c playwright-ct.config.ts"
greentfrapp marked this conversation as resolved.
Show resolved Hide resolved
"test:unit": "vitest",
"test:e2e": "playwright test"
},
Expand All @@ -21,6 +22,7 @@
},
"devDependencies": {
"@babel/types": "^7.18.9",
"@playwright/experimental-ct-vue": "^1.25.0",
"@playwright/test": "^1.25.0",
"@types/node": "^18.0.6",
"@types/sortablejs": "^1.13.0",
Expand Down
63 changes: 63 additions & 0 deletions playwright-ct.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { PlaywrightTestConfig } from '@playwright/experimental-ct-vue';
import { devices } from '@playwright/experimental-ct-vue';
import path from 'path'

/**
* See https://playwright.dev/docs/test-configuration.
*/
const config: PlaywrightTestConfig = {
testDir: './src/components/tests',
/* The base directory, relative to the config file, for snapshot files created with toMatchSnapshot and toHaveScreenshot. */
snapshotDir: './__snapshots__',
/* Maximum time one test can run for. */
timeout: 10 * 1000,
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',

/* Port to use for Playwright component endpoint. */
ctPort: 3100,
ctViteConfig: {
resolve:{
alias:{
'@' : path.resolve('./src')
},
},
}
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
},
},
{
name: 'firefox',
use: {
...devices['Desktop Firefox'],
},
},
{
name: 'webkit',
use: {
...devices['Desktop Safari'],
},
},
],
};

export default config;
12 changes: 12 additions & 0 deletions playwright/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
greentfrapp marked this conversation as resolved.
Show resolved Hide resolved
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Testing Page</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/playwright/index.ts"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions playwright/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Import styles, initialize component theme here.
// import '../src/common.css';
2 changes: 1 addition & 1 deletion src/components/BlockMenu.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div ref="container" as="div" class="relative w-max h-max">
<div @click="open = !open" class="handle">
<div @click="open = !open" class="handle" data-test-id="openmenu">
vvidday marked this conversation as resolved.
Show resolved Hide resolved
<Tooltip value="<span class='text-neutral-400'><span class='text-white'>Drag</span> to move<br/><span class='text-white'>Click</span> to open menu</span>">
<v-icon name="md-dragindicator" @mouseup="$event.stopPropagation()"
class="w-6 h-6 hover:bg-neutral-100 hover:text-neutral-400 p-0.5 rounded group-hover:opacity-100 opacity-0"
Expand Down
56 changes: 56 additions & 0 deletions src/components/tests/Lotion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { test, expect } from '@playwright/experimental-ct-vue'
greentfrapp marked this conversation as resolved.
Show resolved Hide resolved
import Lotion from '../Lotion.vue'
import { BlockType } from '../../../tests/utils/testTypes.ts'
import { isBlockType } from '../../../tests/utils/helpers.ts'

const page = {
name: '🧴 Lotion',
blocks: [
{
id: 'f8296d43-7920-4ab8-a869-7d58439534b2',
type: BlockType.Text,
details: {
value: '<p><strong><em>Text</em></strong> block</p>',
},
},
{
id: '9274a245-38b8-49fe-b4f4-3476fb23202c',
type: BlockType.H1,
details: {
value: 'H1 Block',
},
},
{
id: '720f5772-0086-4054-8487-17ca5627123b',
type: BlockType.Quote,
details: {
value: '<p>Quote Block</p>',
},
},
],
}

test.use({ viewport: { width: 1000, height: 800 } })

// Example of failing test w/ italic bold (nested) tags
test('converting within italic bold text should work', async ({ mount }) => {
const component = await mount(Lotion, {
props: {
page: page,
},
})
await expect(component).toContainText('Quote Block')
let block = await component.locator('.ProseMirror').first()
await block.click()
let text = await block.innerHTML()
expect(text).toBe('<p><strong><em>Text</em></strong> block</p>')
await block.press('Home')
await block.press('ArrowRight')
await block.type('/quote')
await block.press('Enter')
const innerHTML = await block.innerHTML()
expect(innerHTML).toBe('<p><strong><em>Text</em></strong> block</p>')
await component.locator('text="ext block"').waitFor()
let isQuote = await isBlockType(block, BlockType.Quote)
expect(isQuote).toBe(true)
})
Loading