Cypress: Add test for WT2017 integration

Add e2e test to verify adding a basic ref and a VE-Cite tool template works with the WT2017 editor

TODO: In follow-up work, streamline Cite and Citoid initialization so
that we don't have to `wait` for partially-wired elements to get
their full behavior.

Bug: T373787
Change-Id: Iea41ce8b71e61d2c9868e50ba680d9c9245bb906
This commit is contained in:
mareikeheuer 2024-09-17 13:26:16 +02:00
parent 25b71720a4
commit 326abf110d
2 changed files with 119 additions and 1 deletions

View file

@ -0,0 +1,110 @@
/* eslint-disable cypress/no-unnecessary-waiting */
import * as helper from './../../utils/functions.helper.js';
import * as veHelper from './../../utils/ve.helper.js';
const title = helper.getTestString( 'CiteTest-title' );
const wikiText = '';
let usesCitoid;
describe( 'Visual Editor Wt 2017 Cite Integration', () => {
before( () => {
helper.loginAsAdmin();
helper.editPage( 'MediaWiki:Cite-tool-definition.json', JSON.stringify( [
{
name: 'Webseite',
icon: 'ref-cite-web',
template: 'Internetquelle'
}
] ) );
} );
beforeEach( () => {
cy.clearCookies();
helper.editPage( title, wikiText );
cy.window().then( async ( win ) => {
usesCitoid = win.mw.loader.getModuleNames().includes( 'ext.citoid.visualEditor' );
} );
veHelper.setVECookiesToDisableDialogs();
veHelper.openVEForSourceEditingReferences( title, usesCitoid );
} );
it( 'should be able to create a basic reference', () => {
// FIXME: Fix application logic to only render once fully initialized.
cy.wait( 1000 );
if ( usesCitoid ) {
cy.get( '.ve-ui-toolbar-group-citoid' ).click();
cy.wait( 500 );
cy.get( '.oo-ui-tabSelectWidget .oo-ui-labelElement-label', { timeout: 5000 } ).should( 'be.visible' ).contains( 'Manual' ).click();
cy.wait( 500 );
cy.get( '.ve-ui-citeSourceSelectWidget-basic' ).click();
} else {
cy.get( '.ve-ui-toolbar-group-cite' ).click();
cy.get( '.oo-ui-popupToolGroup-active-tools .oo-ui-tool-title', { timeout: 5000 } ).should( 'be.visible' ).contains( 'Basic' ).click();
}
cy.get( '.ve-ui-mwReferenceDialog .mw-content-ltr' ).type( 'Basic ref' );
// Save changes
cy.get( '.ve-ui-mwReferenceDialog .oo-ui-flaggedElement-primary' ).click();
// Ref tag appears with correct content in edit source mode
cy.get( '.ve-ui-mwWikitextSurface' ).should( 'contain.text', '<ref>Basic ref</ref>' );
// Save changes
cy.get( '.ve-ui-toolbar-saveButton' ).click();
cy.wait( 500 );
cy.get( '.oo-ui-labelElement-label' ).contains( 'Save changes' ).click( { force: true } );
// Success notification should be visible
cy.get( '.mw-notification-visible .oo-ui-icon-success' ).should( 'be.visible' );
// Ref has been added to references section and has correct content
helper.getRefFromReferencesSection( 1 ).find( '.reference-text' ).should( 'have.text', 'Basic ref' );
} );
it( 'should be able to create a VE-Cite tool template', () => {
// FIXME: Replace this wait with a trigger when VE is fully initialized.
cy.wait( 1000 );
if ( usesCitoid ) {
cy.get( '.ve-ui-toolbar-group-citoid' ).click();
cy.wait( 500 );
cy.get( '.oo-ui-tabSelectWidget .oo-ui-labelElement-label', { timeout: 5000 } ).should( 'be.visible' ).contains( 'Manual' ).click();
cy.wait( 500 );
cy.get( '.oo-ui-labelElement-label' ).contains( 'Webseite' ).click();
} else {
cy.get( '.ve-ui-toolbar-group-cite' ).click();
cy.get( '.oo-ui-popupToolGroup-active-tools .oo-ui-tool-title', { timeout: 5000 } ).should( 'be.visible' ).contains( 'Webseite' ).click();
}
// Add undocumented parameter
cy.get( '.ve-ui-mwTransclusionDialog-addParameterFieldset-header' ).click();
cy.get( '.ve-ui-mwTransclusionDialog-addParameterFieldset-input' ).type( 't' );
cy.get( '.ve-ui-mwTransclusionDialog-addParameterFieldset-input .oo-ui-actionFieldLayout-button .oo-ui-buttonElement-button' ).click();
cy.get( '.ve-ui-mwParameterPage-field' ).type( 't' );
// Click on insert button
cy.get( '.ve-ui-mwTemplateDialog .oo-ui-processDialog-actions-primary .oo-ui-buttonElement-button' ).click();
cy.get( '.ve-ui-toolbar-saveButton' ).click();
// Ref tag with template and added parameter has been created
cy.get( '.ve-ui-mwWikitextSurface' ).should( 'contain.text', '<ref>{{Internetquelle|t=t}}</ref>' );
// Save changes
cy.get( '.ve-ui-toolbar-saveButton' ).click();
cy.wait( 500 );
cy.get( '.oo-ui-labelElement-label' ).contains( 'Save changes' ).click( { force: true } );
// Success notification should be visible
cy.get( '.mw-notification-visible .oo-ui-icon-success' ).should( 'be.visible' );
// Ref has been added to references section and has correct content
helper.getRefFromReferencesSection( 1 ).find( '.reference-text' ).should( 'have.text', 'Template:Internetquelle' );
} );
} );

View file

@ -17,8 +17,16 @@ export function openVEForEditingReferences( title, usesCitoid ) {
}
}
export function openVEForSourceEditingReferences( title, usesCitoid ) {
helpers.visitTitle( title, { veaction: 'editsource' } );
waitForVECiteToLoad();
if ( usesCitoid ) {
waitForVECitoidToLoad();
}
}
export function waitForVECiteToLoad() {
cy.get( '.ve-init-mw-desktopArticleTarget-toolbar-open', { timeout: 7000 } )
cy.get( '.ve-init-mw-desktopArticleTarget-toolbar-open', { timeout: 20000 } )
.should( 'be.visible' );
helpers.waitForModuleReady( 'ext.cite.visualEditor' );
}