Skip to content

Commit d0be329

Browse files
tests for a11y and arrow highlighting
these test some elements we saw bad behavior in nojs mode also, a rather more severe bug where light highlighting is being applied
1 parent 6db4e21 commit d0be329

File tree

4 files changed

+151
-1
lines changed

4 files changed

+151
-1
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: a11y syntax highlighting
3+
execute:
4+
echo: false
5+
warning: false
6+
theme:
7+
light: [cosmo, theme.scss]
8+
dark: [cosmo, theme-dark.scss]
9+
highlight-style: a11y
10+
---
11+
12+
13+
```markdown
14+
![asdf](asd.png)
15+
```
16+
17+
18+
```python
19+
#| label: fig-polar
20+
#| fig-cap: "A line plot on a polar axis"
21+
22+
import numpy as np
23+
import matplotlib.pyplot as plt
24+
25+
r = np.arange(0, 2, 0.01)
26+
theta = 2 * np.pi * r
27+
fig, ax = plt.subplots(
28+
subplot_kw = {'projection': 'polar'}
29+
)
30+
ax.plot(theta, r)
31+
ax.set_rticks([0.5, 1, 1.5, 2])
32+
ax.grid(True)
33+
plt.show()
34+
```
35+
36+
```r
37+
nycflights13::flights %>%
38+
mutate(
39+
cancelled = is.na(dep_time),
40+
sched_hour = sched_dep_time %/% 100,
41+
sched_min = sched_dep_time %% 100,
42+
sched_dep_time = sched_hour + sched_min / 60
43+
) %>%
44+
ggplot(mapping = aes(sched_dep_time)) +
45+
geom_freqpoly(mapping = aes(colour = cancelled), binwidth = 1/4) +
46+
labs (x = "Scheduled Departure Time")
47+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
format: html
3+
title: arrow syntax highlighting
4+
theme:
5+
light: united
6+
dark: slate
7+
_quarto:
8+
tests:
9+
html:
10+
ensureHtmlElements:
11+
- []
12+
- ["link[href*=\"-dark-\"]"]
13+
---
14+
15+
## Hello
16+
17+
```markdown
18+
![asdf](asd.png)
19+
```
20+
21+
22+
```python
23+
#| label: fig-polar
24+
#| fig-cap: "A line plot on a polar axis"
25+
26+
import numpy as np
27+
import matplotlib.pyplot as plt
28+
29+
r = np.arange(0, 2, 0.01)
30+
theta = 2 * np.pi * r
31+
fig, ax = plt.subplots(
32+
subplot_kw = {'projection': 'polar'}
33+
)
34+
ax.plot(theta, r)
35+
ax.set_rticks([0.5, 1, 1.5, 2])
36+
ax.grid(True)
37+
plt.show()
38+
```
39+
40+
```r
41+
nycflights13::flights %>%
42+
mutate(
43+
cancelled = is.na(dep_time),
44+
sched_hour = sched_dep_time %/% 100,
45+
sched_min = sched_dep_time %% 100,
46+
sched_dep_time = sched_hour + sched_min / 60
47+
) %>%
48+
ggplot(mapping = aes(sched_dep_time)) +
49+
geom_freqpoly(mapping = aes(colour = cancelled), binwidth = 1/4) +
50+
labs (x = "Scheduled Departure Time")
51+
```
52+

tests/integration/playwright/tests/html-dark-mode-nojs.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@ test('Light brand default, no JS', async ({ page }) => {
2222
});
2323

2424

25+
test('Syntax highlighting, a11y, no JS', async ({ page }) => {
26+
// This document use a custom theme file that change the background color of the title banner
27+
// Same user defined color should be used in both dark and light theme
28+
await page.goto('./html/dark-brand/syntax-highlighting/a11y-syntax-highlighting.html');
29+
const locatr = await page.locator('body').first();
30+
await expect(locatr).toHaveClass('fullcontent quarto-light');
31+
await expect(locatr).toHaveCSS('background-color', 'rgb(255, 255, 255)');
32+
const importKeyword = await page.locator('span.im').first();
33+
await expect(importKeyword).toHaveCSS('color', 'rgb(84, 84, 84)');
34+
});
35+
36+
37+
test('Syntax highlighting, arrow, no JS', async ({ page }) => {
38+
// This document use a custom theme file that change the background color of the title banner
39+
// Same user defined color should be used in both dark and light theme
40+
await page.goto('./html/dark-brand/syntax-highlighting/arrow-syntax-highlighting.html');
41+
const locatr = await page.locator('body').first();
42+
await expect(locatr).toHaveClass('fullcontent quarto-light');
43+
await expect(locatr).toHaveCSS('background-color', 'rgb(255, 255, 255)');
44+
const link = await page.locator('span.al').first();
45+
await expect(link).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
46+
});
47+
2548
test('Project dark brand default, no JS', async ({ page }) => {
2649
// This document use a custom theme file that change the background color of the title banner
2750
// Same user defined color should be used in both dark and light theme

tests/integration/playwright/tests/html-dark-mode.spec.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,32 @@ test('Brand false remove project brand', async ({ page }) => {
3232
await expect(locatr).toHaveCSS('background-color', 'rgb(255, 255, 255)');
3333
// no toggle
3434
expect(await page.locator('a.quarto-color-scheme-toggle').count()).toEqual(0);
35-
});
35+
});
36+
37+
38+
test('Syntax highlighting, a11y, with JS', async ({ page }) => {
39+
// This document use a custom theme file that change the background color of the title banner
40+
// Same user defined color should be used in both dark and light theme
41+
await page.goto('./html/dark-brand/syntax-highlighting/a11y-syntax-highlighting.html');
42+
const locatr = await page.locator('body').first();
43+
await expect(locatr).toHaveClass('fullcontent quarto-light');
44+
await expect(locatr).toHaveCSS('background-color', 'rgb(255, 255, 255)');
45+
const importKeyword = await page.locator('span.im').first();
46+
// light highlight stylesheet
47+
await expect(importKeyword).toHaveCSS('color', 'rgb(84, 84, 84)');
48+
await page.locator("a.quarto-color-scheme-toggle").click();
49+
// dark highlight stylesheet
50+
await expect(importKeyword).toHaveCSS('color', 'rgb(248, 248, 242)');
51+
});
52+
53+
54+
test('Syntax highlighting, arrow, with JS', async ({ page }) => {
55+
// This document use a custom theme file that change the background color of the title banner
56+
// Same user defined color should be used in both dark and light theme
57+
await page.goto('./html/dark-brand/syntax-highlighting/arrow-syntax-highlighting.html');
58+
const locatr = await page.locator('body').first();
59+
await expect(locatr).toHaveClass('fullcontent quarto-light');
60+
await expect(locatr).toHaveCSS('background-color', 'rgb(255, 255, 255)');
61+
const link = await page.locator('span.al').first();
62+
await expect(link).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
63+
});

0 commit comments

Comments
 (0)