|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +test('test', async ({ page }) => { |
| 4 | + await page.goto('http://localhost:6006/iframe.html?id=test--katex&viewMode=story'); |
| 5 | + const cells = await page.locator('.cell').all(); |
| 6 | + |
| 7 | + expect(cells).toHaveLength(9); |
| 8 | + |
| 9 | + { |
| 10 | + expect(await cells[0].locator('.input_prompt').textContent()).toContain('In [1]:'); |
| 11 | + expect(await cells[0].locator('pre').textContent()).toContain('import matplotlib.pyplot as plt'); |
| 12 | + expect(await cells[0].locator('.output_area').innerHTML()).toContain('<img src="data:image/png;base64,iVBORw0'); |
| 13 | + } |
| 14 | + |
| 15 | + { |
| 16 | + expect(await cells[1].locator('.input_prompt').textContent()).toContain('In [5]:'); |
| 17 | + expect(await cells[1].locator('pre').textContent()).toContain('A = sy.Matrix([[2, 8], [1, 0]])'); |
| 18 | + |
| 19 | + const output = cells[1].locator('.output_area').first(); |
| 20 | + const katex = output.locator('.katex').first(); |
| 21 | + expect(await katex.innerHTML()).toContain('<span class="mord">2</span>'); |
| 22 | + expect(await katex.innerHTML()).toContain('<span class="mord">8</span>'); |
| 23 | + expect(await katex.innerHTML()).toContain('<span class="mord">1</span>'); |
| 24 | + expect(await katex.innerHTML()).toContain('<span class="mord">0</span>'); |
| 25 | + expect(await katex.innerHTML()).toContain('<span class="delimsizing size3">[</span>'); |
| 26 | + expect(await katex.innerHTML()).toContain('<span class="delimsizing size3">]</span>'); |
| 27 | + } |
| 28 | + |
| 29 | + { |
| 30 | + expect(await cells[2].locator('.input_prompt').textContent()).toContain('In [6]:'); |
| 31 | + expect(await cells[2].locator('pre').textContent()).toContain('A ** (n-1) * sy.Matrix([3, 1])'); |
| 32 | + //expect(await cells[2].locator('.output_area').innerHTML()).toContain('<svg xmlns="http://www.w3.org/2000/svg" width="20.183ex" height="7.908ex" role="img"'); |
| 33 | + } |
| 34 | + |
| 35 | + { |
| 36 | + expect(await cells[3].locator('.input_prompt').textContent()).toContain('In [7]:'); |
| 37 | + expect(await cells[3].locator('pre').textContent()).toContain('display(df)'); |
| 38 | + const tables = await cells[3].locator('.output_area').locator('table').all(); |
| 39 | + expect(tables).toHaveLength(1); |
| 40 | + const table = tables[0]; |
| 41 | + expect(await table.locator('tr').count()).toBe(6); |
| 42 | + } |
| 43 | + |
| 44 | + { |
| 45 | + expect(await cells[4].locator('.input_prompt').textContent()).toContain('In [9]:'); |
| 46 | + expect(await cells[4].locator('.language-python').textContent()).toContain('this is a syntax error'); |
| 47 | + |
| 48 | + const output = cells[4].locator('.output_subarea').first(); |
| 49 | + expect(output).toHaveClass(/output_error/); |
| 50 | + expect(output).toHaveCSS('background-color', 'rgba(255, 0, 0, 0.25)'); |
| 51 | + //expect(output.locator('span').filter({hasText: 'File'}).first()).toHaveCSS('color', 'rgb(0, 187, 187)'); |
| 52 | + //expect(output.locator('span').filter({hasText: '<ipython-input-9-4d9d942c1a8e>'}).first()).toHaveCSS('color', 'rgb(0, 187, 0)'); |
| 53 | + } |
| 54 | + |
| 55 | + { |
| 56 | + expect(await cells[5].locator('.input_prompt').textContent()).toContain('In [10]:'); |
| 57 | + expect(await cells[5].locator('pre').textContent()).toContain('from IPython.display import Latex'); |
| 58 | + expect(await cells[5].locator('.output_area').textContent()).toContain('The mass-energy equivalence is described by the famous equation'); |
| 59 | + |
| 60 | + const katex = cells[5].locator('.output_area').locator('.katex').first(); |
| 61 | + // E = mc^2 |
| 62 | + expect(await katex.innerHTML()).toContain('<span class="mord mathnormal" style="margin-right: 0.05764em;">E</span>'); |
| 63 | + expect(await katex.innerHTML()).toContain('<span class="mspace" style="margin-right: 0.2778em;"></span>'); |
| 64 | + expect(await katex.innerHTML()).toContain('<span class="mrel">=</span>'); |
| 65 | + expect(await katex.innerHTML()).toContain('<span class="mord mathnormal">m</span>'); |
| 66 | + expect(await katex.innerHTML()).toContain('<span class="mord mathnormal">c</span>'); |
| 67 | + expect(await katex.innerHTML()).toContain('<span class="mord mtight">2</span>'); |
| 68 | + |
| 69 | + expect(await cells[5].locator('.output_area').textContent()).toContain('discovered in 1905 by Albert Einstein.'); |
| 70 | + // c |
| 71 | + //expect(await cells[5].locator('.output_area').innerHTML()).toContain('<svg xmlns="http://www.w3.org/2000/svg" width="0.98ex" height="1.025ex" role="img"'); |
| 72 | + expect(await cells[5].locator('.output_area').textContent()).toContain('the formula expresses the identity'); |
| 73 | + // E = m |
| 74 | + //expect(await cells[5].locator('.output_area').innerHTML()).toContain('<svg xmlns="http://www.w3.org/2000/svg" width="6.732ex" height="1.724ex" role="img"'); |
| 75 | + } |
| 76 | + |
| 77 | + { |
| 78 | + // Markdown |
| 79 | + expect(await cells[6].locator('.input_prompt').textContent()).not.toContain('In'); |
| 80 | + const output = cells[6].locator('.rendered_html').first(); |
| 81 | + const header = output.locator('h1').first(); |
| 82 | + expect(header).toHaveText('Markdown Cell'); |
| 83 | + |
| 84 | + //expect(await output.innerHTML()).toContain('<svg xmlns="http://www.w3.org/2000/svg" width="23.457ex" height="2.388ex" role="img"'); |
| 85 | + expect(await output.innerHTML()).toContain('<p><em>It</em> <strong>really</strong> is!!</p>'); |
| 86 | + } |
| 87 | + |
| 88 | + { |
| 89 | + expect(await cells[7].locator('.input_prompt').textContent()).toContain('In [11]:'); |
| 90 | + expect(await cells[7].locator('.language-python').textContent()).toContain("sys.stdout.write('hello world\\n')"); |
| 91 | + const outputs = await cells[7].locator('.output_area').all(); |
| 92 | + expect(outputs).toHaveLength(3); |
| 93 | + expect(outputs[0].locator('.output_subarea').first()).toHaveClass(/output-stdout/); |
| 94 | + expect(outputs[1].locator('.output_subarea').first()).toHaveClass(/output-stderr/); |
| 95 | + //expect(outputs[2].locator('.output_subarea').first()).toHaveClass(/output-stdout/); |
| 96 | + } |
| 97 | + |
| 98 | + { |
| 99 | + // markdown |
| 100 | + expect(await cells[8].locator('.input_prompt').textContent()).not.toContain('In'); |
| 101 | + const output = cells[8].locator('.rendered_html').first(); |
| 102 | + expect(await output.innerHTML()).toContain('<img src="https://github.com/righ/react-ipynb-renderer/raw/master/images/logo.png" alt="logo.png">'); |
| 103 | + } |
| 104 | + |
| 105 | +}); |
0 commit comments