summaryrefslogtreecommitdiff
blob: 7c98fc6a57cc366adf2bbedcb8bb002060764cb6 (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
( function ( mw ) {
	// Mock partial API response we feed into the model
	var sources = {
		local: {
			pages: [
				{
					ns: 2,
					title: 'User:Admin',
					unprefixed: 'Admin',
					pages: [
						'User:Admin',
						'User talk:Admin',
						null
					],
					count: 24
				},
				{
					ns: 2,
					title: 'User:RandomUser',
					unprefixed: 'RandomUser',
					pages: [
						'User:RandomUser',
						'User talk:RandomUser'
					],
					count: 6
				},
				{
					ns: 0,
					title: 'Moai',
					unprefixed: 'Moai',
					pages: [
						'Moai',
						'Talk:Moai'
					],
					count: 3
				}
			],
			totalCount: 33,
			source: {
				title: 'LocalWiki',
				url: 'http://dev.wiki.local.wmftest.net:8080/w/api.php',
				base: 'http://dev.wiki.local.wmftest.net:8080/wiki/$1'
			}
		},
		hewiki: {
			pages: [
				{
					ns: 2,
					title: 'Foo',
					unprefixed: 'Foo',
					pages: [
						'Foo',
						'Talk:Foo',
						null
					],
					count: 10
				},
				{
					ns: 0,
					title: 'User:Bar',
					unprefixed: 'Bar',
					pages: [
						'User:Bar',
						'User talk:Bar'
					],
					count: 5
				}
			],
			totalCount: 15,
			source: {
				title: 'Hebrew Wikipedia',
				url: 'http://he.wiki.local.wmftest.net:8080/w/api.php',
				base: 'http://he.wiki.local.wmftest.net:8080/wiki/$1'
			}
		}
	};

	QUnit.module( 'ext.echo.dm - mw.echo.dm.SourcePagesModel' );

	QUnit.test( 'Creating source-page map', function ( assert ) {
		var model = new mw.echo.dm.SourcePagesModel();

		model.setAllSources( sources );

		assert.strictEqual(
			model.getCurrentSource(),
			'local',
			'Default source is local'
		);
		assert.strictEqual(
			model.getCurrentPage(),
			null,
			'Default page is null'
		);
		assert.deepEqual(
			model.getSourcesArray(),
			[ 'local', 'hewiki' ],
			'Source array includes all sources'
		);
		assert.strictEqual(
			model.getSourceTitle( 'hewiki' ),
			'Hebrew Wikipedia',
			'Source title'
		);
		assert.strictEqual(
			model.getSourceTotalCount( 'hewiki' ),
			15,
			'Source total count'
		);
		assert.deepEqual(
			model.getSourcePages( 'local' ),
			{
				Moai: {
					count: 3,
					ns: 0,
					pages: [
						'Moai',
						'Talk:Moai'
					],
					title: 'Moai',
					unprefixed: 'Moai'
				},
				'User:Admin': {
					count: 24,
					ns: 2,
					pages: [
						'User:Admin',
						'User talk:Admin',
						null
					],
					title: 'User:Admin',
					unprefixed: 'Admin'
				},
				'User:RandomUser': {
					count: 6,
					ns: 2,
					pages: [
						'User:RandomUser',
						'User talk:RandomUser'
					],
					title: 'User:RandomUser',
					unprefixed: 'RandomUser'
				}
			},
			'Outputting source pages'
		);
		assert.deepEqual(
			model.getGroupedPagesForTitle( 'local', 'User:Admin' ),
			[
				'User:Admin',
				'User talk:Admin',
				null
			],
			'Grouped pages per title'
		);

		// Change source
		model.setCurrentSourcePage( 'hewiki', 'User:Bar' );

		assert.strictEqual(
			model.getCurrentSource(),
			'hewiki',
			'Source changed successfully'
		);
		assert.strictEqual(
			model.getCurrentPage(),
			'User:Bar',
			'Page changed successfully'
		);

	} );
}( mediaWiki ) );