Remove referencePreviews tests

These are causing trouble because of the forwards-compatibility
logic.  When Cite is present, we transparently switch to using that
code base for reference previews which means these tests are running
against the wrong code.  Dropping tests here in favor of the Cite
tests.

Bug: T355194
Change-Id: Ide1940ad1e915eee7127f36fb2a7c87b5fb6f88a
This commit is contained in:
Adam Wight 2024-03-18 13:48:23 +01:00
parent 2245ecee4e
commit cf2a10e42e
7 changed files with 0 additions and 629 deletions

View file

@ -1 +0,0 @@
Code in this folder and subfolders is maintained by WMDE.

View file

@ -1,171 +0,0 @@
import { createStubTitle } from '../stubs';
import createReferenceGateway from '../../../resources/ext.popups.referencePreviews/createReferenceGateway';
QUnit.module( 'ext.popups.referencePreviews/createReferenceGateway', {
beforeEach() {
global.CSS = {
escape: ( str ) => $.escapeSelector( str )
};
mw.msg = ( key ) => `<${ key }>`;
mw.message = ( key ) => {
return { exists: () => !key.endsWith( 'generic' ), text: () => `<${ key }>` };
};
this.$sourceElement = $( '<a>' ).appendTo(
$( '<sup>' ).attr( 'id', 'cite_ref-1' ).appendTo( document.body )
);
this.$references = $( '<ul>' ).append(
$( '<li>' ).attr( 'id', 'cite_note-1' ).append(
$( '<span>' ).addClass( 'mw-reference-text' ).text( 'Footnote 1' )
),
$( '<li>' ).attr( 'id', 'cite_note-2' ).append(
$( '<span>' ).addClass( 'reference-text' ).append(
$( '<cite>' ).addClass( 'journal web unknown' ).text( 'Footnote 2' )
)
),
$( '<li>' ).attr( 'id', 'cite_note-3' ).append(
$( '<span>' ).addClass( 'reference-text' ).append(
$( '<cite>' ).addClass( 'news' ).text( 'Footnote 3' ),
$( '<cite>' ).addClass( 'news citation' ),
$( '<cite>' ).addClass( 'citation' )
)
),
$( '<li>' ).attr( 'id', 'cite_note-4' ).append(
$( '<span>' ).addClass( 'reference-text' ).append(
$( '<cite>' ).addClass( 'news' ).text( 'Footnote 4' ),
$( '<cite>' ).addClass( 'web' )
)
),
$( '<li>' ).attr( 'id', 'cite_note-5' ).append(
$( '<span>' ).addClass( 'mw-reference-text' ).html( '&nbsp;' )
)
).appendTo( document.body );
},
afterEach() {
mw.msg = null;
mw.message = null;
this.$sourceElement.parent().remove();
this.$references.remove();
}
} );
QUnit.test( 'Reference preview gateway returns the correct data', function ( assert ) {
const gateway = createReferenceGateway(),
title = createStubTitle( 1, 'Foo', 'cite note-1' );
return gateway.fetchPreviewForTitle( title, this.$sourceElement[ 0 ] ).then( ( result ) => {
assert.propEqual(
result,
{
url: '#cite_note-1',
extract: 'Footnote 1',
type: 'reference',
referenceType: null,
sourceElementId: 'cite_ref-1'
}
);
} );
} );
QUnit.test( 'Reference preview gateway accepts alternative text node class name', function ( assert ) {
const gateway = createReferenceGateway(),
title = createStubTitle( 1, 'Foo', 'cite note-2' );
return gateway.fetchPreviewForTitle( title, this.$sourceElement[ 0 ] ).then( ( result ) => {
assert.propEqual(
result,
{
url: '#cite_note-2',
extract: '<cite class="journal web unknown">Footnote 2</cite>',
type: 'reference',
referenceType: 'web',
sourceElementId: 'cite_ref-1'
}
);
} );
} );
QUnit.test( 'Reference preview gateway accepts duplicated types', function ( assert ) {
const gateway = createReferenceGateway(),
title = createStubTitle( 1, 'Foo', 'cite note-3' );
return gateway.fetchPreviewForTitle( title, this.$sourceElement[ 0 ] ).then( ( result ) => {
assert.propEqual(
result,
{
url: '#cite_note-3',
extract: '<cite class="news">Footnote 3</cite><cite class="news citation"></cite><cite class="citation"></cite>',
type: 'reference',
referenceType: 'news',
sourceElementId: 'cite_ref-1'
}
);
} );
} );
QUnit.test( 'Reference preview gateway ignores conflicting types', function ( assert ) {
const gateway = createReferenceGateway(),
title = createStubTitle( 1, 'Foo', 'cite note-4' );
return gateway.fetchPreviewForTitle( title, this.$sourceElement[ 0 ] ).then( ( result ) => {
assert.propEqual(
result,
{
url: '#cite_note-4',
extract: '<cite class="news">Footnote 4</cite><cite class="web"></cite>',
type: 'reference',
referenceType: 'news',
sourceElementId: 'cite_ref-1'
}
);
} );
} );
QUnit.test( 'Reference preview gateway returns source element id', function ( assert ) {
const gateway = createReferenceGateway(),
title = createStubTitle( 1, 'Foo', 'cite note-1' );
return gateway.fetchPreviewForTitle( title, this.$sourceElement[ 0 ] ).then( ( result ) => {
assert.propEqual(
result,
{
url: '#cite_note-1',
extract: 'Footnote 1',
type: 'reference',
referenceType: null,
sourceElementId: 'cite_ref-1'
}
);
} );
} );
QUnit.test( 'Reference preview gateway rejects non-existing references', function ( assert ) {
const gateway = createReferenceGateway(),
title = createStubTitle( 1, 'Foo', 'undefined' );
return gateway.fetchPreviewForTitle( title, this.$sourceElement[ 0 ] ).then( () => {
assert.true( false, 'It should not resolve' );
} ).catch( ( result ) => {
assert.propEqual( result, { textStatus: 'abort', textContext: 'Footnote not found or empty', xhr: { readyState: 0 } } );
} );
} );
QUnit.test( 'Reference preview gateway rejects all-whitespace references', function ( assert ) {
const gateway = createReferenceGateway(),
title = createStubTitle( 1, 'Foo', 'cite note-5' );
return gateway.fetchPreviewForTitle( title, this.$sourceElement[ 0 ] ).then( () => {
assert.true( false, 'It should not resolve' );
} ).catch( ( result ) => {
assert.propEqual( result, { textStatus: 'abort', textContext: 'Footnote not found or empty', xhr: { readyState: 0 } } );
} );
} );
QUnit.test( 'Reference preview gateway is abortable', function ( assert ) {
const gateway = createReferenceGateway(),
title = createStubTitle( 1, 'Foo', 'cite note-1' ),
promise = gateway.fetchPreviewForTitle( title, this.$sourceElement[ 0 ] );
assert.strictEqual( typeof promise.abort, 'function' );
} );

