Skip to content

Commit 03b8f87

Browse files
playwright tests for dark brand
for #12319 testing theme/brand integration and dark brand also includes NoJS tests for #12173
1 parent 16ce21a commit 03b8f87

File tree

6 files changed

+162
-0
lines changed

6 files changed

+162
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
color:
2+
background: "#ccddff"
3+
foreground: "#336644"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: "dark brand - ggplot"
3+
brand:
4+
dark: red-background.yml
5+
light: blue-background.yml
6+
theme:
7+
dark: [cyborg, brand]
8+
light: [simplex, brand]
9+
execute:
10+
echo: false
11+
warning: false
12+
---
13+
14+
```{r}
15+
#| echo: false
16+
#| warning: false
17+
library(ggplot2)
18+
19+
ggplot_theme <- function(bgcolor, fgcolor) {
20+
theme_minimal(base_size = 11) %+%
21+
theme(
22+
panel.border = element_blank(),
23+
panel.grid.major.y = element_blank(),
24+
panel.grid.minor.y = element_blank(),
25+
panel.grid.major.x = element_blank(),
26+
panel.grid.minor.x = element_blank(),
27+
text = element_text(colour = fgcolor),
28+
axis.text = element_text(colour = fgcolor),
29+
rect = element_rect(colour = bgcolor, fill = bgcolor),
30+
plot.background = element_rect(fill = bgcolor, colour = NA),
31+
axis.line = element_line(colour = fgcolor),
32+
axis.ticks = element_line(colour = fgcolor)
33+
)
34+
}
35+
36+
brand_ggplot <- function(brand_yml) {
37+
brand <- yaml::yaml.load_file(brand_yml)
38+
ggplot_theme(brand$color$background, brand$color$foreground)
39+
}
40+
41+
blue_theme <- brand_ggplot("blue-background.yml")
42+
red_theme <- brand_ggplot("red-background.yml")
43+
44+
colour_scale <- scale_colour_manual(values = c("darkorange", "purple", "cyan4"))
45+
```
46+
47+
48+
```{r}
49+
#| renderings: [light, dark]
50+
ggplot(mtcars, aes(mpg, wt)) +
51+
geom_point(aes(colour = factor(cyl))) + blue_theme + colour_scale
52+
ggplot(mtcars, aes(mpg, wt)) +
53+
geom_point(aes(colour = factor(cyl))) + red_theme + colour_scale
54+
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: "dark brand - ggplot"
3+
brand:
4+
light: blue-background.yml
5+
dark: red-background.yml
6+
theme:
7+
light: simplex
8+
dark: cyborg # same effect as [brand, cyborg]
9+
execute:
10+
echo: false
11+
warning: false
12+
---
13+
14+
```{r}
15+
#| echo: false
16+
#| warning: false
17+
library(ggplot2)
18+
19+
ggplot_theme <- function(bgcolor, fgcolor) {
20+
theme_minimal(base_size = 11) %+%
21+
theme(
22+
panel.border = element_blank(),
23+
panel.grid.major.y = element_blank(),
24+
panel.grid.minor.y = element_blank(),
25+
panel.grid.major.x = element_blank(),
26+
panel.grid.minor.x = element_blank(),
27+
text = element_text(colour = fgcolor),
28+
axis.text = element_text(colour = fgcolor),
29+
rect = element_rect(colour = bgcolor, fill = bgcolor),
30+
plot.background = element_rect(fill = bgcolor, colour = NA),
31+
axis.line = element_line(colour = fgcolor),
32+
axis.ticks = element_line(colour = fgcolor)
33+
)
34+
}
35+
36+
brand_ggplot <- function(brand_yml) {
37+
brand <- yaml::yaml.load_file(brand_yml)
38+
ggplot_theme(brand$color$background, brand$color$foreground)
39+
}
40+
41+
blue_theme <- brand_ggplot("blue-background.yml")
42+
red_theme <- brand_ggplot("red-background.yml")
43+
44+
colour_scale <- scale_colour_manual(values = c("darkorange", "purple", "cyan4"))
45+
```
46+
47+
48+
```{r}
49+
#| renderings: [light, dark]
50+
ggplot(mtcars, aes(mpg, wt)) +
51+
geom_point(aes(colour = factor(cyl))) + blue_theme + colour_scale
52+
ggplot(mtcars, aes(mpg, wt)) +
53+
geom_point(aes(colour = factor(cyl))) + red_theme + colour_scale
54+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
color:
2+
background: "#42070b"
3+
foreground: "#cceedd"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test.use({ javaScriptEnabled: false });
4+
5+
test('Dark brand default, no JS', async ({ page }) => {
6+
// This document use a custom theme file that change the background color of the title banner
7+
// Same user defined color should be used in both dark and light theme
8+
await page.goto('./html/dark-brand/brand-after-theme.html');
9+
const locatr = await page.locator('body').first();
10+
await expect(locatr).toHaveClass('fullcontent quarto-dark');
11+
await expect(locatr).toHaveCSS('background-color', 'rgb(66, 7, 11)');
12+
});
13+
14+
15+
test('Light brand default, no JS', async ({ page }) => {
16+
// This document use a custom theme file that change the background color of the title banner
17+
// Same user defined color should be used in both dark and light theme
18+
await page.goto('./html/dark-brand/brand-before-theme.html');
19+
const locatr = await page.locator('body').first();
20+
await expect(locatr).toHaveClass('fullcontent quarto-light');
21+
await expect(locatr).toHaveCSS('background-color', 'rgb(252, 252, 252)');
22+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { test, expect } from '@playwright/test';
2+
3+
test('Dark and light brand after user themes', async ({ page }) => {
4+
// This document use a custom theme file that change the background color of the title banner
5+
// Same user defined color should be used in both dark and light theme
6+
await page.goto('./html/dark-brand/brand-after-theme.html');
7+
const locatr = await page.locator('body').first();
8+
await expect(locatr).toHaveClass('fullcontent quarto-dark');
9+
await expect(locatr).toHaveCSS('background-color', 'rgb(66, 7, 11)');
10+
await page.locator("a.quarto-color-scheme-toggle").click();
11+
const locatr2 = await page.locator('body').first();
12+
await expect(locatr2).toHaveCSS('background-color', 'rgb(204, 221, 255)');
13+
});
14+
15+
16+
test('Dark and light brand before user themes', async ({ page }) => {
17+
// This document use a custom theme file that change the background color of the title banner
18+
// Same user defined color should be used in both dark and light theme
19+
await page.goto('./html/dark-brand/brand-before-theme.html');
20+
const locatr = await page.locator('body').first();
21+
await expect(locatr).toHaveClass('fullcontent quarto-light');
22+
await expect(locatr).toHaveCSS('background-color', 'rgb(252, 252, 252)');
23+
await page.locator("a.quarto-color-scheme-toggle").click();
24+
const locatr2 = await page.locator('body').first();
25+
await expect(locatr2).toHaveCSS('background-color', 'rgb(6, 6, 6)');
26+
});

0 commit comments

Comments
 (0)