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

added tests for html raw #169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions tests/roots/test-basic_caption/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extensions = ['sphinxcontrib.mermaid']
exclude_patterns = ['_build']
13 changes: 13 additions & 0 deletions tests/roots/test-basic_caption/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Hi, basic test
--------------

.. mermaid::
:name: participants
:caption: A simple sequence diagram


sequenceDiagram
participant Alice
participant Bob
Alice->John: Hello John, how are you?

2 changes: 2 additions & 0 deletions tests/roots/test-basic_caption_align/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extensions = ['sphinxcontrib.mermaid']
exclude_patterns = ['_build']
14 changes: 14 additions & 0 deletions tests/roots/test-basic_caption_align/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Hi, basic test
--------------

.. mermaid::
:name: participants
:caption: A simple sequence diagram
:align: center


sequenceDiagram
participant Alice
participant Bob
Alice->John: Hello John, how are you?

2 changes: 2 additions & 0 deletions tests/roots/test-basic_config/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extensions = ['sphinxcontrib.mermaid']
exclude_patterns = ['_build']
13 changes: 13 additions & 0 deletions tests/roots/test-basic_config/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Hi, basic test
--------------

.. mermaid::
:name: participants
:config: { "theme": "forest" }


sequenceDiagram
participant Alice
participant Bob
Alice->John: Hello John, how are you?

2 changes: 2 additions & 0 deletions tests/roots/test-basic_title/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extensions = ['sphinxcontrib.mermaid']
exclude_patterns = ['_build']
13 changes: 13 additions & 0 deletions tests/roots/test-basic_title/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Hi, basic test
--------------

.. mermaid::
:title: test title
:name: participants


sequenceDiagram
participant Alice
participant Bob
Alice->John: Hello John, how are you?

2 changes: 2 additions & 0 deletions tests/roots/test-file/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extensions = ['sphinxcontrib.mermaid']
exclude_patterns = ['_build']
8 changes: 8 additions & 0 deletions tests/roots/test-file/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Hi, basic test
--------------

.. mermaid:: sequence.mmd
:name: participants



4 changes: 4 additions & 0 deletions tests/roots/test-file/sequence.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sequenceDiagram
participant Alice
participant Bob
Alice->John: Hello John, how are you?
2 changes: 2 additions & 0 deletions tests/roots/test-file_content/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extensions = ['sphinxcontrib.mermaid']
exclude_patterns = ['_build']
10 changes: 10 additions & 0 deletions tests/roots/test-file_content/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Hi, basic test
--------------

.. mermaid:: sequence.mmd
:name: participants

sequenceDiagram
participant Alice
participant Bob
Alice->John: Hello John, how are you?
4 changes: 4 additions & 0 deletions tests/roots/test-file_content/sequence.mmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sequenceDiagram
participant Alice
participant Bob
Alice->John: Hello John, how are you?
2 changes: 2 additions & 0 deletions tests/roots/test-file_empty/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extensions = ['sphinxcontrib.mermaid']
exclude_patterns = ['_build']
19 changes: 19 additions & 0 deletions tests/roots/test-file_empty/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Hi, basic test
--------------

.. mermaid:: sequence.mmd
:name: participants



Empty class diagram should not fail
-----------------------------------

.. mermaid::

classDiagram


.. toctree::

zoom.rst
Empty file.
2 changes: 2 additions & 0 deletions tests/roots/test-file_not_found/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extensions = ['sphinxcontrib.mermaid']
exclude_patterns = ['_build']
5 changes: 5 additions & 0 deletions tests/roots/test-file_not_found/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Hi, basic test
--------------

.. mermaid:: invalid_file_name.mmd

