Skip to content

Commit

Permalink
add DreamRimmer's tests from wikimedia-gadgets#387
Browse files Browse the repository at this point in the history
from deleted commit f5df016
  • Loading branch information
NovemLinguae committed Oct 20, 2024
1 parent a92b5ae commit a37e3f2
Showing 1 changed file with 83 additions and 3 deletions.
86 changes: 83 additions & 3 deletions tests/test-submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,90 @@ describe( 'AFCH', () => {
} );

describe( 'AFCH.Text.cleanUp', () => {
it( 'simple accept', () => {
const wikicode = 'Test';
it( 'should handle empty input', () => {
const wikicode = '';
const isAccept = true;
const output = ( new AFCH.Text( wikicode ) ).cleanUp( isAccept );
expect( output ).toBe( 'Test' );
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 );
} );
} );

0 comments on commit a37e3f2

Please sign in to comment.