1
1
import { argosScreenshot } from '@argos-ci/playwright' ;
2
2
import {
3
3
CustomizationBackground ,
4
+ CustomizationCorners ,
5
+ CustomizationFont ,
4
6
CustomizationHeaderPreset ,
5
7
CustomizationIconsStyle ,
6
8
CustomizationLocale ,
9
+ CustomizationThemeMode ,
7
10
SiteCustomizationSettings ,
8
11
} from '@gitbook/api' ;
9
12
import { test , expect , Page } from '@playwright/test' ;
10
13
import jwt from 'jsonwebtoken' ;
11
14
import rison from 'rison' ;
12
15
import { DeepPartial } from 'ts-essentials' ;
16
+ import deepMerge from 'deepmerge' ;
13
17
14
18
import { getContentTestURL } from '../tests/utils' ;
15
19
@@ -35,6 +39,18 @@ const allLocales: CustomizationLocale[] = [
35
39
CustomizationLocale . Zh ,
36
40
] ;
37
41
42
+ const allThemeModes : CustomizationThemeMode [ ] = [
43
+ CustomizationThemeMode . Light ,
44
+ CustomizationThemeMode . Dark ,
45
+ ] ;
46
+
47
+ const allThemePresets : CustomizationHeaderPreset [ ] = [
48
+ CustomizationHeaderPreset . Default ,
49
+ CustomizationHeaderPreset . Bold ,
50
+ CustomizationHeaderPreset . Contrast ,
51
+ CustomizationHeaderPreset . Custom ,
52
+ ] ;
53
+
38
54
async function waitForCookiesDialog ( page : Page ) {
39
55
const dialog = page . getByRole ( 'dialog' , { name : 'Cookies' } ) ;
40
56
const accept = dialog . getByRole ( 'button' , { name : 'Accept' } ) ;
@@ -436,30 +452,38 @@ const testCases: TestsCase[] = [
436
452
{
437
453
name : 'Customization' ,
438
454
baseUrl : 'https://gitbook.gitbook.io/test-gitbook-open/' ,
439
- tests : [
455
+ tests : allThemeModes . flatMap ( ( theme ) => [
440
456
{
441
- name : ' Without header' ,
457
+ name : ` Without header - Theme ${ theme } ` ,
442
458
url : getCustomizationURL ( {
443
459
header : {
444
460
preset : CustomizationHeaderPreset . None ,
445
461
links : [ ] ,
446
462
} ,
463
+ themes : {
464
+ default : theme ,
465
+ toggeable : false ,
466
+ } ,
447
467
} ) ,
448
468
run : waitForCookiesDialog ,
449
469
} ,
450
470
{
451
- name : ' With duotone icons' ,
471
+ name : ` With duotone icons - Theme ${ theme } ` ,
452
472
url :
453
473
'page-options/page-with-icon' +
454
474
getCustomizationURL ( {
455
475
styling : {
456
476
icons : CustomizationIconsStyle . Duotone ,
457
477
} ,
478
+ themes : {
479
+ default : theme ,
480
+ toggeable : false ,
481
+ } ,
458
482
} ) ,
459
483
run : waitForCookiesDialog ,
460
484
} ,
461
485
{
462
- name : ' With header buttons' ,
486
+ name : ` With header buttons - Theme ${ theme } ` ,
463
487
url : getCustomizationURL ( {
464
488
header : {
465
489
preset : CustomizationHeaderPreset . Default ,
@@ -476,39 +500,16 @@ const testCases: TestsCase[] = [
476
500
} ,
477
501
] ,
478
502
} ,
479
- } ) ,
480
- run : waitForCookiesDialog ,
481
- } ,
482
- {
483
- name : 'With tint - Legacy background match' ,
484
- url : getCustomizationURL ( {
485
- styling : {
486
- background : CustomizationBackground . Match ,
487
- } ,
488
- header : {
489
- preset : CustomizationHeaderPreset . Default ,
490
- links : [
491
- {
492
- title : 'Secondary button' ,
493
- to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
494
- style : 'button-secondary' ,
495
- } ,
496
- {
497
- title : 'Primary button' ,
498
- to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
499
- style : 'button-primary' ,
500
- } ,
501
- ] ,
503
+ themes : {
504
+ default : theme ,
505
+ toggeable : false ,
502
506
} ,
503
507
} ) ,
504
508
run : waitForCookiesDialog ,
505
509
} ,
506
510
{
507
- name : 'With tint - Default preset' ,
511
+ name : `Without tint - Default preset - Theme ${ theme } ` ,
508
512
url : getCustomizationURL ( {
509
- styling : {
510
- tint : { color : { light : '#346DDB' , dark : '#346DDB' } } ,
511
- } ,
512
513
header : {
513
514
preset : CustomizationHeaderPreset . Default ,
514
515
links : [
@@ -524,41 +525,27 @@ const testCases: TestsCase[] = [
524
525
} ,
525
526
] ,
526
527
} ,
527
- } ) ,
528
- run : waitForCookiesDialog ,
529
- } ,
530
- {
531
- name : 'With tint - Bold preset' ,
532
- url : getCustomizationURL ( {
533
- styling : {
534
- tint : { color : { light : '#346DDB' , dark : '#346DDB' } } ,
535
- } ,
536
- header : {
537
- preset : CustomizationHeaderPreset . Bold ,
538
- links : [
539
- {
540
- title : 'Secondary button' ,
541
- to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
542
- style : 'button-secondary' ,
543
- } ,
544
- {
545
- title : 'Primary button' ,
546
- to : { kind : 'url' , url : 'https://www.gitbook.com' } ,
547
- style : 'button-primary' ,
548
- } ,
549
- ] ,
528
+ themes : {
529
+ default : theme ,
530
+ toggeable : false ,
550
531
} ,
551
532
} ) ,
552
533
run : waitForCookiesDialog ,
553
534
} ,
554
- {
555
- name : ' With tint - Contrast' ,
535
+ ... allThemePresets . flatMap ( ( preset ) => ( {
536
+ name : ` With tint - Preset ${ preset } - Theme ${ theme } ` ,
556
537
url : getCustomizationURL ( {
557
538
styling : {
558
539
tint : { color : { light : '#346DDB' , dark : '#346DDB' } } ,
559
540
} ,
560
541
header : {
561
- preset : CustomizationHeaderPreset . Contrast ,
542
+ preset,
543
+ ...( preset === CustomizationHeaderPreset . Custom
544
+ ? {
545
+ backgroundColor : { light : '#C62C68' , dark : '#EF96B8' } ,
546
+ linkColor : { light : '#4DDE98' , dark : '#0C693D' } ,
547
+ }
548
+ : { } ) ,
562
549
links : [
563
550
{
564
551
title : 'Secondary button' ,
@@ -572,19 +559,21 @@ const testCases: TestsCase[] = [
572
559
} ,
573
560
] ,
574
561
} ,
562
+ themes : {
563
+ default : theme ,
564
+ toggeable : false ,
565
+ } ,
575
566
} ) ,
576
567
run : waitForCookiesDialog ,
577
- } ,
568
+ } ) ) ,
578
569
{
579
- name : ' With tint - Custom preset' ,
570
+ name : ` With tint - Legacy background match - Theme ${ theme } ` ,
580
571
url : getCustomizationURL ( {
581
572
styling : {
582
- tint : { color : { light : '#346DDB' , dark : '#346DDB' } } ,
573
+ background : CustomizationBackground . Match ,
583
574
} ,
584
575
header : {
585
- preset : CustomizationHeaderPreset . Custom ,
586
- backgroundColor : { light : '#C62C68' , dark : '#EF96B8' } ,
587
- linkColor : { light : '#4DDE98' , dark : '#0C693D' } ,
576
+ preset : CustomizationHeaderPreset . Default ,
588
577
links : [
589
578
{
590
579
title : 'Secondary button' ,
@@ -598,10 +587,14 @@ const testCases: TestsCase[] = [
598
587
} ,
599
588
] ,
600
589
} ,
590
+ themes : {
591
+ default : theme ,
592
+ toggeable : false ,
593
+ } ,
601
594
} ) ,
602
595
run : waitForCookiesDialog ,
603
596
} ,
604
- ] ,
597
+ ] ) ,
605
598
} ,
606
599
{
607
600
name : 'Ads' ,
@@ -971,7 +964,62 @@ for (const testCase of testCases) {
971
964
* Create a URL with customization settings.
972
965
*/
973
966
function getCustomizationURL ( partial : DeepPartial < SiteCustomizationSettings > ) : string {
974
- const encoded = rison . encode_object ( partial ) ;
967
+ /**
968
+ * Default customization settings.
969
+ *
970
+ * The customization object passed to the URL should be a valid API settings object. Hence we extend the test with necessary defaults.
971
+ */
972
+ const DEFAULT_CUSTOMIZATION : SiteCustomizationSettings = {
973
+ styling : {
974
+ primaryColor : { light : '#346DDB' , dark : '#346DDB' } ,
975
+ corners : CustomizationCorners . Rounded ,
976
+ font : CustomizationFont . Inter ,
977
+ background : CustomizationBackground . Plain ,
978
+ icons : CustomizationIconsStyle . Regular ,
979
+ } ,
980
+ internationalization : {
981
+ locale : CustomizationLocale . En ,
982
+ } ,
983
+ favicon : { } ,
984
+ header : {
985
+ preset : CustomizationHeaderPreset . Default ,
986
+ links : [ ] ,
987
+ } ,
988
+ footer : {
989
+ groups : [ ] ,
990
+ } ,
991
+ themes : {
992
+ default : CustomizationThemeMode . Light ,
993
+ toggeable : true ,
994
+ } ,
995
+ pdf : {
996
+ enabled : true ,
997
+ } ,
998
+ feedback : {
999
+ enabled : false ,
1000
+ } ,
1001
+ aiSearch : {
1002
+ enabled : true ,
1003
+ } ,
1004
+ advancedCustomization : {
1005
+ enabled : true ,
1006
+ } ,
1007
+ git : {
1008
+ showEditLink : false ,
1009
+ } ,
1010
+ pagination : {
1011
+ enabled : true ,
1012
+ } ,
1013
+ trademark : {
1014
+ enabled : true ,
1015
+ } ,
1016
+ privacyPolicy : {
1017
+ url : 'https://www.gitbook.com/privacy' ,
1018
+ } ,
1019
+ socialPreview : { } ,
1020
+ } ;
1021
+
1022
+ const encoded = rison . encode_object ( deepMerge ( DEFAULT_CUSTOMIZATION , partial ) ) ;
975
1023
976
1024
const searchParams = new URLSearchParams ( ) ;
977
1025
searchParams . set ( 'customization' , encoded ) ;
0 commit comments