Skip to content

Commit c7e6bea

Browse files
committed
Add better examples of automated tests
1 parent dc35644 commit c7e6bea

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

docs/guides/automated-tests.md

+61-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,68 @@ One of the advantages of `render_patterns` is the ability for you to test the pa
2828

2929
## Visual regression testing
3030

31-
Pattern libraries are a natural fit for automated visual regression tests. Check out [BackstopJS](https://github.com/garris/BackstopJS) to get started.
31+
Pattern libraries are a natural fit for automated visual regression tests. Here is an example [BackstopJS](https://github.com/garris/BackstopJS) configuration file:
32+
33+
```json
34+
{
35+
"viewports": [
36+
{
37+
"label": "tablet",
38+
"width": 1024,
39+
"height": 768
40+
}
41+
],
42+
"scenarios": [
43+
{
44+
"label": "accordion.html",
45+
"url": "https://torchbox.github.io/django-pattern-library/dpl-rendered-patterns/molecules/accordion/accordion.html"
46+
},
47+
{
48+
"label": "person_page.html",
49+
"url": "https://torchbox.github.io/django-pattern-library/dpl-rendered-patterns/pages/people/person_page.html"
50+
}
51+
],
52+
"paths": {
53+
"bitmaps_reference": "backstop_data/bitmaps_reference",
54+
"bitmaps_test": "backstop_data/bitmaps_test",
55+
"engine_scripts": "backstop_data/engine_scripts",
56+
"html_report": "backstop_data/html_report",
57+
"ci_report": "backstop_data/ci_report"
58+
},
59+
"engine": "puppeteer"
60+
}
61+
```
62+
63+
Try this out by saving the file as `backstop.json`, then:
64+
65+
```sh
66+
npm install -g backstopjs
67+
backstop test
68+
```
3269

3370
## Accessibility testing
3471

3572
Here as well, pattern libraries are a natural fit, due to them providing the test data, and making it possible to test components in isolation. Have a look at [Pa11y](https://pa11y.org/) or [Lighthouse CI](https://github.com/GoogleChrome/lighthouse-ci) to get started.
73+
74+
Here is an example Pa11y configuration:
75+
76+
```js
77+
module.exports = {
78+
defaults: {
79+
standard: "WCAG2AAA",
80+
runners: ["axe"],
81+
},
82+
83+
urls: [
84+
"https://torchbox.github.io/django-pattern-library/dpl-rendered-patterns/molecules/accordion/accordion.html",
85+
"https://torchbox.github.io/django-pattern-library/dpl-rendered-patterns/pages/people/person_page.html",
86+
],
87+
};
88+
```
89+
90+
Try this out by saving the file as `pa11y.config.js`, then:
91+
92+
```sh
93+
npm install -g pa11y-ci
94+
pa11y-ci --config pa11y.config.js
95+
```

tests/templates/patterns/base.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<body>
1212
{% include "patterns/atoms/sprites/sprites.html" %}
1313

14-
{% block content %}{{ pattern_library_rendered_pattern }}{% endblock %}
14+
<main>
15+
{% block content %}{{ pattern_library_rendered_pattern }}{% endblock %}
16+
</main>
1517
<script src="{% static 'main.js' %}"></script>
1618
</body>
1719
</html>

tests/tests/test_commands.py

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def test_shows_wrap_fragment(self):
5656
<use xlink:href="#close"></use>
5757
</svg>
5858
59+
</main>
5960
<script src="/static/main.js"></script>
6061
</body>
6162
</html>""", stdout.getvalue())

0 commit comments

Comments
 (0)