|
| 1 | +import '../../../src/types'; |
| 2 | +import 'types-mediawiki'; |
| 3 | +import BrowserHelper from '../../util/BrowserHelper'; |
| 4 | +import WikiConfiguration from '../../../src/config/WikiConfiguration'; |
| 5 | +import CopyrightProblemsListing, { |
| 6 | + SerializedCopyrightProblemsListingData |
| 7 | +} from '../../../src/modules/ia/models/CopyrightProblemsListing'; |
| 8 | + |
| 9 | +describe( 'CopyrightProblemsPage tests', () => { |
| 10 | + |
| 11 | + let page: BrowserHelper; |
| 12 | + |
| 13 | + beforeAll( async () => { |
| 14 | + page = await BrowserHelper.build() |
| 15 | + .then( p => p.loadWikipediaPage( |
| 16 | + 'User:Chlod/Scripts/Deputy/tests/Problems/UnitTests' |
| 17 | + ) ) |
| 18 | + .then( async p => ( <const>[ await p.evaluate( () => { |
| 19 | + // Override the IA root page |
| 20 | + const mockCPN = async () => { |
| 21 | + const config = await window.InfringementAssistant.getWikiConfig(); |
| 22 | + config.ia.rootPage.set( new mw.Title( |
| 23 | + 'User:Chlod/Scripts/Deputy/tests/Problems' |
| 24 | + ) ); |
| 25 | + }; |
| 26 | + mw.hook( 'deputy.preload' ).add( mockCPN ); |
| 27 | + mw.hook( 'infringementAssistant.preload' ).add( mockCPN ); |
| 28 | + } ), p ] )[ 1 ] ) |
| 29 | + .then( p => p.loadDeputyScript() ) |
| 30 | + .then( async p => ( <const>[ await p.wait( |
| 31 | + () => p.evaluate( |
| 32 | + () => window.InfringementAssistant.session != null |
| 33 | + ), |
| 34 | + 30e3 |
| 35 | + ), p ] )[ 1 ] ); |
| 36 | + }, 60e3 ); |
| 37 | + |
| 38 | + afterAll( async () => { |
| 39 | + await page.close(); |
| 40 | + } ); |
| 41 | + |
| 42 | + test( 'session exists', async () => { |
| 43 | + expect( await page.evaluate( () => { |
| 44 | + console.log( 'a', window ); |
| 45 | + return window.InfringementAssistant.session != null; |
| 46 | + } ) ).toBe( true ); |
| 47 | + } ); |
| 48 | + |
| 49 | + test( 'listings detected', async () => { |
| 50 | + expect( await page.evaluate( () => { |
| 51 | + return window.InfringementAssistant.session.listingMap.size; |
| 52 | + } ) ).toBe( 10 ); |
| 53 | + } ); |
| 54 | + |
| 55 | + const testListingPage = ( |
| 56 | + listingPage: SerializedCopyrightProblemsListingData['listingPage'] |
| 57 | + ) => { |
| 58 | + expect( listingPage ).toHaveProperty( 'namespace', 2 ); |
| 59 | + expect( listingPage ).toHaveProperty( |
| 60 | + 'title', |
| 61 | + 'Chlod/Scripts/Deputy/tests/Problems/UnitTests' |
| 62 | + ); |
| 63 | + expect( listingPage ).toHaveProperty( 'fragment', null ); |
| 64 | + }; |
| 65 | + |
| 66 | + // `* {{subst:article-cv|Example1}} from somewhere ~~~~` |
| 67 | + test( 'listing', async () => { |
| 68 | + const listing: SerializedCopyrightProblemsListingData = await page.evaluate( () => { |
| 69 | + return window.InfringementAssistant.session.getListings()[ 0 ].serialize(); |
| 70 | + } ); |
| 71 | + expect( listing.i ).toBe( 1 ); |
| 72 | + expect( listing.id ).toBe( 'Example1' ); |
| 73 | + expect( listing.basic ).toBeFalsy(); |
| 74 | + testListingPage( listing.listingPage ); |
| 75 | + expect( listing.title ).toHaveProperty( 'namespace', 0 ); |
| 76 | + expect( listing.title ).toHaveProperty( 'title', 'Example1' ); |
| 77 | + expect( listing.title ).toHaveProperty( 'fragment', null ); |
| 78 | + expect( ( listing.lines.end - listing.lines.start ) + 1 ).toBe( 1 ); |
| 79 | + } ); |
| 80 | + |
| 81 | + // ``` |
| 82 | + // * {{subst:article-cv|Example2}} from somewhere ~~~~ |
| 83 | + // *: Comment ~~~~ |
| 84 | + // ``` |
| 85 | + test( 'listing with comment', async () => { |
| 86 | + const listing: SerializedCopyrightProblemsListingData = await page.evaluate( () => { |
| 87 | + return window.InfringementAssistant.session.getListings()[ 1 ].serialize(); |
| 88 | + } ); |
| 89 | + expect( listing.i ).toBe( 1 ); |
| 90 | + expect( listing.id ).toBe( 'Example2' ); |
| 91 | + expect( listing.basic ).toBeFalsy(); |
| 92 | + testListingPage( listing.listingPage ); |
| 93 | + expect( listing.title ).toHaveProperty( 'namespace', 0 ); |
| 94 | + expect( listing.title ).toHaveProperty( 'title', 'Example2' ); |
| 95 | + expect( listing.title ).toHaveProperty( 'fragment', null ); |
| 96 | + expect( ( listing.lines.end - listing.lines.start ) + 1 ).toBe( 2 ); |
| 97 | + } ); |
| 98 | + |
| 99 | + // ``` |
| 100 | + // * {{subst:article-cv|Example3}} from somewhere ~~~~ |
| 101 | + // *: Comment1 ~~~~ |
| 102 | + // *:: Comment2 ~~~~ |
| 103 | + // ``` |
| 104 | + test( 'listing with nested comment', async () => { |
| 105 | + const listing: SerializedCopyrightProblemsListingData = await page.evaluate( () => { |
| 106 | + return window.InfringementAssistant.session.getListings()[ 2 ].serialize(); |
| 107 | + } ); |
| 108 | + expect( listing.i ).toBe( 1 ); |
| 109 | + expect( listing.id ).toBe( 'Example3' ); |
| 110 | + expect( listing.basic ).toBeFalsy(); |
| 111 | + testListingPage( listing.listingPage ); |
| 112 | + expect( listing.title ).toHaveProperty( 'namespace', 0 ); |
| 113 | + expect( listing.title ).toHaveProperty( 'title', 'Example3' ); |
| 114 | + expect( listing.title ).toHaveProperty( 'fragment', null ); |
| 115 | + expect( ( listing.lines.end - listing.lines.start ) + 1 ).toBe( 3 ); |
| 116 | + } ); |
| 117 | + |
| 118 | + // ``` |
| 119 | + // * {{subst:article-cv|Example4}} from somewhere ~~~~ |
| 120 | + // {{subst:CPC|c}} |
| 121 | + // *:: Comment 3 ~~~~ |
| 122 | + // ``` |
| 123 | + test( 'listing with resolution with reply', async () => { |
| 124 | + const listing: SerializedCopyrightProblemsListingData = await page.evaluate( () => { |
| 125 | + return window.InfringementAssistant.session.getListings()[ 3 ].serialize(); |
| 126 | + } ); |
| 127 | + expect( listing.i ).toBe( 1 ); |
| 128 | + expect( listing.id ).toBe( 'Example4' ); |
| 129 | + expect( listing.basic ).toBeFalsy(); |
| 130 | + testListingPage( listing.listingPage ); |
| 131 | + expect( listing.title ).toHaveProperty( 'namespace', 0 ); |
| 132 | + expect( listing.title ).toHaveProperty( 'title', 'Example4' ); |
| 133 | + expect( listing.title ).toHaveProperty( 'fragment', null ); |
| 134 | + expect( ( listing.lines.end - listing.lines.start ) + 1 ).toBe( 3 ); |
| 135 | + } ); |
| 136 | + |
| 137 | + // ``` |
| 138 | + // * {{subst:article-cv|Example5}} from somewhere ~~~~ |
| 139 | + // *:: Comment 4 ~~~~ |
| 140 | + // {{subst:CPC|c}} |
| 141 | + // ``` |
| 142 | + test( 'listing with resolution and comment', async () => { |
| 143 | + const listing: SerializedCopyrightProblemsListingData = await page.evaluate( () => { |
| 144 | + return window.InfringementAssistant.session.getListings()[ 4 ].serialize(); |
| 145 | + } ); |
| 146 | + expect( listing.i ).toBe( 1 ); |
| 147 | + expect( listing.id ).toBe( 'Example5' ); |
| 148 | + expect( listing.basic ).toBeFalsy(); |
| 149 | + testListingPage( listing.listingPage ); |
| 150 | + expect( listing.title ).toHaveProperty( 'namespace', 0 ); |
| 151 | + expect( listing.title ).toHaveProperty( 'title', 'Example5' ); |
| 152 | + expect( listing.title ).toHaveProperty( 'fragment', null ); |
| 153 | + expect( ( listing.lines.end - listing.lines.start ) + 1 ).toBe( 3 ); |
| 154 | + } ); |
| 155 | + |
| 156 | + // ``` |
| 157 | + // * {{subst:article-cv|Example6}} from somewhere ~~~~ |
| 158 | + // ** Comment 5 ~~~~ |
| 159 | + // *** Comment 6 ~~~~ |
| 160 | + // ``` |
| 161 | + test( 'listing with bullet-based comments', async () => { |
| 162 | + const listing: SerializedCopyrightProblemsListingData = await page.evaluate( () => { |
| 163 | + return window.InfringementAssistant.session.getListings()[ 5 ].serialize(); |
| 164 | + } ); |
| 165 | + expect( listing.i ).toBe( 1 ); |
| 166 | + expect( listing.id ).toBe( 'Example6' ); |
| 167 | + expect( listing.basic ).toBeFalsy(); |
| 168 | + testListingPage( listing.listingPage ); |
| 169 | + expect( listing.title ).toHaveProperty( 'namespace', 0 ); |
| 170 | + expect( listing.title ).toHaveProperty( 'title', 'Example6' ); |
| 171 | + expect( listing.title ).toHaveProperty( 'fragment', null ); |
| 172 | + expect( ( listing.lines.end - listing.lines.start ) + 1 ).toBe( 3 ); |
| 173 | + } ); |
| 174 | + |
| 175 | + // ``` |
| 176 | + // * {{subst:article-cv|Example7}} from somewhere ~~~~ |
| 177 | + // |
| 178 | + // |
| 179 | + // ``` |
| 180 | + test( 'listing with list break', async () => { |
| 181 | + const listing: SerializedCopyrightProblemsListingData = await page.evaluate( () => { |
| 182 | + return window.InfringementAssistant.session.getListings()[ 6 ].serialize(); |
| 183 | + } ); |
| 184 | + expect( listing.i ).toBe( 1 ); |
| 185 | + expect( listing.id ).toBe( 'Example7' ); |
| 186 | + expect( listing.basic ).toBeFalsy(); |
| 187 | + testListingPage( listing.listingPage ); |
| 188 | + expect( listing.title ).toHaveProperty( 'namespace', 0 ); |
| 189 | + expect( listing.title ).toHaveProperty( 'title', 'Example7' ); |
| 190 | + expect( listing.title ).toHaveProperty( 'fragment', null ); |
| 191 | + expect( ( listing.lines.end - listing.lines.start ) + 1 ).toBe( 1 ); |
| 192 | + } ); |
| 193 | + |
| 194 | + // ``` |
| 195 | + // * {{subst:article-cv|Example8}} from somewhere ~~~~ |
| 196 | + // ``` |
| 197 | + test( 'edge: post-break listing', async () => { |
| 198 | + const listing: SerializedCopyrightProblemsListingData = await page.evaluate( () => { |
| 199 | + return window.InfringementAssistant.session.getListings()[ 7 ].serialize(); |
| 200 | + } ); |
| 201 | + expect( listing.i ).toBe( 1 ); |
| 202 | + expect( listing.id ).toBe( 'Example8' ); |
| 203 | + expect( listing.basic ).toBeFalsy(); |
| 204 | + testListingPage( listing.listingPage ); |
| 205 | + expect( listing.title ).toHaveProperty( 'namespace', 0 ); |
| 206 | + expect( listing.title ).toHaveProperty( 'title', 'Example8' ); |
| 207 | + expect( listing.title ).toHaveProperty( 'fragment', null ); |
| 208 | + expect( ( listing.lines.end - listing.lines.start ) + 1 ).toBe( 1 ); |
| 209 | + } ); |
| 210 | + |
| 211 | + // ``` |
| 212 | + // * {{subst:article-cv|Example9}} from somewhere ~~~~ |
| 213 | + // *: Comment 7 ~~~~ |
| 214 | + // ::: Comment 8 ~~~~ |
| 215 | + // ``` |
| 216 | + test( 'edge: listing with broken (dl) comment thread', async () => { |
| 217 | + const listing: SerializedCopyrightProblemsListingData = await page.evaluate( () => { |
| 218 | + return window.InfringementAssistant.session.getListings()[ 8 ].serialize(); |
| 219 | + } ); |
| 220 | + expect( listing.i ).toBe( 1 ); |
| 221 | + expect( listing.id ).toBe( 'Example9' ); |
| 222 | + expect( listing.basic ).toBeFalsy(); |
| 223 | + testListingPage( listing.listingPage ); |
| 224 | + expect( listing.title ).toHaveProperty( 'namespace', 0 ); |
| 225 | + expect( listing.title ).toHaveProperty( 'title', 'Example9' ); |
| 226 | + expect( listing.title ).toHaveProperty( 'fragment', null ); |
| 227 | + expect( ( listing.lines.end - listing.lines.start ) + 1 ).toBe( 3 ); |
| 228 | + } ); |
| 229 | + |
| 230 | + // ``` |
| 231 | + // * {{subst:article-cv|Example1}} from somewhere ~~~~ |
| 232 | + // ``` |
| 233 | + test( 'edge: post-break and duplicate listing', async () => { |
| 234 | + const listing: SerializedCopyrightProblemsListingData = await page.evaluate( () => { |
| 235 | + return window.InfringementAssistant.session.getListings()[ 9 ].serialize(); |
| 236 | + } ); |
| 237 | + expect( listing.i ).toBe( 2 ); |
| 238 | + expect( listing.id ).toBe( 'Example1' ); |
| 239 | + expect( listing.basic ).toBeFalsy(); |
| 240 | + testListingPage( listing.listingPage ); |
| 241 | + expect( listing.title ).toHaveProperty( 'namespace', 0 ); |
| 242 | + expect( listing.title ).toHaveProperty( 'title', 'Example1' ); |
| 243 | + expect( listing.title ).toHaveProperty( 'fragment', null ); |
| 244 | + expect( ( listing.lines.end - listing.lines.start ) + 1 ).toBe( 1 ); |
| 245 | + } ); |
| 246 | + |
| 247 | +} ); |
0 commit comments