|
|
|
|
|
|
|
|
|
|
|
|
|
|
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: [ |
|
|
|
|
|
{ |
|
|
blockName: 'Image', |
|
|
blockEditorSelector: '[data-type="core/image"]', |
|
|
blockEditorContent: [ |
|
|
'.components-placeholder__label:has-text("Image")', |
|
|
'.jetpack-external-media-button-menu:has-text("Select Image")', |
|
|
], |
|
|
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', |
|
|
}, |
|
|
|
|
|
|
|
|
{ |
|
|
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', |
|
|
}, |
|
|
|
|
|
|
|
|
{ |
|
|
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: [ |
|
|
|
|
|
{ |
|
|
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")', |
|
|
], |
|
|
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', |
|
|
}, |
|
|
|
|
|
|
|
|
{ |
|
|
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', |
|
|
}, |
|
|
|
|
|
|
|
|
{ |
|
|
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: [ |
|
|
|
|
|
{ |
|
|
blockName: '转诪讜谞讛', |
|
|
blockEditorSelector: '[data-type="core/image"]', |
|
|
blockEditorContent: [ |
|
|
'.components-placeholder__label:has-text("转诪讜谞讛")', |
|
|
'.jetpack-external-media-button-menu:has-text("诇讘讞讜专 转诪讜谞讛")', |
|
|
], |
|
|
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: '讻讬住讜讬', |
|
|
}, |
|
|
|
|
|
|
|
|
{ |
|
|
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: '砖注讜转 驻注讬诇讜转', |
|
|
}, |
|
|
|
|
|
|
|
|
{ |
|
|
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 ); |
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
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 () { |
|
|
|
|
|
|
|
|
await page.route( '**/block-editor/nux*', ( route ) => { |
|
|
route.abort(); |
|
|
} ); |
|
|
|
|
|
|
|
|
const editor = new EditorComponent( page ); |
|
|
const editorWelcomeTourComponent = new EditorWelcomeTourComponent( page, editor ); |
|
|
|
|
|
|
|
|
|
|
|
const etkTranslations = translations[ locale ]!.etkPlugin!; |
|
|
|
|
|
|
|
|
await editorWelcomeTourComponent.forceShowWelcomeTour(); |
|
|
|
|
|
const editorParent = await editorPage.getEditorParent(); |
|
|
|
|
|
await editorParent.locator( etkTranslations.welcomeGuide.welcomeTitleSelector ).waitFor(); |
|
|
await editorParent.locator( etkTranslations.welcomeGuide.closeButtonSelector ).click(); |
|
|
} ); |
|
|
} ); |
|
|
|
|
|
|
|
|
|
|
|
describe.each( translations[ locale ]!.blocks! )( |
|
|
'Translations for block: $blockName', |
|
|
( ...args ) => { |
|
|
const block = args[ 0 ]; |
|
|
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(); |
|
|
|
|
|
|
|
|
|
|
|
await Promise.all( |
|
|
block.blockEditorContent.map( ( content ) => |
|
|
editorParent |
|
|
.locator( `${ block.blockEditorSelector } ${ content }` ) |
|
|
.first() |
|
|
.waitFor() |
|
|
) |
|
|
); |
|
|
} ); |
|
|
|
|
|
it( 'Render block title translations', async function () { |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
await editorParent |
|
|
.locator( '.block-editor-block-parent-selector__button:visible' ) |
|
|
.count() |
|
|
) { |
|
|
await editorParent.locator( '.block-editor-block-parent-selector__button' ).click(); |
|
|
} |
|
|
|
|
|
|
|
|
await editorParent |
|
|
.locator( `.block-editor-block-card__title:has-text("${ block.blockPanelTitle }")` ) |
|
|
.waitFor(); |
|
|
} ); |
|
|
} |
|
|
); |
|
|
} ); |
|
|
} ); |
|
|
|