Skip to content

Commit

Permalink
Expect I
Browse files Browse the repository at this point in the history
  • Loading branch information
RickiJay-WMDE committed Feb 20, 2024
1 parent 248beb3 commit 73210a7
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 135 deletions.
3 changes: 1 addition & 2 deletions test/helpers/default-functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import axios, { AxiosResponse } from 'axios';
import lodash from 'lodash';
import { Context } from 'mocha';
Expand Down Expand Up @@ -176,7 +175,7 @@ export function defaultFunctions(): void {
const changes = result.data.query.recentchanges;
const foundResult = lodash.find( changes, expectedChange );

assert.strictEqual( result.status, 200 );
expect( result.status ).toBe( 200 );

if ( !foundResult ) {
testEnv.testLog.error( 'Could not find:' );
Expand Down
4 changes: 1 addition & 3 deletions test/specs/confirm_edit/confirm-edit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import assert from 'assert';

describe( 'ConfirmEdit', function () {
it( 'Should allow to edit with captcha', async () => {
const executionResult = await browser.editPage(
Expand All @@ -9,6 +7,6 @@ describe( 'ConfirmEdit', function () {
'paris'
);

assert.strictEqual( executionResult, 'something great' );
expect( executionResult ).toBe( 'something great' );
} );
} );
14 changes: 5 additions & 9 deletions test/specs/fedprops/prefetching.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import { getTestString } from 'wdio-mediawiki/Util.js';
import WikibaseApi from 'wdio-wikibase/wikibase.api.js';
import ItemPage from '../../helpers/pages/entity/item.page.js';
Expand Down Expand Up @@ -34,7 +33,7 @@ describe( 'Property Prefetching', function () {
};
} )
);
assert.strictEqual( claims.length, NUM_PROPERTIES );
expect( claims ).toHaveLength( NUM_PROPERTIES );

const data = { claims: claims };
itemId = await WikibaseApi.createItem( getTestString( itemLabel ), data );
Expand All @@ -51,11 +50,11 @@ describe( 'Property Prefetching', function () {
statements.map( async ( statement ) => statement.getAttribute( 'id' ) )
);

assert.strictEqual( propertyGuids.length, NUM_PROPERTIES );
expect( propertyGuids ).toHaveLength( NUM_PROPERTIES );

for ( const guid of propertyGuids ) {
const response = await browser.deleteClaim( guid );
assert.strictEqual( response.success, 1 );
expect( response.success ).toBe( 1 );
}

// Sleep for 2 seconds to ensure post edit things run
Expand All @@ -68,10 +67,7 @@ describe( 'Property Prefetching', function () {
await $( '#pagehistory' );

// +1 for the initial item creation
assert.strictEqual(
( await $$( '#pagehistory li' ) ).length,
NUM_PROPERTIES + 1
);
expect( await $$( '#pagehistory li' ) ).toHaveLength( NUM_PROPERTIES + 1 );
} );

it( 'Should render recent changes list within threshold', async () => {
Expand All @@ -83,6 +79,6 @@ describe( 'Property Prefetching', function () {
// +1 for the initial item creation
// +1 for the Main Page creation?
// +1 for ?
assert.strictEqual( ( await $$( 'ul.special li' ) ).length, NUM_PROPERTIES + 3 );
expect( await $$( 'ul.special li' ) ).toHaveLength( NUM_PROPERTIES + 3 );
} );
} );
10 changes: 4 additions & 6 deletions test/specs/pingback/pingback.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import assert from 'assert';

describe( 'Pingback', function () {
it( 'Should ping on first page request', async () => {
await browser.url( testEnv.vars.WIKIBASE_URL + '/wiki/Main_Page' );
Expand All @@ -10,16 +8,16 @@ describe( 'Pingback', function () {
const sqlResult = await browser.dbQuery(
'SELECT * from updatelog where ul_key LIKE "WikibasePingback%"'
);
assert.strictEqual( sqlResult.includes( 'WikibasePingback\t' ), true );
assert.strictEqual( sqlResult.includes( 'WikibasePingback-1.' ), true );
expect( sqlResult.includes( 'WikibasePingback\t' ) ).toBe( true );
expect( sqlResult.includes( 'WikibasePingback-1.' ) ).toBe( true );

const result = await browser.makeRequest( 'http://mediawiki.svc' );
assert.strictEqual( result.data.length, 2 );
expect( result.data ).toHaveLength( 2 );

const requestData = JSON.parse(
Object.keys( result.data[ 0 ] )[ 0 ].replace( ';', '' )
);

assert.strictEqual( requestData.schema, 'WikibasePingback' );
expect( requestData.schema ).toBe( 'WikibasePingback' );
} );
} );
5 changes: 2 additions & 3 deletions test/specs/repo/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import { getTestString } from 'wdio-mediawiki/Util.js';
import WikibaseApi from 'wdio-wikibase/wikibase.api.js';
import { wikibasePropertyString } from '../../helpers/wikibase-property-types.js';
Expand Down Expand Up @@ -33,8 +32,8 @@ describe( 'Wikibase API', function () {
data
);

assert.strictEqual( itemId.startsWith( 'Q' ), true );
assert.strictEqual( propertyId.startsWith( 'P' ), true );
expect( itemId.startsWith( 'Q' ) ).toBe( true );
expect( propertyId.startsWith( 'P' ) ).toBe( true );
} );
} );
} );
Expand Down
17 changes: 6 additions & 11 deletions test/specs/repo/extensions/babel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import LoginPage from 'wdio-mediawiki/LoginPage.js';