117 changes: 101 additions & 16 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def index(app, build_all):
def test_html_raw(index):
assert "mermaid.run()" in index
assert (
'<script type="module" src="https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs"></script>'
in index
'<script type="module" src="https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs"></script>'
in index
)
assert '<script type="module">import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs";import elkLayouts from "https://cdn.jsdelivr.net/npm/@mermaid-js/layout-elk@0.1.4/dist/mermaid-layout-elk.esm.min.mjs";mermaid.registerLayoutLoaders(elkLayouts);mermaid.initialize({startOnLoad:false});</script>' in index
assert (
'<pre id="participants" class="mermaid">\n sequenceDiagram\n participant Alice\n participant Bob\n Alice-&gt;John: Hello John, how are you?\n </pre>'
in index
'<pre id="participants" class="mermaid">\n sequenceDiagram\n participant Alice\n participant Bob\n Alice-&gt;John: Hello John, how are you?\n </pre>'
in index
)


Expand All @@ -49,21 +49,21 @@ def test_html_zoom_option(index, app):
def test_html_zoom_option_global(index):
assert "mermaid.run()" in index
assert "svg.call(zoom);" in index


@pytest.mark.sphinx("html", testroot="basic", confoverrides={"mermaid_d3_zoom": False})
def test_html_no_zoom(index):
assert "mermaid.run()" in index
assert "svg.call(zoom);" not in index


@pytest.mark.sphinx("html", testroot="basic", confoverrides={"mermaid_version": "10.3.0", "mermaid_include_elk": ""})
def test_conf_mermaid_version(app, index):
assert "mermaid.run()" in index
assert app.config.mermaid_version == "10.3.0"
assert (
'<script type="module" src="https://cdn.jsdelivr.net/npm/mermaid@10.3.0/dist/mermaid.esm.min.mjs"></script>'
in index
'<script type="module" src="https://cdn.jsdelivr.net/npm/mermaid@10.3.0/dist/mermaid.esm.min.mjs"></script>'
in index
)


Expand All @@ -85,8 +85,8 @@ def test_conf_d3_version(app, index):
assert "mermaid.run()" in index
assert app.config.d3_version == "1.2.3"
assert (
'<script src="https://cdn.jsdelivr.net/npm/d3@1.2.3/dist/d3.min.js"></script>'
in index
'<script src="https://cdn.jsdelivr.net/npm/d3@1.2.3/dist/d3.min.js"></script>'
in index
)


Expand All @@ -108,20 +108,105 @@ def test_mermaid_init_js(index):
def test_mermaid_with_elk(app, index):
assert "mermaid.run()" in index
assert (
'<script type="module" src="https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs"></script>'
in index
'<script type="module" src="https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs"></script>'
in index
)


@pytest.mark.sphinx("html", testroot="markdown")
def test_html_raw_from_markdown(index):
assert "mermaid.run()" in index
assert (
'<script type="module" src="https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs"></script>'
in index
'<script type="module" src="https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs"></script>'
in index
)
assert '<script type="module">import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs";import elkLayouts from "https://cdn.jsdelivr.net/npm/@mermaid-js/layout-elk@0.1.4/dist/mermaid-layout-elk.esm.min.mjs";mermaid.registerLayoutLoaders(elkLayouts);mermaid.initialize({startOnLoad:false});</script>' in index
assert (
'<pre align="center" id="participants" class="mermaid align-center">\n sequenceDiagram\n participant Alice\n participant Bob\n Alice-&gt;John: Hello John, how are you?\n </pre>'
in index
'<pre align="center" id="participants" class="mermaid align-center">\n sequenceDiagram\n participant Alice\n participant Bob\n Alice-&gt;John: Hello John, how are you?\n </pre>'
in index
)

@pytest.mark.sphinx("html", testroot="file")
def test_html_raw__file_input__correctly_parsed(index):
assert "mermaid.run()" in index
assert (
'<script type="module" src="https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs"></script>'
in index
)
assert '<script type="module">import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs";import elkLayouts from "https://cdn.jsdelivr.net/npm/@mermaid-js/layout-elk@0.1.4/dist/mermaid-layout-elk.esm.min.mjs";mermaid.registerLayoutLoaders(elkLayouts);mermaid.initialize({startOnLoad:false});</script>' in index
assert '<pre id="participants" class="mermaid">' in index
assert 'sequenceDiagram' in index
assert 'participant Alice' in index
assert 'participant Bob' in index
assert 'Alice-&gt;John: Hello John, how are you?' in index

