File size: 11,377 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
/**
* @group i18n
*/
import {
EditorPage,
TestAccount,
envVariables,
getTestAccountByFeature,
envToFeatureKey,
RestAPIClient,
EditorWelcomeTourComponent,
EditorComponent,
} from '@automattic/calypso-e2e';
import { Page, Browser, Locator } from 'playwright';
import type { LanguageSlug } from '@automattic/languages';
type Translations = {
[ language in LanguageSlug ]?: Partial< {
etkPlugin: {
welcomeGuide: {
openGuideSelector: string;
welcomeTitleSelector: string;
closeButtonSelector: string;
};
};
blocks: {
blockName: string;
blockEditorSelector: string;
blockEditorContent: string[];
blockPanelTitle: string;
}[];
} >;
};
const translations: Translations = {
en: {
etkPlugin: {
welcomeGuide: {
openGuideSelector:
'.interface-more-menu-dropdown__content button:has-text("Welcome Guide")',
welcomeTitleSelector:
'.wpcom-tour-kit-step-card__heading:has-text("Welcome to WordPress!")',
closeButtonSelector: '.wpcom-tour-kit button[aria-label="Close Tour"]',
},
},
blocks: [
// Core
{
blockName: 'Image',
blockEditorSelector: '[data-type="core/image"]',
blockEditorContent: [
'.components-placeholder__label:has-text("Image")',
'.jetpack-external-media-button-menu:has-text("Select Image")', // Jetpack extension
],
blockPanelTitle: 'Image',
},
{
blockName: 'Spacer',
blockEditorSelector: '[data-type="core/spacer"]',
blockEditorContent: [],
blockPanelTitle: 'Spacer',
},
{
blockName: 'Cover',
blockEditorSelector: '[data-type="core/cover"]',
blockEditorContent: [ '.block-editor-media-placeholder__upload-button:has-text("Upload")' ],
blockPanelTitle: 'Cover',
},
// Jetpack
{
blockName: 'Contact Form',
blockEditorSelector: '[data-type="jetpack/contact-form"]',
blockEditorContent: [ ':text("Name")', ':text("Email")', ':text("Message")' ],
blockPanelTitle: 'Form',
},
{
blockName: 'Business Hours',
blockEditorSelector: '[data-type="jetpack/business-hours"]',
blockEditorContent: [
'.business-hours__day-name:text("Monday")',
'.business-hours__hours:has-text("Add Hours")',
],
blockPanelTitle: 'Business Hours',
},
// Crowdsignal Forms
{
blockName: 'Applause',
blockEditorSelector: '[data-type="crowdsignal-forms/applause"]',
blockEditorContent: [ ':text("Claps")' ],
blockPanelTitle: 'Applause',
},
{
blockName: 'Poll',
blockEditorSelector: '[data-type="crowdsignal-forms/poll"]',
blockEditorContent: [
'[aria-label="Enter your question"]',
'[aria-label="Add a note (optional)"]',
],
blockPanelTitle: 'Poll',
},
],
},
fr: {
etkPlugin: {
welcomeGuide: {
openGuideSelector:
'.interface-more-menu-dropdown__content button:has-text("Guide de bienvenue")',
welcomeTitleSelector:
'.wpcom-tour-kit-step-card__heading:has-text("Bienvenue dans WordPress !")',
closeButtonSelector: '.wpcom-tour-kit button[aria-label="Fermer la visite"]',
},
},
blocks: [
// Core
{
blockName: 'Image',
blockEditorSelector: '[data-type="core/image"]',
blockEditorContent: [
'.components-placeholder__label:has-text("Image")',
'.jetpack-external-media-button-menu:has-text("S茅lectionner une image")', // Jetpack extension
],
blockPanelTitle: 'Image',
},
{
blockName: 'Espacement',
blockEditorSelector: '[data-type="core/spacer"]',
blockEditorContent: [],
blockPanelTitle: 'Espacement',
},
{
blockName: 'Banni猫re',
blockEditorSelector: '[data-type="core/cover"]',
blockEditorContent: [
'.block-editor-media-placeholder__upload-button:has-text("T茅l茅verser")',
],
blockPanelTitle: 'Banni猫re',
},
// Jetpack
{
blockName: 'Formulaire de contact',
blockEditorSelector: '[data-type="jetpack/contact-form"]',
blockEditorContent: [ ':text("Nom")', ':text("E-mail")', ':text("Message")' ],
blockPanelTitle: 'Formulaire',
},
{
blockName: 'Heures d鈥檕uverture',
blockEditorSelector: '[data-type="jetpack/business-hours"]',
blockEditorContent: [
'.business-hours__day-name:text("lundi")',
'.business-hours__hours:has-text("Ajouter les heures")',
],
blockPanelTitle: 'Heures d鈥檕uverture',
},
// Crowdsignal Forms
{
blockName: 'Applaudissement',
blockEditorSelector: '[data-type="crowdsignal-forms/applause"]',
blockEditorContent: [ ':text("Claps")' ],
blockPanelTitle: 'Applaudissement',
},
{
blockName: 'Sondage',
blockEditorSelector: '[data-type="crowdsignal-forms/poll"]',
blockEditorContent: [
'[aria-label="Entrez votre question"]',
'[aria-label="Ajouter une note (facultatif)"]',
],
blockPanelTitle: 'Sondage',
},
],
},
he: {
etkPlugin: {
welcomeGuide: {
openGuideSelector:
'.interface-more-menu-dropdown__content button:has-text("诪讚专讬讱 讘专讜讻讬诐 讛讘讗讬诐")',
welcomeTitleSelector:
'.wpcom-tour-kit-step-card__heading:has-text("讘专讜讱 讘讜讗讱 诇-WordPress!")',
closeButtonSelector: '.wpcom-tour-kit button[aria-label="诇住讙讜专 讗转 讛住讬讜专"]',
},
},
blocks: [
// Core
{
blockName: '转诪讜谞讛',
blockEditorSelector: '[data-type="core/image"]',
blockEditorContent: [
'.components-placeholder__label:has-text("转诪讜谞讛")',
'.jetpack-external-media-button-menu:has-text("诇讘讞讜专 转诪讜谞讛")', // Jetpack extension
],
blockPanelTitle: '转诪讜谞讛',
},
{
blockName: '诪专讜讜讞',
blockEditorSelector: '[data-type="core/spacer"]',
blockEditorContent: [],
blockPanelTitle: '诪专讜讜讞',
},
{
blockName: '讻讬住讜讬',
blockEditorSelector: '[data-type="core/cover"]',
blockEditorContent: [ '.block-editor-media-placeholder__upload-button:has-text("讛注诇讗讛")' ],
blockPanelTitle: '讻讬住讜讬',
},
// Jetpack
{
blockName: '讟讜驻住 讬爪讬专转 拽砖专',
blockEditorSelector: '[data-type="jetpack/contact-form"]',
blockEditorContent: [ ':text("砖诐")', ':text("讗讬诪讬讬诇")', ':text("讛讜讚注讛")' ],
blockPanelTitle: '讟讜驻住',
},
{
blockName: '砖注讜转 驻注讬诇讜转',
blockEditorSelector: '[data-type="jetpack/business-hours"]',
blockEditorContent: [
'.business-hours__day-name:text("讬讜诐 砖谞讬")',
'.business-hours__hours:has-text("讛讜住驻转 砖注讜转")',
],
blockPanelTitle: '砖注讜转 驻注讬诇讜转',
},
// Crowdsignal Forms
{
blockName: '诪讞讬讗讜转 讻驻讬讬诐',
blockEditorSelector: '[data-type="crowdsignal-forms/applause"]',
blockEditorContent: [ ':text("Claps")' ],
blockPanelTitle: '诪讞讬讗讜转 讻驻讬讬诐',
},
{
blockName: '住拽专',
blockEditorSelector: '[data-type="crowdsignal-forms/poll"]',
blockEditorContent: [
'[aria-label="讬砖 诇讛讝讬谉 讗转 讛砖讗诇讛 砖诇讱"]',
'[aria-label="诇讛讜住讬祝 驻转拽 (讗讜驻爪讬讜谞诇讬)"]',
],
blockPanelTitle: '住拽专',
},
],
},
};
declare const browser: Browser;
describe( 'I18N: Editor', function () {
const features = envToFeatureKey( envVariables );
const accountName = getTestAccountByFeature( { ...features, variant: 'i18n' } );
const testAccount = new TestAccount( accountName );
// Filter out the locales that do not have valid translation content defined above.
const locales: LanguageSlug[] = Object.keys( translations ).filter( ( locale ) =>
( envVariables.TEST_LOCALES as ReadonlyArray< string > ).includes( locale )
) as LanguageSlug[];
let page: Page;
let editorPage: EditorPage;
let restAPIClient: RestAPIClient;
beforeAll( async () => {
page = await browser.newPage();
// Confirm page leave with unsaved changes prompt.
page.on( 'dialog', async ( dialog ) => {
if ( dialog.type() === 'beforeunload' ) {
await dialog.accept();
}
} );
await testAccount.authenticate( page );
restAPIClient = new RestAPIClient( testAccount.credentials );
editorPage = new EditorPage( page );
} );
describe.each( locales )( 'Locale: %s', function ( locale ) {
beforeAll( async function () {
await restAPIClient.setMySettings( { language: locale } );
await page.reload();
} );
describe( 'Editing Toolkit Plugin', function () {
it( 'Go to the new post page', async function () {
await editorPage.visit( 'post' );
} );
it( 'Translations for Welcome Guide', async function () {
// Abort API request to fetch the Welcome Tour status in order to avoid
// overwriting the current state when the request finishes.
await page.route( '**/block-editor/nux*', ( route ) => {
route.abort();
} );
// @TODO Consider moving this to EditorPage.
const editor = new EditorComponent( page );
const editorWelcomeTourComponent = new EditorWelcomeTourComponent( page, editor );
// We know these are all defined because of the filtering above. Non-null asserting is safe here.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const etkTranslations = translations[ locale ]!.etkPlugin!;
// Ensure the Welcome Guide component is shown.
await editorWelcomeTourComponent.forceShowWelcomeTour();
const editorParent = await editorPage.getEditorParent();
await editorParent.locator( etkTranslations.welcomeGuide.welcomeTitleSelector ).waitFor();
await editorParent.locator( etkTranslations.welcomeGuide.closeButtonSelector ).click();
} );
} );
// We know these are all defined because of the filtering above. Non-null asserting is safe here.
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
describe.each( translations[ locale ]!.blocks! )(
'Translations for block: $blockName',
( ...args ) => {
const block = args[ 0 ]; // Makes TS stop complaining about incompatible args type
let editorPage: EditorPage;
let editorParent: Locator;
it( 'Insert test block', async function () {
editorPage = new EditorPage( page );
await editorPage.addBlockFromSidebar( block.blockName, block.blockEditorSelector );
} );
it( 'Render block content translations', async function () {
editorParent = await editorPage.getEditorParent();
// Ensure block contents are translated as expected.
// To deal with multiple potential matches (eg. Jetpack/Business Hours > Add Hours)
// the first locator is matched.
await Promise.all(
block.blockEditorContent.map( ( content ) =>
editorParent
.locator( `${ block.blockEditorSelector } ${ content }` )
.first()
.waitFor()
)
);
} );
it( 'Render block title translations', async function () {
// If on block insertion, one of the sub-blocks are selected, click on
// the first button in the floating toolbar which selects the overall
// block.
if (
await editorParent
.locator( '.block-editor-block-parent-selector__button:visible' )
.count()
) {
await editorParent.locator( '.block-editor-block-parent-selector__button' ).click();
}
// Ensure the Settings with the block selected shows the expected title.
await editorParent
.locator( `.block-editor-block-card__title:has-text("${ block.blockPanelTitle }")` )
.waitFor();
} );
}
);
} );
} );
|