Skip to content

Commit 59c5f14

Browse files
playwright tests for dark brand
for #12319 and (to a lesser degree) #12173 testing theme/brand integration and dark brand
1 parent 16ce21a commit 59c5f14

File tree

5 files changed

+141
-0
lines changed

5 files changed

+141
-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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { test, expect } from '@playwright/test';
2+
import { asRGB, checkBorderProperties, checkColor, getCSSProperty } from '../src/utils';
3+
4+
test('Dark and light brand after user themes', async ({ page }) => {
5+
// This document use a custom theme file that change the background color of the title banner
6+
// Same user defined color should be used in both dark and light theme
7+
await page.goto('./html/dark-brand/brand-after-theme.html');
8+
const locatr = await page.locator('body').first();
9+
await expect(locatr).toHaveClass('fullcontent quarto-dark');
10+
await expect(locatr).toHaveCSS('background-color', 'rgb(66, 7, 11)');
11+
await page.locator("a.quarto-color-scheme-toggle").click();
12+
const locatr2 = await page.locator('body').first();
13+
await expect(locatr2).toHaveCSS('background-color', 'rgb(204, 221, 255)');
14+
});
15+
16+
17+
test('Dark and light brand before user themes', async ({ page }) => {
18+
// This document use a custom theme file that change the background color of the title banner
19+
// Same user defined color should be used in both dark and light theme
20+
await page.goto('./html/dark-brand/brand-before-theme.html');
21+
const locatr = await page.locator('body').first();
22+
await expect(locatr).toHaveClass('fullcontent quarto-light');
23+
await expect(locatr).toHaveCSS('background-color', 'rgb(252, 252, 252)');
24+
await page.locator("a.quarto-color-scheme-toggle").click();
25+
const locatr2 = await page.locator('body').first();
26+
await expect(locatr2).toHaveCSS('background-color', 'rgb(6, 6, 6)');
27+
});

0 commit comments

Comments
 (0)