View file

@ -1,210 +0,0 @@
import * as stubs from '../stubs';
import isReferencePreviewsEnabled from '../../../resources/ext.popups.referencePreviews/isReferencePreviewsEnabled';
function createStubUserSettings( expectEnabled ) {
return {
isPreviewTypeEnabled() {
return expectEnabled !== false;
}
};
}
const options = { get: () => '1' };
QUnit.module( 'ext.popups.referencePreviews#isReferencePreviewsEnabled' );
QUnit.test( 'all relevant combinations of flags', ( assert ) => {
[
{
testCase: 'enabled for an anonymous user',
wgPopupsReferencePreviews: true,
wgPopupsConflictsWithRefTooltipsGadget: false,
isMobile: false,
isAnon: true,
enabledByAnon: true,
enabledByRegistered: false,
expected: true
},
{
testCase: 'turned off via the feature flag (anonymous user)',
wgPopupsReferencePreviews: false,
wgPopupsConflictsWithRefTooltipsGadget: false,
isMobile: false,
isAnon: true,
enabledByAnon: true,
enabledByRegistered: true,
expected: null
},
{
testCase: 'not available because of a conflicting gadget (anonymous user)',
wgPopupsReferencePreviews: true,
wgPopupsConflictsWithRefTooltipsGadget: true,
isMobile: false,
isAnon: true,
enabledByAnon: true,
enabledByRegistered: true,
expected: null
},
{
testCase: 'not available in the mobile skin (anonymous user)',
wgPopupsReferencePreviews: true,
wgPopupsConflictsWithRefTooltipsGadget: false,
isMobile: true,
isAnon: true,
enabledByAnon: true,
enabledByRegistered: true,
expected: null
},
{
testCase: 'manually disabled by the anonymous user',
wgPopupsReferencePreviews: true,
wgPopupsConflictsWithRefTooltipsGadget: false,
isMobile: false,
isAnon: true,
enabledByAnon: false,
enabledByRegistered: true,
expected: false
},
{
testCase: 'enabled for a registered user',
wgPopupsReferencePreviews: true,
wgPopupsConflictsWithRefTooltipsGadget: false,
isMobile: false,
isAnon: false,
enabledByAnon: false,
enabledByRegistered: true,
expected: true
},
{
testCase: 'turned off via the feature flag (registered user)',
wgPopupsReferencePreviews: false,
wgPopupsConflictsWithRefTooltipsGadget: false,
isMobile: false,
isAnon: false,
enabledByAnon: true,
enabledByRegistered: true,
expected: null
},
{
testCase: 'not available because of a conflicting gadget (registered user)',
wgPopupsReferencePreviews: true,
wgPopupsConflictsWithRefTooltipsGadget: true,
isMobile: false,
isAnon: false,
enabledByAnon: true,
enabledByRegistered: true,
expected: null
},
{
testCase: 'not available in the mobile skin (registered user)',
wgPopupsReferencePreviews: true,
wgPopupsConflictsWithRefTooltipsGadget: false,
isMobile: true,
isAnon: false,
enabledByAnon: true,
enabledByRegistered: true,
expected: null
},
{
// TODO: This combination will make much more sense when the server-side
// wgPopupsReferencePreviews flag doesn't include the user's setting any more
testCase: 'manually disabled by the registered user',
wgPopupsReferencePreviews: true,
wgPopupsConflictsWithRefTooltipsGadget: false,
isMobile: false,
isAnon: false,
enabledByAnon: true,
enabledByRegistered: false,
expected: null
}
].forEach( ( data ) => {
const user = {
isNamed: () => !data.isAnon && !data.isIPMasked,
isAnon: () => data.isAnon,
options: {
get: () => {}
}
},
isPreviewTypeEnabled = () => {
if ( !data.isAnon ) {
assert.true( false, 'not expected to be called' );
}
return data.enabledByAnon;
},
config = {
get: ( key ) => key === 'skin' && data.isMobile ? 'minerva' : data[ key ]
};
if ( data.isAnon ) {
user.options.get = () => assert.true( false, 'not expected to be called 2' );
} else {
user.options.get = () => data.enabledByRegistered ? '1' : '0';
}
assert.strictEqual(
isReferencePreviewsEnabled( user, isPreviewTypeEnabled, config ),
data.expected,
data.testCase
);
} );
} );
QUnit.test( 'it should display reference previews when conditions are fulfilled', ( assert ) => {
const user = stubs.createStubUser( false, options ),
userSettings = createStubUserSettings( false ),
config = new Map();
config.set( 'wgPopupsReferencePreviews', true );
config.set( 'wgPopupsConflictsWithRefTooltipsGadget', false );
assert.true(
isReferencePreviewsEnabled( user, userSettings, config ),
'If the user is logged in and the user is in the on group, then it\'s enabled.'
);
} );
QUnit.test( 'it should handle the conflict with the Reference Tooltips Gadget', ( assert ) => {
const user = stubs.createStubUser( false ),
userSettings = createStubUserSettings( false ),
config = new Map();
config.set( 'wgPopupsReferencePreviews', true );
config.set( 'wgPopupsConflictsWithRefTooltipsGadget', true );
assert.strictEqual(
isReferencePreviewsEnabled( user, userSettings, config ),
null,
'Reference Previews is disabled.'
);
} );
QUnit.test( 'it should not be enabled when the global is disabling it', ( assert ) => {
const user = stubs.createStubUser( false ),
userSettings = createStubUserSettings( false ),
config = new Map();
config.set( 'wgPopupsReferencePreviews', false );
config.set( 'wgPopupsConflictsWithRefTooltipsGadget', false );
assert.strictEqual(
isReferencePreviewsEnabled( user, userSettings, config ),
null,
'Reference Previews is disabled.'
);
} );
QUnit.test( 'it should not be enabled when minerva skin used', ( assert ) => {
const user = stubs.createStubUser( false ),
userSettings = createStubUserSettings( false ),
config = new Map();
config.set( 'wgPopupsReferencePreviews', true );
config.set( 'wgPopupsConflictsWithRefTooltipsGadget', false );
config.set( 'skin', 'minerva' );
assert.strictEqual(
isReferencePreviewsEnabled( user, userSettings, config ),
null,
'Reference Previews is disabled.'
);
} );

