-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathUserHighlighterSimple.test.js
More file actions
108 lines (82 loc) · 4.9 KB
/
Copy pathUserHighlighterSimple.test.js
File metadata and controls
108 lines (82 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { UserHighlighterSimple } from '../modules/UserHighlighterSimple.js';
// Babel is required to use ES6 module syntax
// Copy package.json and .babelrc from a project that already has this working
// Babel tutorial: https://www.sitepoint.com/babel-beginners-guide/
const userHighlighterSimple = new UserHighlighterSimple( $, mw, window );
describe( 'linksToAUser( url )', () => {
test( 'normal non-userpage URL using /wiki/', () => {
expect( userHighlighterSimple.linksToAUser( 'https://en.wikipedia.org/wiki/Main_Page' ) ).toBe( false );
} );
test( 'normal userpage URL using /wiki/', () => {
expect( userHighlighterSimple.linksToAUser( 'https://en.wikipedia.org/wiki/User:Novem_Linguae' ) ).toBe( true );
} );
test( 'normal user talk page URL using /wiki/', () => {
expect( userHighlighterSimple.linksToAUser( 'https://en.wikipedia.org/wiki/User talk:Novem_Linguae' ) ).toBe( true );
} );
test( 'not http or https', () => {
expect( userHighlighterSimple.linksToAUser( 'ftp://en.wikipedia.org/wiki/User:Novem_Linguae' ) ).toBe( false );
} );
test( 'is an anchor URL only (starts with #)', () => {
expect( userHighlighterSimple.linksToAUser( 'ftp://en.wikipedia.org/wiki/User:Novem_Linguae' ) ).toBe( false );
} );
test( 'gibberish string', () => {
expect( userHighlighterSimple.linksToAUser( 'abcd' ) ).toBe( false );
} );
test( 'empty string', () => {
expect( userHighlighterSimple.linksToAUser( '' ) ).toBe( false );
} );
test( 'URL starts with /, needs a domain added', () => {
expect( userHighlighterSimple.linksToAUser( '/wiki/User:Novem_Linguae' ) ).toBe( true );
} );
test( 'URL starts with /, needs a domain added', () => {
expect( userHighlighterSimple.linksToAUser( '/wiki/Main_Page' ) ).toBe( false );
} );
test( 'URL with section link should not throw error', () => {
expect( userHighlighterSimple.linksToAUser( 'https://meta.wikimedia.org/wiki/Community_Wishlist_Survey_2022/Larger_suggestions#1%' ) ).toBe( false );
} );
test( 'URL with parameters that aren\'t title, action, or redlink', () => {
expect( userHighlighterSimple.linksToAUser( 'https://en.wikipedia.org/w/index.php?title=User:Novem_Linguae&diff=prev&oldid=1276401726' ) ).toBe( false );
} );
test( 'URL with parameters that are title, action, or redlink', () => {
expect( userHighlighterSimple.linksToAUser( 'https://en.wikipedia.org/w/index.php?title=Main_Page' ) ).toBe( false );
} );
test( 'URL with parameters that are title, action, or redlink', () => {
expect( userHighlighterSimple.linksToAUser( 'https://en.wikipedia.org/w/index.php?title=User:Novem_Linguae' ) ).toBe( true );
} );
test( 'archive URL of a user page', () => {
expect( userHighlighterSimple.linksToAUser( 'https://web.archive.org/web/20231105033559/https://en.wikipedia.org/wiki/User:SandyGeorgia/SampleIssue' ) ).toBe( false );
} );
test( 'wrong namespace', () => {
expect( userHighlighterSimple.linksToAUser( 'https://en.wikipedia.org/wiki/Template:Uw-test1' ) ).toBe( false );
} );
test( 'DiscussionTools section link', () => {
expect( userHighlighterSimple.linksToAUser( 'https://en.wikipedia.org/wiki/User_talk:Novem_Linguae#c-Scope_creep-20250218175200-Novem_Linguae-20250218170600' ) ).toBe( false );
} );
test( 'invalid domain name (weird punctuation)', () => {
expect( userHighlighterSimple.linksToAUser( 'https://a:a' ) ).toBe( false );
expect( userHighlighterSimple.linksToAUser( 'http://Wikipedia:Requests%20for%20arbitration/Eastern%20Europe' ) ).toBe( false );
} );
test( 'mainspace article names that start with "User"', () => {
expect( userHighlighterSimple.linksToAUser( 'https://en.wikipedia.org/wiki/User' ) ).toBe( false );
expect( userHighlighterSimple.linksToAUser( 'https://en.wikipedia.org/wiki/User_(computing)' ) ).toBe( false );
expect( userHighlighterSimple.linksToAUser( 'https://en.wikipedia.org/wiki/User-centered_design' ) ).toBe( false );
expect( userHighlighterSimple.linksToAUser( 'https://en.wikipedia.org/wiki/User_interface' ) ).toBe( false );
} );
} );
describe( 'getTitle( url )', () => {
test( 'URL using /wiki/, user namespace', () => {
expect( userHighlighterSimple.getTitle( 'https://en.wikipedia.org/wiki/User:Novem_Linguae' ) ).toBe( 'User:Novem_Linguae' );
} );
test( 'URL using ?title=, user namespace', () => {
expect( userHighlighterSimple.getTitle( 'https://en.wikipedia.org/w/index.php?title=User:Novem_Linguae' ) ).toBe( 'User:Novem_Linguae' );
} );
test( 'URL using /wiki/, user talk namespace', () => {
expect( userHighlighterSimple.getTitle( 'https://en.wikipedia.org/wiki/User talk:Novem_Linguae' ) ).toBe( 'User talk:Novem_Linguae' );
} );
test( 'URL using ?title=, user talk namespace', () => {
expect( userHighlighterSimple.getTitle( 'https://en.wikipedia.org/w/index.php?title=User talk:Novem_Linguae' ) ).toBe( 'User talk:Novem_Linguae' );
} );
test( 'neither of the above', () => {
expect( userHighlighterSimple.getTitle( 'https://en.wikipedia.org/' ) ).toBe( '' );
} );
} );