|
| 1 | +import MediaWiki from '../../src/MediaWiki.js' |
| 2 | + |
| 3 | +describe('Checking Mediawiki capabilities', () => { |
| 4 | + beforeEach(() => { |
| 5 | + MediaWiki.reset() |
| 6 | + }) |
| 7 | + |
| 8 | + afterEach(() => { |
| 9 | + MediaWiki.reset() |
| 10 | + }) |
| 11 | + |
| 12 | + test('test capabilities of en.wikipedia.org', async () => { |
| 13 | + MediaWiki.base = 'https://en.wikipedia.org' |
| 14 | + expect(await MediaWiki.hasWikimediaDesktopApi()).toBe(true) |
| 15 | + expect(await MediaWiki.hasWikimediaMobileApi()).toBe(true) |
| 16 | + expect(await MediaWiki.hasMediawikiRestApi()).toBe(true) |
| 17 | + expect(await MediaWiki.hasVisualEditorApi()).toBe(true) |
| 18 | + }) |
| 19 | + |
| 20 | + test('test capabilities of wiki.openstreetmap.org', async () => { |
| 21 | + MediaWiki.base = 'https://wiki.openstreetmap.org' |
| 22 | + |
| 23 | + expect(await MediaWiki.hasWikimediaDesktopApi()).toBe(false) |
| 24 | + expect(await MediaWiki.hasWikimediaMobileApi()).toBe(false) |
| 25 | + expect(await MediaWiki.hasMediawikiRestApi()).toBe(true) |
| 26 | + expect(await MediaWiki.hasVisualEditorApi()).toBe(true) |
| 27 | + }) |
| 28 | + |
| 29 | + test('test capabilities of fo.wikisource.org', async () => { |
| 30 | + MediaWiki.base = 'https://fo.wikisource.org' |
| 31 | + |
| 32 | + expect(await MediaWiki.hasWikimediaDesktopApi()).toBe(true) |
| 33 | + expect(await MediaWiki.hasWikimediaMobileApi()).toBe(false) |
| 34 | + expect(await MediaWiki.hasMediawikiRestApi()).toBe(true) |
| 35 | + expect(await MediaWiki.hasVisualEditorApi()).toBe(true) |
| 36 | + }) |
| 37 | + |
| 38 | + test('test capabilities of minecraft.wiki with correct VisualEditor receipt', async () => { |
| 39 | + MediaWiki.base = 'https://minecraft.wiki' |
| 40 | + MediaWiki.wikiPath = '/' |
| 41 | + MediaWiki.actionApiPath = 'api.php' |
| 42 | + |
| 43 | + expect(await MediaWiki.hasWikimediaDesktopApi()).toBe(false) |
| 44 | + expect(await MediaWiki.hasWikimediaMobileApi()).toBe(false) |
| 45 | + expect(await MediaWiki.hasMediawikiRestApi()).toBe(false) |
| 46 | + expect(await MediaWiki.hasVisualEditorApi()).toBe(true) |
| 47 | + }) |
| 48 | + |
| 49 | + test('test capabilities of pokemon.fandom.com with correct VisualEditor receipt', async () => { |
| 50 | + MediaWiki.base = 'https://pokemon.fandom.com/' |
| 51 | + MediaWiki.wikiPath = '/' |
| 52 | + MediaWiki.actionApiPath = 'api.php' |
| 53 | + |
| 54 | + expect(await MediaWiki.hasWikimediaDesktopApi()).toBe(false) |
| 55 | + expect(await MediaWiki.hasWikimediaMobileApi()).toBe(false) |
| 56 | + expect(await MediaWiki.hasMediawikiRestApi()).toBe(false) |
| 57 | + expect(await MediaWiki.hasVisualEditorApi()).toBe(true) |
| 58 | + }) |
| 59 | + |
| 60 | + test('test capabilities of pokemon.fandom.com with default receipt', async () => { |
| 61 | + MediaWiki.base = 'https://pokemon.fandom.com/' |
| 62 | + |
| 63 | + expect(await MediaWiki.hasWikimediaDesktopApi()).toBe(false) |
| 64 | + expect(await MediaWiki.hasWikimediaMobileApi()).toBe(false) |
| 65 | + expect(await MediaWiki.hasMediawikiRestApi()).toBe(false) |
| 66 | + expect(await MediaWiki.hasVisualEditorApi()).toBe(false) |
| 67 | + }) |
| 68 | + |
| 69 | + test('test capabilities of pokemon.fandom.com with MediawikiRestApi receipt', async () => { |
| 70 | + MediaWiki.base = 'https://pokemon.fandom.com/' |
| 71 | + MediaWiki.wikiPath = '/' |
| 72 | + MediaWiki.mediawikiRestApiPath = 'rest.php/v1/page/' |
| 73 | + |
| 74 | + expect(await MediaWiki.hasWikimediaDesktopApi()).toBe(false) |
| 75 | + expect(await MediaWiki.hasWikimediaMobileApi()).toBe(false) |
| 76 | + expect(await MediaWiki.hasVisualEditorApi()).toBe(false) |
| 77 | + |
| 78 | + /* TODO: |
| 79 | + Title MediaWiki:Sidebar does not exist for Mediawiki Rest Api in pokemon.fandom.com for some reason. This will lead to incorrect capability check |
| 80 | + See: https://pokemon.fandom.com/rest.php/v1/page/MediaWiki%3ASidebar/html |
| 81 | + */ |
| 82 | + MediaWiki.apiCheckArticleId = 'Volcarona' |
| 83 | + expect(await MediaWiki.hasMediawikiRestApi()).toBe(true) |
| 84 | + }) |
| 85 | +}) |
0 commit comments