forked from wikimedia-gadgets/afc-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: write test for AFCH.Text.cleanUp() (wikimedia-gadgets#388)
* tests: write test for AFCH.Text.cleanUp() * rename * requireScript() -> require() * fix * fix fatal error outside of tests * add DreamRimmer's tests from wikimedia-gadgets#387 from deleted commit f5df016 * fix expectedOutput * Co-authored-by: DR-WP <[email protected]> * null edit
- Loading branch information
1 parent
a76e7f2
commit 72f9c47
Showing
3 changed files
with
135 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* Tests for src/modules/submission.js | ||
*/ | ||
|
||
/* eslint-env jest */ | ||
|
||
require( './scaffold.js' ); | ||
|
||
resetToAFCApplicablePage(); | ||
|
||
require( './../src/modules/core.js' ); | ||
require( './../src/modules/submissions.js' ); | ||
|
||
// It's always good to start simple :) | ||
describe( 'AFCH', () => { | ||
it( 'is an object', () => { | ||
expect( typeof AFCH ).toBe( 'object' ); | ||
} ); | ||
} ); | ||
|
||
describe( 'AFCH.Text.cleanUp', () => { | ||
it( 'should handle empty input', () => { | ||
const wikicode = ''; | ||
const isAccept = true; | ||
const output = ( new AFCH.Text( wikicode ) ).cleanUp( isAccept ); | ||
expect( output ).toBe( '' ); | ||
} ); | ||
|
||
it( 'should clean up {{Draft categories|[[Category:Test]]}} when isAccept is true', () => { | ||
const wikicode = '{{Draft categories|[[Category:Test]]}}'; | ||
const isAccept = true; | ||
const expectedOutput = '[[Category:Test]]'; | ||
const output = ( new AFCH.Text( wikicode ) ).cleanUp( isAccept ); | ||
expect( output ).toBe( expectedOutput ); | ||
} ); | ||
|
||
it( 'should not clean up {{Draft categories|[[Category:Test]]}} when isAccept is false', () => { | ||
const wikicode = '{{Draft categories|[[Category:Test]]}}'; | ||
const isAccept = false; | ||
const expectedOutput = '{{Draft categories|[[:Category:Test]]}}'; | ||
const output = ( new AFCH.Text( wikicode ) ).cleanUp( isAccept ); | ||
expect( output ).toBe( expectedOutput ); | ||
} ); | ||
|
||
it( 'should clean up {{draft categories|[[Category:Test]]}} (case insensitive) when isAccept is true', () => { | ||
const wikicode = '{{draft categories|[[Category:Test]]}}'; | ||
const isAccept = true; | ||
const expectedOutput = '[[Category:Test]]'; | ||
const output = ( new AFCH.Text( wikicode ) ).cleanUp( isAccept ); | ||
expect( output ).toBe( expectedOutput ); | ||
} ); | ||
|
||
it( 'should not clean up {{draft categories|[[Category:Test]]}} (case insensitive) when isAccept is false', () => { | ||
const wikicode = '{{draft categories|[[Category:Test]]}}'; | ||
const isAccept = false; | ||
const expectedOutput = '{{draft categories|[[:Category:Test]]}}'; | ||
const output = ( new AFCH.Text( wikicode ) ).cleanUp( isAccept ); | ||
expect( output ).toBe( expectedOutput ); | ||
} ); | ||
|
||
it( 'should clean up {{Draftcat|[[Category:Test]]}} when isAccept is true', () => { | ||
const wikicode = '{{Draftcat|[[Category:Test]]}}'; | ||
const isAccept = true; | ||
const expectedOutput = '[[Category:Test]]'; | ||
const output = ( new AFCH.Text( wikicode ) ).cleanUp( isAccept ); | ||
expect( output ).toBe( expectedOutput ); | ||
} ); | ||
|
||
it( 'should not clean up {{Draftcat|[[Category:Test]]}} when isAccept is false', () => { | ||
const wikicode = '{{Draftcat|[[Category:Test]]}}'; | ||
const isAccept = false; | ||
const expectedOutput = '{{Draftcat|[[:Category:Test]]}}'; | ||
const output = ( new AFCH.Text( wikicode ) ).cleanUp( isAccept ); | ||
expect( output ).toBe( expectedOutput ); | ||
} ); | ||
|
||
it( 'should clean up multiple categories in {{Draft categories}} when isAccept is true', () => { | ||
const wikicode = '{{Draft categories|[[Category:Test1]] [[Category:Test2]]}}'; | ||
const isAccept = true; | ||
const expectedOutput = '[[Category:Test1]] [[Category:Test2]]'; | ||
const output = ( new AFCH.Text( wikicode ) ).cleanUp( isAccept ); | ||
expect( output ).toBe( expectedOutput ); | ||
} ); | ||
|
||
it( 'should not clean up {{Draft categories}} without categories when isAccept is false', () => { | ||
const wikicode = '{{Draft categories}}'; | ||
const isAccept = false; | ||
const expectedOutput = '{{Draft categories}}'; | ||
const output = ( new AFCH.Text( wikicode ) ).cleanUp( isAccept ); | ||
expect( output ).toBe( expectedOutput ); | ||
} ); | ||
|
||
it( 'should clean up {{Draft categories}} with text outside the template when isAccept is true', () => { | ||
const wikicode = 'Some text {{Draft categories|[[Category:Test]]}} more text'; | ||
const isAccept = true; | ||
const expectedOutput = 'Some text [[Category:Test]] more text'; | ||
const output = ( new AFCH.Text( wikicode ) ).cleanUp( isAccept ); | ||
expect( output ).toBe( expectedOutput ); | ||
} ); | ||
|
||
it( 'should not alter non-draft templates', () => { | ||
const wikicode = '{{NonDraft|[[Category:Test]]}}'; | ||
const isAccept = true; | ||
const expectedOutput = '{{NonDraft|[[Category:Test]]}}'; | ||
const output = ( new AFCH.Text( wikicode ) ).cleanUp( isAccept ); | ||
expect( output ).toBe( expectedOutput ); | ||
} ); | ||
} ); |