describe( 'Babel', function () {
Expand All @@ -18,17 +17,13 @@ describe( 'Babel', function () {
'{{#babel: sv | en }}'
);

assert.strictEqual(
executionContent.includes(
'Den här användaren har svenska som modersmål.'
),
true
);
assert.strictEqual(
expect(
executionContent.includes( 'Den här användaren har svenska som modersmål.' )
).toBe( true );
expect(
executionContent.includes(
'This user has a native understanding of English.'
),
true
);
)
).toBe( true );
} );
} );
5 changes: 2 additions & 3 deletions test/specs/repo/extensions/nuke.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import LoginPage from 'wdio-mediawiki/LoginPage.js';

describe( 'Nuke', function () {
Expand All @@ -20,7 +19,7 @@ describe( 'Nuke', function () {
{}
);

assert.strictEqual( pageExistsResult.status, 200 );
expect( pageExistsResult.status ).toBe( 200 );

await LoginPage.login(
testEnv.vars.MW_ADMIN_NAME,
Expand Down Expand Up @@ -48,6 +47,6 @@ describe( 'Nuke', function () {
{}
);

assert.strictEqual( pageIsGoneResult.status, 404 );
expect( pageIsGoneResult.status ).toBe( 404 );
} );
} );
7 changes: 3 additions & 4 deletions test/specs/repo/extensions/scribunto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import { readFile } from 'fs/promises';
import { utf8 } from '../../../helpers/readFileEncoding.js';

Expand Down Expand Up @@ -26,7 +25,7 @@ describe( 'Scribunto', function () {
);

// should come from executed lua script
assert( executionContent.includes( 'Hello, world!' ) );
expect( executionContent.includes( 'Hello, world!' ) ).toBe( true );
} );

it( 'Should be able to execute lua module within 0.05 seconds', async () => {
Expand All @@ -35,7 +34,7 @@ describe( 'Scribunto', function () {
'LuaTest'
);

assert( cpuTime.value < 0.05 );
assert.strictEqual( cpuTime.scale, 'seconds' );
expect( cpuTime.value ).toBeLessThan( 0.05 );
expect( cpuTime.scale ).toBe( 'seconds' );
} );
} );
6 changes: 1 addition & 5 deletions test/specs/repo/extensions/universal-language-selector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import assert from 'assert';

