1- import puppeteer from 'puppeteer'
2- import { testServer } from '../run'
3-
4- let serverPort = 3003
5-
6- describe ( "a fresh instance of biscuitman" , ( ) => {
7- let server , browser , page
8- let getConfig , getConsent , loadConsents
9-
10- beforeAll ( async ( ) => {
11- server = await testServer ( serverPort )
12-
13- browser = await puppeteer . launch ( {
14- headless : true ,
15- // slowMo: showBrowser ? 100 : false,
16- // devtools: showBrowser
17- ignoreHTTPSErrors : true
18- } )
19-
20- page = await context . newPage ( )
21-
22- await page . setViewport ( { width : 1200 , height : 600 } ) ;
23-
24- page . on ( 'pageerror' , ( error ) => {
25- console . error ( 'Page error:' , error )
26- } )
27-
28- page . on ( 'console' , ( msg ) => {
29- let text = msg . text ( )
30- if ( msg . type ( ) === 'error' ) {
31- if ( text . startsWith ( 'Failed to load resource:' ) ) return false
32- console . log ( "Console error:" , msg . text ( ) )
33- }
34- } )
35-
36- getConfig = ( ) => page . evaluate ( ( ) => window . biscuitman )
37- getConsent = ( ) => page . evaluate ( ( ) => window . Consent )
38- loadConsents = ( ) => page . evaluate ( ( ) => JSON . parse ( localStorage . getItem ( 'myconsent' ) ) )
1+ describe ( 'a fresh instance of biscuitman' , ( ) => {
2+ test ( 'should load without without consents' , async ( ) => {
3+ expect ( await utils . getConsent ( ) ) . toBeEmpty ( )
4+ expect ( await utils . loadConsents ( ) ) . toBeNull ( )
395 } )
406
41- beforeEach ( async ( ) => {
42- await page . goto ( `https://localhost:${ serverPort } ` , { waitUntil : 'domcontentloaded' } )
43- } )
44-
45- afterEach ( async ( ) => {
46- // Wipe storages
47- const client = await page . target ( ) . createCDPSession ( )
48- await client . send ( 'Storage.clearDataForOrigin' , {
49- origin : `https://localhost:${ serverPort } ` ,
50- storageTypes : 'cookies, local_storage, session_storage, indexeddb, websql, cache_storage, service_workers'
51- } )
52- } )
53-
54- afterAll ( async ( ) => {
55- await browser . close ( )
56- server . exit ( )
57- } )
58-
59- test ( "should load without without consents" , async ( ) => {
60- expect ( await getConsent ( ) ) . toBeEmpty ( )
61- expect ( await loadConsents ( ) ) . toBeNull ( )
62- } )
63-
64- test ( "should display a UI" , async ( ) => {
7+ test ( 'should display a UI' , async ( ) => {
658 const ui = await page . $ ( '.biscuitman' )
669 expect ( ui ) . not . toBeNull ( )
67-
10+
6811 const banner = await page . $ ( '.biscuitman article' )
6912 expect ( await banner . isVisible ( ) ) . toBe ( true )
7013 } )
7114
72- test ( " should open settings modal after clicking settings" , async ( ) => {
15+ test ( ' should open settings modal after clicking settings' , async ( ) => {
7316 await page . click ( 'button[data-id=settings]' )
7417 const dialog = await page . $ ( 'dialog' )
7518 expect ( await dialog . isVisible ( ) ) . toBe ( true )
7619 } )
7720
78- test ( " should close settings modal after clicking close" , async ( ) => {
21+ test ( ' should close settings modal after clicking close' , async ( ) => {
7922 await page . click ( 'button[data-id=settings]' )
8023 const dialog = await page . $ ( 'dialog' )
8124 await page . click ( 'button[data-id=close]' )
8225 expect ( await dialog . isVisible ( ) ) . toBe ( false )
8326 } )
8427
85- test ( " should hide UI and save consents correctly after clicking accept" , async ( ) => {
28+ test ( ' should hide UI and save consents correctly after clicking accept' , async ( ) => {
8629 await page . click ( 'button[data-id=accept]' )
8730
8831 const banner = await page . $ ( '.biscuitman article' )
8932 expect ( await banner . isVisible ( ) ) . toBe ( false )
9033
9134 let entries = [
92- [ 'analytics' , true ] ,
93- [ 'functional' , true ] ,
94- [ 'advertisement' , true ] ,
95- [ 'performance' , true ] ,
96- [ 'uncategorized' , true ] ,
35+ [ 'analytics' , true ] ,
36+ [ 'functional' , true ] ,
37+ [ 'advertisement' , true ] ,
38+ [ 'performance' , true ] ,
39+ [ 'uncategorized' , true ]
9740 ]
9841
99- expect ( await getConsent ( ) ) . toContainEntries ( entries )
100- expect ( await loadConsents ( ) ) . toContainEntries ( entries )
42+ expect ( await utils . getConsent ( ) ) . toContainEntries ( entries )
43+ expect ( await utils . loadConsents ( ) ) . toContainEntries ( entries )
10144 } )
10245
103- test ( " should hide UI and save consents correctly after clicking reject" , async ( ) => {
46+ test ( ' should hide UI and save consents correctly after clicking reject' , async ( ) => {
10447 await page . click ( 'button[data-id=reject]' )
10548
10649 const banner = await page . $ ( '.biscuitman article' )
10750 expect ( await banner . isVisible ( ) ) . toBe ( false )
10851
10952 let entries = [
110- [ 'analytics' , false ] ,
111- [ 'functional' , false ] ,
112- [ 'advertisement' , false ] ,
113- [ 'performance' , false ] ,
114- [ 'uncategorized' , false ] ,
53+ [ 'analytics' , false ] ,
54+ [ 'functional' , false ] ,
55+ [ 'advertisement' , false ] ,
56+ [ 'performance' , false ] ,
57+ [ 'uncategorized' , false ]
11558 ]
116- expect ( await getConsent ( ) ) . toContainEntries ( entries )
117- expect ( await loadConsents ( ) ) . toContainEntries ( entries )
59+ expect ( await utils . getConsent ( ) ) . toContainEntries ( entries )
60+ expect ( await utils . loadConsents ( ) ) . toContainEntries ( entries )
11861 } )
11962
120- test ( "should hide UI and save consents correctly after selecting some sections" , async ( ) => {
121-
63+ test ( 'should hide UI and save consents correctly after selecting some sections' , async ( ) => {
12264 await page . click ( 'button[data-id=settings]' )
12365 const dialog = await page . $ ( 'dialog' )
12466 await page . click ( '[for=biscuitman_analytics]' )
@@ -131,27 +73,26 @@ describe("a fresh instance of biscuitman", () => {
13173 expect ( await banner . isVisible ( ) ) . toBe ( false )
13274
13375 let entries = [
134- [ 'analytics' , true ] ,
135- [ 'functional' , true ] ,
136- [ 'advertisement' , false ] ,
137- [ 'performance' , true ] ,
138- [ 'uncategorized' , false ]
76+ [ 'analytics' , true ] ,
77+ [ 'functional' , true ] ,
78+ [ 'advertisement' , false ] ,
79+ [ 'performance' , true ] ,
80+ [ 'uncategorized' , false ]
13981 ]
14082
141- expect ( await getConsent ( ) ) . toContainEntries ( entries )
142- expect ( await loadConsents ( ) ) . toContainEntries ( entries )
83+ expect ( await utils . getConsent ( ) ) . toContainEntries ( entries )
84+ expect ( await utils . loadConsents ( ) ) . toContainEntries ( entries )
14385 } )
14486
145-
14687 test ( 'should remove consent preferences when "bmInvalidate" is called' , async ( ) => {
14788 await page . evaluate ( ( ) => window . bmInvalidate ( ) )
148- expect ( await getConsent ( ) ) . toEqual ( { } )
149- expect ( await loadConsents ( ) ) . toBeNull ( )
89+ expect ( await utils . getConsent ( ) ) . toEqual ( { } )
90+ expect ( await utils . loadConsents ( ) ) . toBeNull ( )
15091 } )
15192
15293 test ( 'should update consent preferences when "bmUpdate" is called' , async ( ) => {
15394 await page . evaluate ( ( ) => window . bmUpdate ( ) )
154- const dialog = await page . $ ( " dialog" )
95+ const dialog = await page . $ ( ' dialog' )
15596 const dialogVisible = await page . evaluate (
15697 ( dialog ) => dialog . open ,
15798 dialog
0 commit comments