From 1eae1aca89af19b00db09789ce7aa89fe3b344ac Mon Sep 17 00:00:00 2001 From: Mateusz Baginski Date: Thu, 14 Nov 2024 15:51:55 +0100 Subject: [PATCH 1/3] OS agnostic mocking of env in editor usage data helper tests. --- .../ckeditor5-core/tests/editor/utils/editorusagedata.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/ckeditor5-core/tests/editor/utils/editorusagedata.js b/packages/ckeditor5-core/tests/editor/utils/editorusagedata.js index 590b7a79b4d..84b7ae4dede 100644 --- a/packages/ckeditor5-core/tests/editor/utils/editorusagedata.js +++ b/packages/ckeditor5-core/tests/editor/utils/editorusagedata.js @@ -192,7 +192,7 @@ describe( 'getEditorUsageData()', () => { for ( const [ flag, osName ] of os ) { it( `should detect ${ osName } OS`, async () => { - sinon.stub( env, flag ).value( true ); + mockFlag( flag, true ); editor = await ClassicTestEditor.create( domElement, {} ); @@ -201,6 +201,12 @@ describe( 'getEditorUsageData()', () => { } ); } ); } + + function mockFlag( mockFlag ) { + for ( const [ flag ] of os ) { + sinon.stub( env, flag ).value( flag === mockFlag ); + } + } } ); describe( 'browser', () => { From e25eb63b701069fa4264d8c38ef583ccdae79010 Mon Sep 17 00:00:00 2001 From: Mateusz Baginski Date: Thu, 14 Nov 2024 15:53:49 +0100 Subject: [PATCH 2/3] Adjust browser mocks. --- .../tests/editor/utils/editorusagedata.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/ckeditor5-core/tests/editor/utils/editorusagedata.js b/packages/ckeditor5-core/tests/editor/utils/editorusagedata.js index 84b7ae4dede..431a9083fbb 100644 --- a/packages/ckeditor5-core/tests/editor/utils/editorusagedata.js +++ b/packages/ckeditor5-core/tests/editor/utils/editorusagedata.js @@ -218,11 +218,7 @@ describe( 'getEditorUsageData()', () => { for ( const [ flag, browser ] of browsers ) { it( `should detect ${ browser } browser`, async () => { - sinon.stub( env, flag ).value( true ); - - if ( flag !== 'isBlink' ) { - sinon.stub( env, 'isBlink' ).value( false ); - } + mockFlag( flag, true ); editor = await ClassicTestEditor.create( domElement, {} ); @@ -231,6 +227,12 @@ describe( 'getEditorUsageData()', () => { } ); } ); } + + function mockFlag( mockFlag ) { + for ( const [ flag ] of browsers ) { + sinon.stub( env, flag ).value( flag === mockFlag ); + } + } } ); } ); From a7f19e58e9989a635e631c4bef6a722303581cb6 Mon Sep 17 00:00:00 2001 From: Mateusz Baginski Date: Thu, 14 Nov 2024 15:56:38 +0100 Subject: [PATCH 3/3] Drop unecessary argument. --- packages/ckeditor5-core/tests/editor/utils/editorusagedata.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ckeditor5-core/tests/editor/utils/editorusagedata.js b/packages/ckeditor5-core/tests/editor/utils/editorusagedata.js index 431a9083fbb..18e3a675ff9 100644 --- a/packages/ckeditor5-core/tests/editor/utils/editorusagedata.js +++ b/packages/ckeditor5-core/tests/editor/utils/editorusagedata.js @@ -192,7 +192,7 @@ describe( 'getEditorUsageData()', () => { for ( const [ flag, osName ] of os ) { it( `should detect ${ osName } OS`, async () => { - mockFlag( flag, true ); + mockFlag( flag ); editor = await ClassicTestEditor.create( domElement, {} ); @@ -218,7 +218,7 @@ describe( 'getEditorUsageData()', () => { for ( const [ flag, browser ] of browsers ) { it( `should detect ${ browser } browser`, async () => { - mockFlag( flag, true ); + mockFlag( flag ); editor = await ClassicTestEditor.create( domElement, {} );