View file

@ -1,107 +0,0 @@
import createReferencePreview from '../../../resources/ext.popups.referencePreviews/createReferencePreview';
import { TYPE_REFERENCE } from '../../../resources/ext.popups.referencePreviews/constants';
const previewTypes = { TYPE_REFERENCE };
QUnit.module( 'ext.popups.referencePreviews#renderer', {
beforeEach() {
mw.msg = ( key ) => `<${ key }>`;
mw.message = ( key ) => {
return { exists: () => !key.endsWith( 'generic' ), text: () => `<${ key }>` };
};
mw.html = {
escape: ( str ) => str && str.replace( /'/g, '&apos;' ).replace( /</g, '&lt;' )
};
mw.track = () => {};
global.navigator = {
sendBeacon() {}
};
// Some tests below stub this function. Keep a copy so it can be restored.
this.getElementById = document.getElementById;
},
afterEach() {
// Restore getElementsById to its original state.
document.getElementById = this.getElementById;
mw.msg = null;
mw.message = null;
mw.html = null;
}
} );
QUnit.test( 'createReferencePreview(model)', ( assert ) => {
const model = {
url: '#custom_id',
extract: 'Custom <i>extract</i> with an <a href="/wiki/Internal">internal</a> and an <a href="//wikipedia.de" class="external">external</a> link',
type: previewTypes.TYPE_REFERENCE,
referenceType: 'web'
},
preview = createReferencePreview( model );
assert.strictEqual( preview.hasThumbnail, false );
assert.strictEqual( preview.isTall, false );
assert.strictEqual(
$( preview.el ).find( '.mwe-popups-title' ).text().trim(),
'<popups-refpreview-web>'
);
assert.strictEqual(
$( preview.el ).find( '.mw-parser-output' ).text().trim(),
'Custom extract with an internal and an external link'
);
assert.strictEqual(
$( preview.el ).find( 'a[target="_blank"]' ).length,
1,
'only external links open in new tabs'
);
} );
QUnit.test( 'createReferencePreview default title', ( assert ) => {
const model = {
url: '',
extract: '',
type: previewTypes.TYPE_REFERENCE
},
preview = createReferencePreview( model );
assert.strictEqual(
$( preview.el ).find( '.mwe-popups-title' ).text().trim(),
'<popups-refpreview-reference>'
);
} );
QUnit.test( 'createReferencePreview updates fade-out effect on scroll', ( assert ) => {
const model = {
url: '',
extract: '',
type: previewTypes.TYPE_REFERENCE
},
preview = createReferencePreview( model ),
$extract = $( preview.el ).find( '.mwe-popups-extract' );
$extract.children()[ 0 ].dispatchEvent( new Event( 'scroll' ) );
assert.false( $extract.children()[ 0 ].isScrolling );
assert.false( $extract.hasClass( 'mwe-popups-fade-out' ) );
} );
QUnit.test( 'createReferencePreview collapsible/sortable handling', ( assert ) => {
const model = {
url: '',
extract: '<table class="mw-collapsible"></table>' +
'<table class="sortable"><th class="headerSort" tabindex="1" title="Click here"></th></table>',
type: previewTypes.TYPE_REFERENCE
},
preview = createReferencePreview( model );
assert.strictEqual( $( preview.el ).find( '.mw-collapsible, .sortable, .headerSort' ).length, 0 );
assert.strictEqual( $( preview.el ).find( 'th' ).attr( 'tabindex' ), undefined );
assert.strictEqual( $( preview.el ).find( 'th' ).attr( 'title' ), undefined );
assert.strictEqual(
$( preview.el ).find( '.mwe-collapsible-placeholder' ).text(),
'<popups-refpreview-collapsible-placeholder>'
);
} );

View file

@ -1,51 +0,0 @@
import setUserConfigFlags from '../../../resources/ext.popups.referencePreviews/setUserConfigFlags';
QUnit.module( 'ext.popups.referencePreviews#setUserConfigFlags' );
QUnit.test( 'reference preview config settings are successfully set from bitmask', ( assert ) => {
const config = new Map();
config.set( 'wgPopupsFlags', '7' );
setUserConfigFlags( config );
assert.deepEqual(
[
config.get( 'wgPopupsConflictsWithRefTooltipsGadget' ),
config.get( 'wgPopupsReferencePreviews' )
],
[ true, true ]
);
config.set( 'wgPopupsFlags', '2' );
setUserConfigFlags( config );
assert.deepEqual(
[
config.get( 'wgPopupsConflictsWithRefTooltipsGadget' ),
config.get( 'wgPopupsReferencePreviews' )
],
[ true, false ]
);
config.set( 'wgPopupsFlags', '5' );
setUserConfigFlags( config );
assert.deepEqual(
[
config.get( 'wgPopupsConflictsWithRefTooltipsGadget' ),
config.get( 'wgPopupsReferencePreviews' )
],
[ false, true ]
);
config.set( 'wgPopupsFlags', '0' );
setUserConfigFlags( config );
assert.deepEqual(
[
config.get( 'wgPopupsConflictsWithRefTooltipsGadget' ),
config.get( 'wgPopupsReferencePreviews' )
],
[ false, false ]
);
} );

View file

@ -1,19 +1,14 @@
'use strict';
/* global document */
const
fs = require( 'fs' ),
Api = require( 'wdio-mediawiki/Api' ),
Page = require( 'wdio-mediawiki/Page' ),
Util = require( 'wdio-mediawiki/Util' ),
TEST_PAGE_POPUPS_TITLE = 'Page popups test page',
TEST_REFERENCE_POPUPS_TITLE = 'Reference popups test page',
POPUPS_SELECTOR = '.mwe-popups',
PAGE_POPUPS_SELECTOR = '.mwe-popups-type-page',
PAGE_POPUPS_LINK_SELECTOR = '.mw-body-content ul a',
REFERENCE_POPUPS_SELECTOR = '.mwe-popups-type-reference',
REFERENCE_INCEPTION_LINK_SELECTOR = '.mwe-popups-type-reference .reference a',
POPUPS_MODULE_NAME = 'ext.popups.main';
async function makePage( title, path ) {
@ -31,13 +26,6 @@ class PopupsPage extends Page {
} );
}
async setupReferencePreviews() {
return browser.call( async () => {
const path = `${ __dirname }/../fixtures/`;
await makePage( TEST_REFERENCE_POPUPS_TITLE, `${ path }test_page.wikitext` );
} );
}
async ready() {
await Util.waitForModuleState( POPUPS_MODULE_NAME );
}
@ -67,15 +55,6 @@ class PopupsPage extends Page {
await $( PAGE_POPUPS_LINK_SELECTOR ).moveTo();
}
async dwellReferenceLink( id ) {
await this.dwellLink( `#${ id } a` );
}
async dwellReferenceInceptionLink() {
await $( REFERENCE_INCEPTION_LINK_SELECTOR ).moveTo();
await browser.pause( 1000 );
}
async doNotSeePreview( selector ) {
return browser.waitUntil( async () => !( await $( selector ).isDisplayed() ) );
}
@ -84,10 +63,6 @@ class PopupsPage extends Page {
return this.doNotSeePreview( PAGE_POPUPS_SELECTOR );
}
async doNotSeeReferencePreview() {
return this.doNotSeePreview( REFERENCE_POPUPS_SELECTOR );
}
async seePreview( selector ) {
return await $( selector ).isDisplayed();
}
@ -96,32 +71,9 @@ class PopupsPage extends Page {
return await this.seePreview( PAGE_POPUPS_SELECTOR );
}
async seeReferencePreview() {
return await this.seePreview( REFERENCE_POPUPS_SELECTOR );
}
async seeReferenceInceptionPreview() {
return await this.seePreview( REFERENCE_INCEPTION_LINK_SELECTOR );
}
async seeScrollableReferencePreview() {
return browser.execute( () => {
const el = document.querySelector( '.mwe-popups-extract .mwe-popups-scroll' );
return el.scrollHeight > el.offsetHeight;
} );
}
async seeFadeoutOnReferenceText() {
return $( '.mwe-popups-fade-out' ).isExisting();
}
async openPagePopupsTest() {
return super.openTitle( TEST_PAGE_POPUPS_TITLE );
}
async openReferencePopupsTest() {
return super.openTitle( TEST_REFERENCE_POPUPS_TITLE );
}
}
module.exports = new PopupsPage();

