PluginProbe
BeyondWords – AI audio for publishers / 7.0.0
BeyondWords – AI audio for publishers v7.0.0
7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.7.0 All 43 releases
speechkit / src / editor / components / inspect-panel / helpers.test.js

helpers.test.js in BeyondWords – AI audio for publishers 7.0.0, at src/editor/components/inspect-panel/helpers.test.js

100 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* global describe, it, expect */
2
3 /**
4 * Internal dependencies
5 */
6 import { SYSTEM_META_KEYS, hasBeyondwordsData, getTextToCopy } from './helpers';
7
8 // Representative subset of the key lists PHP supplies via the settings store.
9 const CURRENT = [ 'beyondwords_generate_audio', 'beyondwords_content_id' ];
10 const DEPRECATED = [ 'speechkit_podcast_id' ];
11 const DATA_KEYS = [ ...CURRENT, ...DEPRECATED ];
12
13 describe( 'hasBeyondwordsData', () => {
14 it( 'is false when none of the data keys are populated', () => {
15 expect( hasBeyondwordsData( {}, DATA_KEYS ) ).toBe( false );
16 } );
17
18 it( 'ignores keys outside the supplied list (e.g. system fields)', () => {
19 expect(
20 hasBeyondwordsData(
21 { plugin_version: '5.0.0', wp_version: '6.5', wp_post_id: 123 },
22 DATA_KEYS
23 )
24 ).toBe( false );
25 } );
26
27 it( 'is true when a current data key is populated', () => {
28 expect(
29 hasBeyondwordsData( { beyondwords_content_id: '12345' }, DATA_KEYS )
30 ).toBe( true );
31 } );
32
33 it( 'is true when only a deprecated data key is populated', () => {
34 expect(
35 hasBeyondwordsData( { speechkit_podcast_id: '999' }, DATA_KEYS )
36 ).toBe( true );
37 } );
38
39 it( 'treats empty strings as no data', () => {
40 const empty = { beyondwords_content_id: '', speechkit_podcast_id: '' };
41 expect( hasBeyondwordsData( empty, DATA_KEYS ) ).toBe( false );
42 } );
43
44 it( 'reflects data added after mount (the stale-snapshot regression)', () => {
45 expect(
46 hasBeyondwordsData( { plugin_version: '5.0.0' }, DATA_KEYS )
47 ).toBe( false );
48 expect(
49 hasBeyondwordsData( { beyondwords_content_id: '12345' }, DATA_KEYS )
50 ).toBe( true );
51 } );
52
53 it( 'is false before the keys load (settings not yet fetched)', () => {
54 expect(
55 hasBeyondwordsData( { beyondwords_content_id: '12345' } )
56 ).toBe( false );
57 } );
58 } );
59
60 describe( 'getTextToCopy', () => {
61 it( 'labels each field with its meta key, in the supplied order', () => {
62 const text = getTextToCopy(
63 { beyondwords_content_id: '12345' },
64 CURRENT,
65 DEPRECATED
66 );
67 expect( text ).toContain( 'beyondwords_content_id\r\n12345' );
68 expect( text.indexOf( 'beyondwords_content_id' ) ).toBeGreaterThan(
69 text.indexOf( 'beyondwords_generate_audio' )
70 );
71 } );
72
73 it( 'groups the sections in order with separators', () => {
74 const text = getTextToCopy( {}, CURRENT, DEPRECATED );
75 const deprecated = text.indexOf( '=== Deprecated ===' );
76 const system = text.indexOf( '=== System ===' );
77 expect( deprecated ).toBeGreaterThan( -1 );
78 expect( system ).toBeGreaterThan( deprecated );
79 expect( text ).toContain( '=== Copied using the Block Editor ===' );
80 } );
81
82 it( 'always appends the system fields', () => {
83 const text = getTextToCopy(
84 { plugin_version: '5.0.0' },
85 CURRENT,
86 DEPRECATED
87 );
88 SYSTEM_META_KEYS.forEach( ( key ) => expect( text ).toContain( key ) );
89 expect( text ).toContain( 'plugin_version\r\n5.0.0' );
90 } );
91
92 it( 'reads the same meta hasBeyondwordsData checks', () => {
93 const meta = { beyondwords_content_id: '12345' };
94 expect( getTextToCopy( meta, CURRENT, DEPRECATED ) ).toContain(
95 '12345'
96 );
97 expect( hasBeyondwordsData( meta, DATA_KEYS ) ).toBe( true );
98 } );
99 } );
100