Skip to content

Commit

Permalink
Add some more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
allejo committed Sep 7, 2017
1 parent 4ffec8c commit 2a53d7c
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 0 deletions.
15 changes: 15 additions & 0 deletions _tests/class.md
@@ -0,0 +1,15 @@
---
---

{% capture markdown %}
# Heading 1
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text class="awesome-toc-class" %}

<!-- /// -->

<ul class="awesome-toc-class">
<li><a href="#heading-1">Heading 1</a></li>
</ul>
16 changes: 16 additions & 0 deletions _tests/id.md
@@ -0,0 +1,16 @@
---
# Test the 'id' attribute correctly assigns the ID to the generated TOC
---

{% capture markdown %}
# Heading 1
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text id="Jekyll-TOC" %}

<!-- /// -->

<ul id="Jekyll-TOC">
<li><a href="#heading-1">Heading 1</a></li>
</ul>
30 changes: 30 additions & 0 deletions _tests/maximumHeadings.md
@@ -0,0 +1,30 @@
---
# Given h_max is defined, it should only use headings less than or equal to this value
---

{% capture markdown %}
# Heading 1

## Heading 2.1

### Heading 3

#### Heading 4

## Heading 2.2
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text h_max=2 %}

<!-- /// -->

<ul>
<li>
<a href="#heading-1">Heading 1</a>
<ul>
<li><a href="#heading-21">Heading 2.1</a></li>
<li><a href="#heading-22">Heading 2.2</a></li>
</ul>
</li>
</ul>
41 changes: 41 additions & 0 deletions _tests/minAndMaxHeadings.md
@@ -0,0 +1,41 @@
---
# Given h_min and h_max are both defined, the TOC should respect both
---

{% capture markdown %}
# Heading 1

## Heading 2.1

### Heading 3

#### Heading 4.1

#### Heading 4.2

##### Heading 5

## Heading 2.2

{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text h_min=2 h_max=4 %}

<!-- /// -->

<ul>
<li>
<a href="#heading-21">Heading 2.1</a>
<ul>
<li>
<a href="#heading-3">Heading 3</a>
<ul>
<li><a href="#heading-41">Heading 4.1</a></li>
<li><a href="#heading-42">Heading 4.2</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#heading-22">Heading 2.2</a></li>
</ul>
35 changes: 35 additions & 0 deletions _tests/minimumHeadings.md
@@ -0,0 +1,35 @@
---
# Given h_min is defined, it should only use headings greater than or equal to this value
---

{% capture markdown %}
# Heading 1

## Heading 2.1

### Heading 3

#### Heading 4

## Heading 2.2
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text h_min=2 %}

<!-- /// -->

<ul>
<li>
<a href="#heading-21">Heading 2.1</a>
<ul>
<li>
<a href="#heading-3">Heading 3</a>
<ul>
<li><a href="#heading-4">Heading 4</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#heading-22">Heading 2.2</a></li>
</ul>
16 changes: 16 additions & 0 deletions _tests/multiple-classes.md
@@ -0,0 +1,16 @@
---
# Supporting multiple classes for the TOC works by concatenating them with periods
---

{% capture markdown %}
# Heading 1
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text class="first-class.second-class" %}

<!-- /// -->

<ul class="first-class second-class">
<li><a href="#heading-1">Heading 1</a></li>
</ul>
18 changes: 18 additions & 0 deletions _tests/noHeadings.md
@@ -0,0 +1,18 @@
---
# Given a markdown block with no headings, no TOC will be generated
---

{% capture markdown %}
Some **awesome** markdown that doesn't have any headings
{% endcapture %}
{% assign text = markdown | markdownify %}

<div id="unit-test">
{% include toc.html html=text id="Jekyll-TOC" %}
</div>

<!-- /// -->

<div id="unit-test">

</div>
40 changes: 40 additions & 0 deletions _tests/sanitizeDisabled.md
@@ -0,0 +1,40 @@
---
# Given `sanitize` is set to false, any HTML from headings should remain
---

{% capture markdown %}
# Heading 1

## `Heading` 2.1

### Heading **3**

#### Heading _4_

## Heading 2.2
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text sanitize=false %}

<!-- /// -->

<ul>
<li>
<a href="#heading-1">Heading 1</a>
<ul>
<li>
<a href="#heading-21"><code class="highlighter-rouge">Heading</code> 2.1</a>
<ul>
<li>
<a href="#heading-3">Heading <strong>3</strong></a>
<ul>
<li><a href="#heading-4">Heading <em>4</em></a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#heading-22">Heading 2.2</a></li>
</ul>
</li>
</ul>
40 changes: 40 additions & 0 deletions _tests/sanitizeEnabled.md
@@ -0,0 +1,40 @@
---
# Given `sanitize` is set to true, any HTML in the TOC should be stripped
---

{% capture markdown %}
# Heading 1

## `Heading` 2.1

### Heading **3**

#### Heading _4_

## Heading 2.2
{% endcapture %}
{% assign text = markdown | markdownify %}

{% include toc.html html=text sanitize=true %}

<!-- /// -->

<ul>
<li>
<a href="#heading-1">Heading 1</a>
<ul>
<li>
<a href="#heading-21">Heading 2.1</a>
<ul>
<li>
<a href="#heading-3">Heading 3</a>
<ul>
<li><a href="#heading-4">Heading 4</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#heading-22">Heading 2.2</a></li>
</ul>
</li>
</ul>

0 comments on commit 2a53d7c

Please sign in to comment.