Debian Codegraph @

tests/qunit/resources/mediawiki.api/mediawiki.api.category.test.js

raw symbols SCIP
1 QUnit.module( 'mediawiki.api.category', ( hooks ) => {
2 let server;
3 hooks.beforeEach( function () {
4 server = this.sandbox.useFakeServer();
5 server.respondImmediately = true;
6 } );
7
8 QUnit.test( '.getCategoriesByPrefix()', async ( assert ) => {
9 server.respondWith( [ 200, { 'Content-Type': 'application/json' },
10 '{ "query": { "allpages": [ ' +
11 '{ "title": "Category:Food" },' +
12 '{ "title": "Category:Fool Supermarine S.6" },' +
13 '{ "title": "Category:Fools" }' +
14 '] } }'
15 ] );
16 const matches = await new mw.Api().getCategoriesByPrefix( 'Foo' );
17 assert.deepEqual(
18 matches,
19 [ 'Food', 'Fool Supermarine S.6', 'Fools' ]
20 );
21 } );
22
23 QUnit.test( '.isCategory("")', async ( assert ) => {
24 server.respondWith( /titles=$/, [
25 200,
26 { 'Content-Type': 'application/json' },
27 '{"batchcomplete":true}'
28 ] );
29 const response = await new mw.Api().isCategory( '' );
30 assert.strictEqual( response, false );
31 } );
32
33 QUnit.test( '.isCategory("#")', async ( assert ) => {
34 server.respondWith( /titles=%23$/, [
35 200,
36 { 'Content-Type': 'application/json' },
37 '{"batchcomplete":true,"query":{"normalized":[{"fromencoded":false,"from":"#","to":""}]}}'
38 ] );
39 const response = await new mw.Api().isCategory( '#' );
40 assert.strictEqual( response, false );
41 } );
42
43 QUnit.test( '.isCategory("mw:")', async ( assert ) => {
44 server.respondWith( /titles=mw%3A$/, [
45 200,
46 { 'Content-Type': 'application/json' },
47 '{"batchcomplete":true,"query":{"interwiki":[{"title":"mw:","iw":"mw"}]}}'
48 ] );
49 const response = await new mw.Api().isCategory( 'mw:' );
50 assert.strictEqual( response, false );
51 } );
52
53 QUnit.test( '.isCategory("|")', async ( assert ) => {
54 server.respondWith( /titles=%1F%7C$/, [
55 200,
56 { 'Content-Type': 'application/json' },
57 '{"batchcomplete":true,"query":{"pages":[{"title":"|","invalidreason":"The requested page title contains invalid characters: \\"|\\".","invalid":true}]}}'
58 ] );
59 const response = await new mw.Api().isCategory( '|' );
60 assert.strictEqual( response, false );
61 } );
62
63 QUnit.test( '.getCategories("")', async ( assert ) => {
64 server.respondWith( /titles=$/, [
65 200,
66 { 'Content-Type': 'application/json' },
67 '{"batchcomplete":true}'
68 ] );
69 const response = await new mw.Api().getCategories( '' );
70 assert.strictEqual( response, false );
71 } );
72
73 QUnit.test( '.getCategories("#")', async ( assert ) => {
74 server.respondWith( /titles=%23$/, [
75 200,
76 { 'Content-Type': 'application/json' },
77 '{"batchcomplete":true,"query":{"normalized":[{"fromencoded":false,"from":"#","to":""}]}}'
78 ] );
79 const response = await new mw.Api().getCategories( '#' );
80 assert.strictEqual( response, false );
81 } );
82
83 QUnit.test( '.getCategories("mw:")', async ( assert ) => {
84 server.respondWith( /titles=mw%3A$/, [
85 200,
86 { 'Content-Type': 'application/json' },
87 '{"batchcomplete":true,"query":{"interwiki":[{"title":"mw:","iw":"mw"}]}}'
88 ] );
89 const response = await new mw.Api().getCategories( 'mw:' );
90 assert.strictEqual( response, false );
91 } );
92
93 QUnit.test( '.getCategories("|")', async ( assert ) => {
94 server.respondWith( /titles=%1F%7C$/, [
95 200,
96 { 'Content-Type': 'application/json' },
97 '{"batchcomplete":true,"query":{"pages":[{"title":"|","invalidreason":"The requested page title contains invalid characters: \\"|\\".","invalid":true}]}}'
98 ] );
99 const response = await new mw.Api().getCategories( '|' );
100 assert.strictEqual( response, false );
101 } );
102 } );