diff --git a/tests/test-submissions.js b/tests/test-submissions.js index fc2c72cc..b9d1d8d4 100644 --- a/tests/test-submissions.js +++ b/tests/test-submissions.js @@ -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 ); } ); } );