Skip to content

Commit

Permalink
test: 💍 Optimize integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Jul 30, 2021
1 parent 46d70d5 commit 15b3bad
Showing 1 changed file with 111 additions and 77 deletions.
188 changes: 111 additions & 77 deletions integration-test/tests/editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,114 +7,148 @@ test('has editor', async ({ page }) => {
expect(await editor.getAttribute('contenteditable')).toBe('true');
});

test('input heading', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');
test.describe('input', () => {
test.describe('node', () => {
test('input heading', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');

await editor.type('# Heading1');
expect(await editor.waitForSelector('.h1 >> text=Heading1')).toBeTruthy();
await editor.type('# Heading1');
expect(await editor.waitForSelector('.h1 >> text=Heading1')).toBeTruthy();

await editor.type('\n');
await editor.type('\n');

await editor.type('## Heading2');
expect(await editor.waitForSelector('.h2 >> text=Heading2')).toBeTruthy();
});
await editor.type('## Heading2');
expect(await editor.waitForSelector('.h2 >> text=Heading2')).toBeTruthy();
});

test('input blockquote ', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');
test('input blockquote ', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');

await editor.type('> Blockquote');
const blockquote = await page.waitForSelector('.blockquote');
await editor.type('> Blockquote');
const blockquote = await page.waitForSelector('.blockquote');

expect(await blockquote.$$('p')).toHaveLength(1);
expect(await blockquote.waitForSelector('p >> text=Blockquote')).toBeTruthy();
expect(await blockquote.$$('p')).toHaveLength(1);
expect(await blockquote.waitForSelector('p >> text=Blockquote')).toBeTruthy();

await editor.type('\n');
await editor.type('\n');

await editor.type('Next line.');
await editor.type('Next line.');

expect(await blockquote.$$('p')).toHaveLength(2);
expect(await blockquote.waitForSelector('p:last-child >> text=Next line.')).toBeTruthy();
});
expect(await blockquote.$$('p')).toHaveLength(2);
expect(await blockquote.waitForSelector('p:last-child >> text=Next line.')).toBeTruthy();
});

test('input bullet list ', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');
test('input bullet list ', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');

await editor.type('* list item 1');
const list = await page.waitForSelector('.bullet-list');
await editor.type('* list item 1');
const list = await page.waitForSelector('.bullet-list');

expect(await list.$$('.list-item')).toHaveLength(1);
expect(await list.waitForSelector('.list-item >> text=list item 1')).toBeTruthy();
expect(await list.$$('.list-item')).toHaveLength(1);
expect(await list.waitForSelector('.list-item >> text=list item 1')).toBeTruthy();

await editor.type('\n');
await editor.type('\n');

await editor.type('list item 2');
await editor.type('list item 2');

expect(await list.$$('.list-item')).toHaveLength(2);
expect(await list.waitForSelector('.list-item:last-child >> text=list item 2')).toBeTruthy();
});
expect(await list.$$('.list-item')).toHaveLength(2);
expect(await list.waitForSelector('.list-item:last-child >> text=list item 2')).toBeTruthy();
});

test('input ordered list ', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');
test('input ordered list ', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');

await editor.type('1. list item 1');
const list = await page.waitForSelector('.ordered-list');
await editor.type('1. list item 1');
const list = await page.waitForSelector('.ordered-list');

expect(await list.$$('.list-item')).toHaveLength(1);
expect(await list.waitForSelector('.list-item >> text=list item 1')).toBeTruthy();
expect(await list.$$('.list-item')).toHaveLength(1);
expect(await list.waitForSelector('.list-item >> text=list item 1')).toBeTruthy();

await editor.type('\n');
await editor.type('\n');

await editor.type('list item 2');
await editor.type('list item 2');

expect(await list.$$('.list-item')).toHaveLength(2);
expect(await list.waitForSelector('.list-item:last-child >> text=list item 2')).toBeTruthy();
});
expect(await list.$$('.list-item')).toHaveLength(2);
expect(await list.waitForSelector('.list-item:last-child >> text=list item 2')).toBeTruthy();
});

test('input hr', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');
test('input hr', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');

await editor.type('---');
expect(await editor.waitForSelector('.hr')).toBeDefined();
});
await editor.type('---');
expect(await editor.waitForSelector('.hr')).toBeDefined();
});

test('input image', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');
test('input image', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');

await editor.type('![image](url)');
const image = await editor.waitForSelector('.image');
expect(image).toBeDefined();
expect(await image.getAttribute('src')).toBe('url');
});
await editor.type('![image](url)');
const image = await editor.waitForSelector('.image');
expect(image).toBeDefined();
expect(await image.getAttribute('src')).toBe('url');
});

test('input bold', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');
test('input code block', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');

await editor.type('here is **bold test**!');
expect(await editor.waitForSelector('.strong >> text=bold test')).toBeTruthy();
});
await editor.type('```markdown ');
const fence = await editor.waitForSelector('.code-fence');
expect(fence).toBeDefined();
expect(await fence.getAttribute('data-language')).toBe('markdown');
});
});

test('input em', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');
test.describe('mark', () => {
test('input bold', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');

await editor.type('here is **bold test**!');
expect(await editor.waitForSelector('.strong >> text=bold test')).toBeTruthy();
});

await editor.type('here is *em test*!');
expect(await editor.waitForSelector('.em >> text=em test')).toBeTruthy();
test('input em', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');

await editor.type('here is *em test*!');
expect(await editor.waitForSelector('.em >> text=em test')).toBeTruthy();
});

test('input inline code', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');

await editor.type('here is `code test`!');
expect(await editor.waitForSelector('.code-inline >> text=code test')).toBeTruthy();
});

test('input link', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');

await editor.type('here is [link test](url)!');
expect(await editor.waitForSelector('.link >> text=link test')).toBeTruthy();

const link = await editor.waitForSelector('.link');
expect(await link.getAttribute('href')).toBe('url');
});
});
});

test('input link', async ({ page }) => {
test('press hard break', async ({ page }) => {
await page.goto('/#/preset-commonmark');
const editor = await page.waitForSelector('.editor');

await editor.type('here is [link test](url)!');
expect(await editor.waitForSelector('.link >> text=link test')).toBeTruthy();

const link = await editor.waitForSelector('.link');
expect(await link.getAttribute('href')).toBe('url');
await editor.type('something');
await editor.press('Shift+Enter');
await editor.type('new line');
await editor.press('Shift+Enter');
expect(await editor.$$('.hardbreak')).toHaveLength(2);
});

0 comments on commit 15b3bad

Please sign in to comment.