@pytest.mark.sphinx("html", testroot="file_content")
def test_html_raw__file_content_input__warning(index, warning):
assert "mermaid.run()" not in index
assert "Mermaid directive cannot have both content and " "a filename argument" in warning.getvalue()


@pytest.mark.sphinx("html", testroot="file_not_found")
def test_html_raw__file_not_available__warning(index, warning):
assert "mermaid.run()" not in index
assert "External Mermaid file" in warning.getvalue()
assert "invalid_file_name.mmd' not found or reading it failed" in warning.getvalue()

@pytest.mark.sphinx("html", testroot="file_empty")
def test_html_raw__file_empty__warning(index, warning):
assert "mermaid.run()" in index
assert 'Ignoring "mermaid" directive without content' in warning.getvalue()


@pytest.mark.sphinx("html", testroot="basic_config")
def test_html_raw__inline_config__config_available(index):
assert "mermaid.run()" in index
assert (
'<script type="module" src="https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs"></script>'
in index
)
assert '<script type="module">import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs";import elkLayouts from "https://cdn.jsdelivr.net/npm/@mermaid-js/layout-elk@0.1.4/dist/mermaid-layout-elk.esm.min.mjs";mermaid.registerLayoutLoaders(elkLayouts);mermaid.initialize({startOnLoad:false});</script>' in index
assert (
'---\nconfig:\n theme: forest\n\n---\n'
in index
)


@pytest.mark.sphinx("html", testroot="basic_title")
def test_html_raw__title__title_available(index):
assert "mermaid.run()" in index
assert (
'<script type="module" src="https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs"></script>'
in index
)
assert '<script type="module">import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs";import elkLayouts from "https://cdn.jsdelivr.net/npm/@mermaid-js/layout-elk@0.1.4/dist/mermaid-layout-elk.esm.min.mjs";mermaid.registerLayoutLoaders(elkLayouts);mermaid.initialize({startOnLoad:false});</script>' in index
assert (
'---\ntitle: test title\n---\n'
in index
)

@pytest.mark.sphinx("html", testroot="basic_caption")
def test_html_raw__caption__caption_available(index):
assert "mermaid.run()" in index
assert (
'<script type="module" src="https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs"></script>'
in index
)
assert '<script type="module">import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs";import elkLayouts from "https://cdn.jsdelivr.net/npm/@mermaid-js/layout-elk@0.1.4/dist/mermaid-layout-elk.esm.min.mjs";mermaid.registerLayoutLoaders(elkLayouts);mermaid.initialize({startOnLoad:false});</script>' in index
assert (
'<figure class="align-default" id="participants">\n<pre class="mermaid">\n sequenceDiagram\n participant Alice\n participant Bob\n Alice-&gt;John: Hello John, how are you?\n </pre><figcaption>\n<p><span class="caption-text">A simple sequence diagram</span><a class="headerlink" href="#participants" title="Link to this image">'
in index
)

@pytest.mark.sphinx("html", testroot="basic_caption_align")
def test_html_raw__caption_align__caption_available(index):
assert "mermaid.run()" in index
assert (
'<script type="module" src="https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs"></script>'
in index
)
assert '<script type="module">import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@11.2.0/dist/mermaid.esm.min.mjs";import elkLayouts from "https://cdn.jsdelivr.net/npm/@mermaid-js/layout-elk@0.1.4/dist/mermaid-layout-elk.esm.min.mjs";mermaid.registerLayoutLoaders(elkLayouts);mermaid.initialize({startOnLoad:false});</script>' in index
assert (
'<figure class="align-center" id="participants">\n<pre class="mermaid">\n sequenceDiagram\n participant Alice\n participant Bob\n Alice-&gt;John: Hello John, how are you?\n </pre><figcaption>\n<p><span class="caption-text">A simple sequence diagram</span><a class="headerlink" href="#participants" title="Link to this image">'
in index
)