Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expect #598

Merged
merged 27 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ you’ll want to consult the documentation of the following libraries we use:
(`browser`, `$`, `waitForVisible`, …)
* [Mocha](https://mochajs.org/) as the general testing framework
(`describe`, `it`, `before`, …)
* [`assert`](https://nodejs.org/api/assert.html) for simple assertions
(`ok`, `strictEqual`, …)
* [`expect`](https://webdriver.io/docs/api/expect-webdriverio/) for assertions
(`toBe`, `toEqual`, …)
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 function () {
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' );
} );
} );
81 changes: 43 additions & 38 deletions test/specs/fedprops/item.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from 'assert';
import { AxiosError } from 'axios';
import { getTestString } from 'wdio-mediawiki/Util.js';
import SpecialEntityPage from 'wdio-wikibase/pageobjects/item.page.js';
Expand All @@ -17,11 +16,9 @@ describe( 'Fed props Item', function () {
const result = await browser.makeRequest(
`${ testEnv.vars.WIKIBASE_URL }/w/api.php?action=wbsearchentities&search=ISNI&format=json&language=en&type=property`
);
const success = result.data.success;
const searchResults = result.data.search;

assert.strictEqual( success, 1 );
assert( searchResults.length > 0 );
expect( result.data.success ).toBe( 1 );
expect( result.data.search.length ).toBeGreaterThan( 0 );
} );

it( 'can add a federated property and it shows up in the ui', async function () {
Expand All @@ -42,10 +39,9 @@ describe( 'Fed props Item', function () {

await ItemPage.open( itemId );

const actualPropertyValue = await $(
'.wikibase-statementgroupview-property'
).getText();
assert( actualPropertyValue.includes( propertyValue ) ); // value is the label
await expect(
$( '.wikibase-statementgroupview-property' )
).toHaveTextContaining( propertyValue ); // value is the label

await SpecialEntityPage.addStatementLink;
} );
Expand All @@ -54,25 +50,24 @@ describe( 'Fed props Item', function () {
try {
await SpecialEntityDataPage.getData( 'Q1', 'ttl' );
} catch ( error ) {
assert( error instanceof AxiosError );
assert.equal( error.request.res.statusCode, 500 );
expect( error ).toBeInstanceOf( AxiosError );
expect( error.request.res.statusCode ).toBe( 500 );
}
} );

it( 'should show up in Special:EntityData with json', async function () {
const data = await SpecialEntityDataPage.getData( 'Q1' );
assert.notEqual(
data.entities.Q1.claims[ 'http://www.wikidata.org/entity/P213' ],
null
);
expect(
data.entities.Q1.claims[ 'http://www.wikidata.org/entity/P213' ]
).not.toBeNull();
} );

it( 'should NOT show up in Special:EntityData with rdf', async function () {
try {
await SpecialEntityDataPage.getData( 'Q1', 'rdf' );
} catch ( error ) {
assert( error instanceof AxiosError );
assert.equal( error.request.res.statusCode, 500 );
expect( error ).toBeInstanceOf( AxiosError );
expect( error.request.res.statusCode ).toBe( 500 );
}
} );

Expand All @@ -90,12 +85,12 @@ describe( 'Fed props Item', function () {
await QueryServiceUIPage.resultTable;

// Item should never have made its way into the query service, as TTL doesnt work
assert(
!( await QueryServiceUIPage.resultIncludes(
await expect(
QueryServiceUIPage.resultIncludes(
`<${ testEnv.vars.WIKIBASE_URL }/entity/${ itemId }>`,
propertyValue
) )
);
)
).resolves.toBe( false );
} );

it( 'should NOT show up in queryservice ui after creation', async function () {
Expand All @@ -106,23 +101,33 @@ describe( 'Fed props Item', function () {
await QueryServiceUIPage.resultTable;

// Item should never have made its way into the query service, as TTL doesnt work
assert( !( await QueryServiceUIPage.resultIncludes( 'schema:version' ) ) );
assert( !( await QueryServiceUIPage.resultIncludes( 'schema:dateModified' ) ) );
assert( !( await QueryServiceUIPage.resultIncludes( 'wikibase:timestamp' ) ) );

assert( !( await QueryServiceUIPage.resultIncludes( 'rdfs:label', itemLabel ) ) );

assert(
!( await QueryServiceUIPage.resultIncludes( 'wikibase:statements', '1' ) )
await expect(
QueryServiceUIPage.resultIncludes( 'schema:version' )
).resolves.toBe( false );
await expect(
QueryServiceUIPage.resultIncludes( 'schema:dateModified' )
).resolves.toBe( false );
await expect(
QueryServiceUIPage.resultIncludes( 'wikibase:timestamp' )
).resolves.toBe( false );

await expect(
QueryServiceUIPage.resultIncludes( 'rdfs:label', itemLabel )
).resolves.toBe( false );

await expect(
QueryServiceUIPage.resultIncludes( 'wikibase:statements', '1' )
).resolves.toBe( false );

await expect(
QueryServiceUIPage.resultIncludes( 'wikibase:sitelinks', '0' )
).resolves.toBe( false );
await expect(
QueryServiceUIPage.resultIncludes( 'wikibase:identifiers', '1' )
).resolves.toBe( false );

await expect( QueryServiceUIPage.resultIncludes( 'p:P213' ) ).resolves.toBe(
false
);

assert(
!( await QueryServiceUIPage.resultIncludes( 'wikibase:sitelinks', '0' ) )
);
assert(
!( await QueryServiceUIPage.resultIncludes( 'wikibase:identifiers', '1' ) )
);

assert( !( await QueryServiceUIPage.resultIncludes( 'p:P213' ) ) );
} );
} );
12 changes: 5 additions & 7 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,8 +67,7 @@ describe( 'Property Prefetching', function () {
await $( '#pagehistory' );

// +1 for the initial item creation
assert.strictEqual(
( await $$( '#pagehistory li' ) ).length,
await expect( $$( '#pagehistory li' ) ).resolves.toHaveLength(
NUM_PROPERTIES + 1
);
} );
Expand All @@ -83,6 +81,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 );
await expect( $$( 'ul.special li' ) ).resolves.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 function () {
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' );
} );
} );
Loading
Loading