1
1
import { argosScreenshot } from '@argos-ci/playwright' ;
2
2
import {
3
3
CustomizationBackground ,
4
+ CustomizationContentLink ,
4
5
CustomizationCorners ,
5
6
CustomizationFont ,
7
+ CustomizationHeaderItem ,
6
8
CustomizationHeaderPreset ,
7
9
CustomizationIconsStyle ,
8
10
CustomizationLocale ,
9
11
CustomizationSidebarBackgroundStyle ,
10
12
CustomizationSidebarListStyle ,
13
+ CustomizationTheme ,
14
+ CustomizationThemedColor ,
11
15
CustomizationThemeMode ,
12
16
SiteCustomizationSettings ,
13
17
} from '@gitbook/api' ;
@@ -81,7 +85,26 @@ const allThemeModes: CustomizationThemeMode[] = [
81
85
CustomizationThemeMode . Dark ,
82
86
] ;
83
87
84
- const allThemePresets : CustomizationHeaderPreset [ ] = [
88
+ const allTintColors : Array < {
89
+ label : string ;
90
+ value : CustomizationThemedColor | undefined ;
91
+ } > = [
92
+ {
93
+ label : 'Off' ,
94
+ value : undefined ,
95
+ } ,
96
+ { label : 'Primary' , value : { light : '#346DDB' , dark : '#346DDB' } } ,
97
+ { label : 'Custom' , value : { light : '#C62C68' , dark : '#EF96B8' } } ,
98
+ ] ;
99
+
100
+ const allThemes : CustomizationTheme [ ] = [
101
+ CustomizationTheme . Clean ,
102
+ CustomizationTheme . Muted ,
103
+ CustomizationTheme . Bold ,
104
+ CustomizationTheme . Gradient ,
105
+ ] ;
106
+
107
+ const allDeprecatedThemePresets : CustomizationHeaderPreset [ ] = [
85
108
CustomizationHeaderPreset . Default ,
86
109
CustomizationHeaderPreset . Bold ,
87
110
CustomizationHeaderPreset . Contrast ,
@@ -93,6 +116,23 @@ const allSidebarBackgroundStyles: CustomizationSidebarBackgroundStyle[] = [
93
116
CustomizationSidebarBackgroundStyle . Filled ,
94
117
] ;
95
118
119
+ // Common customization settings
120
+
121
+ const headerLinks : CustomizationHeaderItem [ ] = [
122
+ {
123
+ title : 'Secondary button' ,
124
+ to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
125
+ style : 'button-secondary' ,
126
+ links : [ ] ,
127
+ } ,
128
+ {
129
+ title : 'Primary button' ,
130
+ to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
131
+ style : 'button-primary' ,
132
+ links : [ ] ,
133
+ } ,
134
+ ] ;
135
+
96
136
async function waitForCookiesDialog ( page : Page ) {
97
137
const dialog = page . getByRole ( 'dialog' , { name : 'Cookies' } ) ;
98
138
const accept = dialog . getByRole ( 'button' , { name : 'Accept' } ) ;
@@ -561,90 +601,94 @@ const testCases: TestsCase[] = [
561
601
{
562
602
name : 'Customization' ,
563
603
baseUrl : 'https://gitbook.gitbook.io/test-gitbook-open/' ,
564
- tests : allThemeModes . flatMap ( ( theme ) => [
604
+ tests : allThemeModes . flatMap ( ( themeMode ) => [
565
605
{
566
- name : `Without header - Theme ${ theme } ` ,
606
+ name : `Without header - Theme mode ${ themeMode } ` ,
567
607
url : getCustomizationURL ( {
568
608
header : {
569
609
preset : CustomizationHeaderPreset . None ,
570
610
links : [ ] ,
571
611
} ,
572
612
themes : {
573
- default : theme ,
613
+ default : themeMode ,
574
614
toggeable : false ,
575
615
} ,
576
616
} ) ,
577
617
run : waitForCookiesDialog ,
578
618
} ,
579
619
{
580
- name : `With duotone icons - Theme ${ theme } ` ,
620
+ name : `With duotone icons - Theme mode ${ themeMode } ` ,
581
621
url :
582
622
'page-options/page-with-icon' +
583
623
getCustomizationURL ( {
584
624
styling : {
585
625
icons : CustomizationIconsStyle . Duotone ,
586
626
} ,
587
627
themes : {
588
- default : theme ,
628
+ default : themeMode ,
589
629
toggeable : false ,
590
630
} ,
591
631
} ) ,
592
632
run : waitForCookiesDialog ,
593
633
} ,
594
634
{
595
- name : `With header buttons - Theme ${ theme } ` ,
635
+ name : `With header buttons - Theme mode ${ themeMode } ` ,
596
636
url : getCustomizationURL ( {
597
637
header : {
598
638
preset : CustomizationHeaderPreset . Default ,
599
- links : [
600
- {
601
- title : 'Secondary button' ,
602
- to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
603
- style : 'button-secondary' ,
604
- } ,
605
- {
606
- title : 'Primary button' ,
607
- to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
608
- style : 'button-primary' ,
609
- } ,
610
- ] ,
639
+ links : headerLinks ,
611
640
} ,
612
641
themes : {
613
- default : theme ,
642
+ default : themeMode ,
614
643
toggeable : false ,
615
644
} ,
616
645
} ) ,
617
646
run : waitForCookiesDialog ,
618
647
} ,
619
648
{
620
- name : `Without tint - Default preset - Theme ${ theme } ` ,
649
+ name : `Without tint - Default preset - Theme mode ${ themeMode } ` ,
621
650
url : getCustomizationURL ( {
622
651
header : {
623
652
preset : CustomizationHeaderPreset . Default ,
624
- links : [
625
- {
626
- title : 'Secondary button' ,
627
- to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
628
- style : 'button-secondary' ,
629
- } ,
630
- {
631
- title : 'Primary button' ,
632
- to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
633
- style : 'button-primary' ,
634
- } ,
635
- ] ,
653
+ links : headerLinks ,
636
654
} ,
637
655
themes : {
638
- default : theme ,
656
+ default : themeMode ,
639
657
toggeable : false ,
640
658
} ,
641
659
} ) ,
642
660
run : waitForCookiesDialog ,
643
661
} ,
644
- // Theme-specific tests
645
- ...allThemePresets . flatMap ( ( preset ) => [
662
+ // New site themes
663
+ ...allThemes . flatMap ( ( theme ) => [
664
+ ...allTintColors . flatMap ( ( tint ) => [
665
+ ...allSidebarBackgroundStyles . flatMap ( ( sidebarStyle ) => ( {
666
+ name : `Theme ${ theme } - Tint ${ tint . label } - Sidebar ${ sidebarStyle } - Mode ${ themeMode } ` ,
667
+ url : getCustomizationURL ( {
668
+ styling : {
669
+ theme,
670
+ ...( tint . value ? { tint : { color : tint . value } } : { } ) ,
671
+ sidebar : {
672
+ background : sidebarStyle ,
673
+ list : CustomizationSidebarListStyle . Default ,
674
+ } ,
675
+ } ,
676
+ header : {
677
+ links : headerLinks ,
678
+ } ,
679
+ themes : {
680
+ default : themeMode ,
681
+ toggeable : false ,
682
+ } ,
683
+ } ) ,
684
+ run : waitForCookiesDialog ,
685
+ } ) ) ,
686
+ ] ) ,
687
+ ] ) ,
688
+ // Deprecated header themes
689
+ ...allDeprecatedThemePresets . flatMap ( ( preset ) => [
646
690
...allSidebarBackgroundStyles . flatMap ( ( sidebarStyle ) => ( {
647
- name : `With tint - Preset ${ preset } - Sidebar ${ sidebarStyle } - Theme ${ theme } ` ,
691
+ name : `With tint - Legacy header preset ${ preset } - Sidebar ${ sidebarStyle } - Theme mode ${ themeMode } ` ,
648
692
url : getCustomizationURL ( {
649
693
styling : {
650
694
tint : { color : { light : '#346DDB' , dark : '#346DDB' } } ,
@@ -661,50 +705,28 @@ const testCases: TestsCase[] = [
661
705
linkColor : { light : '#4DDE98' , dark : '#0C693D' } ,
662
706
}
663
707
: { } ) ,
664
- links : [
665
- {
666
- title : 'Secondary button' ,
667
- to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
668
- style : 'button-secondary' ,
669
- } ,
670
- {
671
- title : 'Primary button' ,
672
- to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
673
- style : 'button-primary' ,
674
- } ,
675
- ] ,
708
+ links : headerLinks ,
676
709
} ,
677
710
themes : {
678
- default : theme ,
711
+ default : themeMode ,
679
712
toggeable : false ,
680
713
} ,
681
714
} ) ,
682
715
run : waitForCookiesDialog ,
683
716
} ) ) ,
684
717
] ) ,
685
718
{
686
- name : `With tint - Legacy background match - Theme ${ theme } ` ,
719
+ name : `With tint - Legacy background match - Theme mode ${ themeMode } ` ,
687
720
url : getCustomizationURL ( {
688
721
styling : {
689
722
background : CustomizationBackground . Match ,
690
723
} ,
691
724
header : {
692
725
preset : CustomizationHeaderPreset . Default ,
693
- links : [
694
- {
695
- title : 'Secondary button' ,
696
- to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
697
- style : 'button-secondary' ,
698
- } ,
699
- {
700
- title : 'Primary button' ,
701
- to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
702
- style : 'button-primary' ,
703
- } ,
704
- ] ,
726
+ links : headerLinks ,
705
727
} ,
706
728
themes : {
707
- default : theme ,
729
+ default : themeMode ,
708
730
toggeable : false ,
709
731
} ,
710
732
} ) ,
@@ -1488,13 +1510,40 @@ for (const testCase of testCases) {
1488
1510
* Create a URL with customization settings.
1489
1511
*/
1490
1512
function getCustomizationURL ( partial : DeepPartial < SiteCustomizationSettings > ) : string {
1513
+ // We replicate the theme migration logic from the API to the tests, because the don't get these settings from the API.
1514
+ // We can remove this once the migration to the new themes have been completed and the new theme styles are verified
1515
+ // Map the theme preset (+ tint) to one of the new themes
1516
+ const newTheme = ( ( ) => {
1517
+ if ( partial . styling ?. theme ) {
1518
+ return partial . styling . theme ;
1519
+ }
1520
+
1521
+ switch ( partial . header ?. preset ) {
1522
+ case CustomizationHeaderPreset . Bold :
1523
+ case CustomizationHeaderPreset . Contrast :
1524
+ case CustomizationHeaderPreset . Custom :
1525
+ return CustomizationTheme . Bold ;
1526
+
1527
+ case CustomizationHeaderPreset . None :
1528
+ case CustomizationHeaderPreset . Default :
1529
+ if ( partial . styling ?. tint ) {
1530
+ return CustomizationTheme . Muted ;
1531
+ }
1532
+
1533
+ return CustomizationTheme . Clean ;
1534
+ default :
1535
+ return CustomizationTheme . Clean ;
1536
+ }
1537
+ } ) ( ) ;
1538
+
1491
1539
/**
1492
1540
* Default customization settings.
1493
1541
*
1494
1542
* The customization object passed to the URL should be a valid API settings object. Hence we extend the test with necessary defaults.
1495
1543
*/
1496
1544
const DEFAULT_CUSTOMIZATION : SiteCustomizationSettings = {
1497
1545
styling : {
1546
+ theme : newTheme ,
1498
1547
primaryColor : { light : '#346DDB' , dark : '#346DDB' } ,
1499
1548
corners : CustomizationCorners . Rounded ,
1500
1549
font : CustomizationFont . Inter ,
0 commit comments