View file

@ -1,41 +0,0 @@
'use strict';
const assert = require( 'assert' ),
page = require( '../pageobjects/popups.page' );
describe( 'Dwelling on a valid reference link', function () {
before( async function () {
await page.setupReferencePreviews();
} );
beforeEach( async function () {
await page.openReferencePopupsTest();
await page.ready();
} );
it( 'I should see a reference preview', async function () {
await page.dwellReferenceLink( 'cite_ref-1' );
assert( await page.seeReferencePreview(), 'Reference preview is shown.' );
assert( !( await page.seeScrollableReferencePreview() ), 'Reference preview is not scrollable.' );
assert( !( await page.seeFadeoutOnReferenceText() ), 'Reference preview has no fading effect' );
} );
it( 'Abandoning link hides reference preview', async function () {
await page.dwellReferenceLink( 'cite_ref-1' );
await page.abandonLink();
assert( await page.doNotSeeReferencePreview(), 'Reference preview is kept hidden.' );
} );
// Skipped due to T341763
it.skip( 'References with lots of text are scrollable and fades', async function () {
await page.dwellReferenceLink( 'cite_ref-2' );
assert( await page.seeScrollableReferencePreview(), 'Reference preview is scrollable' );
assert( await page.seeFadeoutOnReferenceText(), 'Reference preview has a fading effect' );
} );
it.skip( 'Dwelling references links inside reference previews does not close the popup ', async function () {
await page.dwellReferenceLink( 'cite_ref-3' );
await page.dwellReferenceInceptionLink();
assert( await page.seeReferenceInceptionPreview(), 'The reference preview is still showing.' );
} );
} );