PluginProbe
Extendify / 3.1.0
Extendify v3.1.0
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / tests / unit / QuickEdit / lib / translated.test.js

translated.test.js in Extendify 3.1.0, at tests/unit/QuickEdit/lib/translated.test.js

89 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // The translated-content guard's pure helpers: which block types carry
2 // editable text (and so are blocked on a non-default-language render), the
3 // user-facing notice copy, and reading the server-detected context off the
4 // inline-script global.
5
6 import {
7 getTranslatedContext,
8 isTextBearing,
9 isTranslatedRender,
10 translatedNoticeMessage,
11 } from '@quick-edit/lib/translated';
12
13 describe('isTextBearing', () => {
14 it('is true for the inline text blocks (the floating text toolbar)', () => {
15 for (const blockType of ['core/paragraph', 'core/heading', 'core/button']) {
16 expect(isTextBearing(blockType)).toBe(true);
17 }
18 });
19
20 it('is true for the text-bearing modal blocks', () => {
21 for (const blockType of [
22 'core/site-title',
23 'core/site-tagline',
24 'core/navigation-link',
25 'core/navigation-submenu',
26 'product:name',
27 'product:short_description',
28 'product:description',
29 ]) {
30 expect(isTextBearing(blockType)).toBe(true);
31 }
32 });
33
34 it('is false for image / link / numeric edits that stay available', () => {
35 for (const blockType of [
36 'core/image',
37 'core/cover',
38 'core/media-text:image',
39 'product:image',
40 'core/site-logo',
41 'core/social-link',
42 'product:price',
43 'wpforms:field',
44 ]) {
45 expect(isTextBearing(blockType)).toBe(false);
46 }
47 });
48 });
49
50 describe('translatedNoticeMessage', () => {
51 it('names the multilingual plugin when known', () => {
52 expect(translatedNoticeMessage('translatepress')).toContain(
53 'TranslatePress',
54 );
55 expect(translatedNoticeMessage('wpml')).toContain('WPML');
56 expect(translatedNoticeMessage('polylang')).toContain('Polylang');
57 expect(translatedNoticeMessage('translatepress')).toMatch(
58 /can.t edit translated content/i,
59 );
60 });
61
62 it('falls back to a generic message without a plugin name', () => {
63 expect(translatedNoticeMessage(null)).toMatch(/translated content/i);
64 expect(translatedNoticeMessage(undefined)).toMatch(/translated content/i);
65 });
66 });
67
68 describe('translated context readers', () => {
69 afterEach(() => {
70 delete window.extQuickEditData;
71 });
72
73 it('reads translatedContext off the inline-script global', () => {
74 window.extQuickEditData = {
75 translatedContext: { isTranslated: true, plugin: 'wpml' },
76 };
77 expect(getTranslatedContext()).toEqual({
78 isTranslated: true,
79 plugin: 'wpml',
80 });
81 expect(isTranslatedRender()).toBe(true);
82 });
83
84 it('defaults to not-translated when the global is absent', () => {
85 expect(getTranslatedContext()).toBeNull();
86 expect(isTranslatedRender()).toBe(false);
87 });
88 });
89