mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-24 04:22:51 +00:00
dcb513eb0e
The ext.cite.referencePreviews module will transparently replace the ext.popups.referencePreviews module after this patch. Configuration stays in Popups for now, we can migrate it in later work. CSS classes may be renamed in the future but this will be handled separately since it could be a breaking change for on-wiki customizations. A lot of fancy footwork happens in this patch to emulate a soft dependency on Popups. This mechanism doesn't exist explicitly in either ResourceLoader or QUnit, so lots of workarounds are used, to conditionally load the module and to dynamically skip dependent tests. renderer.test.js is fully skipped for now, but can be wired up in later work. Bug: T355194 Change-Id: I0dc47abb59a40d4e41e7dda0eb7b415a2e1ae508
81 lines
3.7 KiB
JavaScript
81 lines
3.7 KiB
JavaScript
import * as helpers from '../../utils/functions.helper.js';
|
|
|
|
const title = getTestString( 'CiteTest-title' );
|
|
const encodedTitle = encodeURIComponent( title );
|
|
|
|
function getTestString( prefix = '' ) {
|
|
return prefix + Math.random().toString();
|
|
}
|
|
|
|
function skipTest( message ) {
|
|
cy.log( message );
|
|
// Dips into secret internals—stealing code from the skip plugin.
|
|
const mochaContext = cy.state( 'runnable' ).ctx;
|
|
return mochaContext.skip();
|
|
}
|
|
|
|
describe( 'Cite popups integration', () => {
|
|
before( () => {
|
|
cy.visit( '/index.php' );
|
|
|
|
const wikiText = 'Lorem ipsum dolor.<ref>small reference</ref>' +
|
|
'Reference with lots of text.<ref>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</ref>' +
|
|
'Lorem ipsum dolor.<ref>reference inception{{#tag:ref|body}}</ref>';
|
|
|
|
// Rely on the retry behavior of Cypress assertions to use this as a "wait"
|
|
// until the specified conditions are met.
|
|
cy.window().should( 'have.property', 'mw' ).and( 'have.property', 'loader' ).and( 'have.property', 'using' );
|
|
// Create a new page containing a reference
|
|
cy.window().then( async ( win ) => {
|
|
await win.mw.loader.using( 'mediawiki.api' );
|
|
const response = await new win.mw.Api().create( title, {}, wikiText );
|
|
expect( response.result ).to.equal( 'Success' );
|
|
|
|
await win.mw.loader.using( 'ext.popups.main', () => {}, () => skipTest( 'Popups not available' ) );
|
|
} );
|
|
|
|
} );
|
|
|
|
beforeEach( () => {
|
|
cy.visit( `/index.php?title=${ encodedTitle }` );
|
|
cy.window()
|
|
.should( 'have.property', 'mw' ).and( 'have.property', 'loader' ).and( 'have.property', 'getState' );
|
|
cy.window().should( ( win ) => win.mw.loader.getState( 'ext.cite.referencePreviews' ) === 'ready' );
|
|
} );
|
|
|
|
it( 'simple popup on hover and hide on leave', () => {
|
|
helpers.abandonReference( 'cite_ref-1' );
|
|
helpers.dwellReference( 'cite_ref-1' );
|
|
cy.get( '.mwe-popups-type-reference', { timeout: 1000 } )
|
|
.should( 'be.visible' );
|
|
helpers.assertPreviewIsScrollable( false );
|
|
cy.get( '.mwe-popups-fade-out' ).should( 'not.exist' );
|
|
|
|
helpers.abandonReference( 'cite_ref-1' );
|
|
cy.get( '.mwe-popups-type-reference' )
|
|
.should( 'not.exist' );
|
|
} );
|
|
|
|
it( 'includes scrollbar and fadeout on long previews', () => {
|
|
helpers.abandonReference( 'cite_ref-2' );
|
|
helpers.dwellReference( 'cite_ref-2' );
|
|
cy.get( '.mwe-popups-type-reference', { timeout: 1000 } )
|
|
.should( 'be.visible' );
|
|
helpers.assertPreviewIsScrollable( true );
|
|
cy.get( '.mwe-popups-fade-out' ).should( 'be.visible' );
|
|
} );
|
|
|
|
it( 'hovering nested reference', () => {
|
|
helpers.abandonReference( 'cite_ref-3' );
|
|
helpers.dwellReference( 'cite_ref-3' );
|
|
cy.get( '.mwe-popups-type-reference', { timeout: 1000 } )
|
|
.should( 'be.visible' );
|
|
helpers.dwellReference( 'cite_ref-4' );
|
|
// eslint-disable-next-line cypress/no-unnecessary-waiting
|
|
cy.wait( 1000 );
|
|
cy.get( '.mwe-popups-type-reference' )
|
|
.should( 'include.text', 'reference inception' );
|
|
} );
|
|
|
|
} );
|