describe( 'UniversalLanguageSelector', function () {
beforeEach( async function () {
await browser.skipIfExtensionNotPresent( this, 'UniversalLanguageSelector' );
Expand All @@ -10,8 +8,6 @@ describe( 'UniversalLanguageSelector', function () {
await $( '#searchInput' ).click();
await $( '.imeselector' ).click();

const firstLang = await $( '.imeselector-menu h3' ).getText();

assert.strictEqual( firstLang, 'English' );
await expect( $( '.imeselector-menu h3' ) ).toHaveText( 'English' );
} );
} );
6 changes: 1 addition & 5 deletions test/specs/repo/extensions/visual-editor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import assert from 'assert';

describe( 'VisualEditor', function () {
beforeEach( async function () {
await browser.skipIfExtensionNotPresent( this, 'VisualEditor' );
Expand Down Expand Up @@ -33,8 +31,6 @@ describe( 'VisualEditor', function () {

await $( '.oo-ui-processDialog-actions-primary a' ).click();

const contentBody = await $( '.mw-parser-output' ).getText();

assert.strictEqual( contentBody, 'TEST' );
await expect( $( '.mw-parser-output' ) ).toHaveText( 'TEST' );
} );
} );
7 changes: 3 additions & 4 deletions test/specs/repo/extensions/wikibase-edtf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import WikibaseApi from 'wdio-wikibase/wikibase.api.js';
import Statement from '../../../helpers/pages/component/statement.js';
import ItemPage from '../../../helpers/pages/entity/item.page.js';
Expand All @@ -13,7 +12,7 @@ describe( 'WikibaseEdtf', function () {
it( 'Should allow to create and use the EDTF property', async () => {
// create the property
const propertyId = await WikibaseApi.createProperty( 'edtf' );
assert.strictEqual( propertyId.startsWith( 'P' ), true );
expect( propertyId.startsWith( 'P' ) ).toBe( true );

const rawValue = '1985-04-12T23:20:30';

Expand All @@ -38,8 +37,8 @@ describe( 'WikibaseEdtf', function () {
const responseSnak =
responseData.entities[ itemId ].claims[ propertyId ][ 0 ].mainsnak;

assert.strictEqual( responseSnak.datavalue.value, '1985-04-12T23:20:30' );
assert.strictEqual( responseSnak.datatype, 'edtf' );
expect( responseSnak.datavalue.value ).toBe( '1985-04-12T23:20:30' );
expect( responseSnak.datatype ).toBe( 'edtf' );

// for a pretty screenshot
await ItemPage.open( itemId );
Expand Down
10 changes: 4 additions & 6 deletions test/specs/repo/extensions/wikibase-local-media.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import LoginPage from 'wdio-mediawiki/LoginPage.js';
import WikibaseApi from 'wdio-wikibase/wikibase.api.js';
import Statement from '../../../helpers/pages/component/statement.js';
Expand Down Expand Up @@ -32,7 +31,7 @@ describe( 'WikibaseLocalMedia', function () {

it( 'Should allow to create a property with localMedia datatype', async () => {
propertyId = await WikibaseApi.createProperty( 'localMedia' );
assert.strictEqual( propertyId.startsWith( 'P' ), true );
expect( propertyId.startsWith( 'P' ) ).toBe( true );

await PropertyPage.open( propertyId );

Expand All @@ -58,11 +57,10 @@ describe( 'WikibaseLocalMedia', function () {
const itemId = await WikibaseApi.createItem( 'image-test', data );

await ItemPage.open( itemId );
const imageSource = await $( '.wikibase-snakview-value img' ).getAttribute(
'src'
await expect( $( '.wikibase-snakview-value img' ) ).toHaveAttributeContaining(
'src',
'Image.png'
);

assert.strictEqual( imageSource.includes( 'Image.png' ), true );
} );

it( 'Should allow to use uploaded image on statement in UI', async () => {
Expand Down
21 changes: 6 additions & 15 deletions test/specs/repo/extensions/wikibase-manifest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import assert from 'assert';

describe( 'WikibaseManifest', function () {
beforeEach( async function () {
await browser.skipIfExtensionNotPresent( this, 'WikibaseManifest' );
Expand All @@ -11,20 +9,13 @@ describe( 'WikibaseManifest', function () {
);
const data = result.data;

assert.strictEqual( 'wikibase-docker', data.name );
expect( 'wikibase-docker' ).toBe( data.name );

assert.strictEqual(
testEnv.vars.WIKIBASE_URL + '/w/api.php',
data.api.action
);
assert.strictEqual(
testEnv.vars.WIKIBASE_URL + '/w/rest.php',
data.api.rest
);
expect( testEnv.vars.WIKIBASE_URL + '/w/api.php' ).toBe( data.api.action );
expect( testEnv.vars.WIKIBASE_URL + '/w/rest.php' ).toBe( data.api.rest );

assert.strictEqual(
testEnv.vars.WIKIBASE_URL + '/wiki/Special:OAuthConsumerRegistration',
data.oauth.registration_page
);
expect(
testEnv.vars.WIKIBASE_URL + '/wiki/Special:OAuthConsumerRegistration'
).toBe( data.oauth.registration_page );
} );
} );
3 changes: 1 addition & 2 deletions test/specs/repo/search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import WikibaseApi from 'wdio-wikibase/wikibase.api.js';

describe( 'Search', function () {
Expand All @@ -15,6 +14,6 @@ describe( 'Search', function () {
`${testEnv.vars.WIKIBASE_URL}/w/api.php?action=wbsearchentities&search=${itemLabel}&format=json&errorformat=plaintext&language=en&uselang=en&type=item`
);

assert.strictEqual( result.data.search[ 0 ].label, itemLabel );
expect( result.data.search[ 0 ].label ).toBe( itemLabel );
} );
} );
35 changes: 15 additions & 20 deletions test/specs/repo/special-item.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import SpecialEntityPage from 'wdio-wikibase/pageobjects/item.page.js';
import SpecialNewItemPage from '../../helpers/pages/special/new-item.page.js';

Expand All @@ -18,24 +17,20 @@ describe( 'Special:NewItem', function () {

await SpecialEntityPage.addStatementLink;

const labelText = await $(
'.wikibase-entitytermsforlanguageview-label'
).getText();
assert.strictEqual( labelText, label );

const descriptionText = await $(
'.wikibase-entitytermsforlanguageview-description'
).getText();
assert.strictEqual( descriptionText, description );

const firstAliasText = await $(
'.wikibase-entitytermsforlanguageview-aliases li:nth-child(1)'
).getText();
assert.strictEqual( firstAliasText, firstAlias );

const secondAliasText = await $(
'.wikibase-entitytermsforlanguageview-aliases li:nth-child(2)'
).getText();
assert.strictEqual( secondAliasText, secondAlias );
await expect( $( '.wikibase-entitytermsforlanguageview-label' ) ).toHaveText(
label
);

await expect(
$( '.wikibase-entitytermsforlanguageview-description' )
).toHaveText( description );

await expect(
$( '.wikibase-entitytermsforlanguageview-aliases li:nth-child(1)' )
).toHaveText( firstAlias );

await expect(
$( '.wikibase-entitytermsforlanguageview-aliases li:nth-child(2)' )
).toHaveText( secondAlias );
} );
} );
10 changes: 3 additions & 7 deletions test/specs/repo/special-version.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import assert from 'assert';

describe( 'Special:Version', function () {
it( 'Should contain the correct MediaWiki version', async function () {
await browser.url( `${testEnv.vars.WIKIBASE_URL}/wiki/Special:Version` );
const text = await $( '#sv-software' ).getText();
assert.strictEqual(
text.includes( `MediaWiki ${testEnv.vars.MEDIAWIKI_VERSION}` ),
true
await expect( $( '#sv-software' ) ).toHaveTextContaining(
`MediaWiki ${testEnv.vars.MEDIAWIKI_VERSION}`
);
} );

Expand Down Expand Up @@ -50,7 +46,7 @@ describe( 'Special:Version', function () {
);
await elementSelector.scrollIntoView();

assert( elementSelector.getText() !== null );
await expect( elementSelector.getText() ).not.toBeNull();
} );
} );
} );
Expand Down
Loading

0 comments on commit 73210a7

Please sign in to comment.