Skip to content

Commit 7ce2552

Browse files
committed
GANReviewTool: add tests
1 parent c85345c commit 7ce2552

File tree

2 files changed

+220
-0
lines changed

2 files changed

+220
-0
lines changed

GANReviewTool/tests/GANReviewWikicodeGenerator.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,12 @@ describe( 'getFirstTemplateNameFromWikicode(wikicode)', () => {
14821482
const output = 'Test';
14831483
expect( wg.getFirstTemplateNameFromWikicode( wikicode ) ).toBe( output );
14841484
} );
1485+
1486+
test( 'Two templates', () => {
1487+
const wikicode = 'Test {{First}} Test {{Second}} Test';
1488+
const output = 'First';
1489+
expect( wg.getFirstTemplateNameFromWikicode( wikicode ) ).toBe( output );
1490+
} );
14851491
} );
14861492

14871493
describe( 'addTemplateInCorrectMOSTalkOrderPosition(talkWikicode, codeToAdd)', () => {
@@ -1608,6 +1614,7 @@ describe( 'determineNextActionNumber(talkWikicode)', () => {
16081614
} );
16091615
} );
16101616

1617+
// Note that GARCloserWikicodeGenerator.updateArticleHistory() and GANReviewWikicodeGenerator.updateArticleHistory() are different. They take different parameters and output different wikitext.
16111618
describe( 'updateArticleHistory(talkWikicode, topic, nominationPageTitle, listedOrFailed)', () => {
16121619
test( 'listed, GA', () => {
16131620
const talkWikicode =

GANReviewTool/tests/GARCloserWikicodeGenerator.test.js

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,3 +1661,216 @@ describe( 'getStrPosOfEndOfFirstTemplateFound(wikicode, templateName)', () => {
16611661
expect( wg.getStrPosOfEndOfFirstTemplateFound( wikicode, templateNameArrayCaseInsensitive ) ).toBe( output );
16621662
} );
16631663
} );
1664+
1665+
// Note that GARCloserWikicodeGenerator.updateArticleHistory() and GANReviewWikicodeGenerator.updateArticleHistory() are different. They take different parameters and output different wikitext.
1666+
describe( 'updateArticleHistory( keepOrDelist, wikicode, garPageTitle, oldid )', () => {
1667+
test( 'kept', () => {
1668+
const keepOrDelist = 'keep';
1669+
const wikicode =
1670+
`{{ArticleHistory|action1=GAN
1671+
|action1date=04:56, 21 June 2008
1672+
|action1link=Talk:Archaeoraptor/GA1
1673+
|action1result=listed
1674+
|action1oldid=220708372
1675+
|currentstatus=GA
1676+
|topic=Biology
1677+
}}`;
1678+
const garPageTitle = 'Wikipedia:Good article reassessment/Archaeoraptor/1';
1679+
const oldid = 1111;
1680+
const output =
1681+
`{{ArticleHistory|action1=GAN
1682+
|action1date=04:56, 21 June 2008
1683+
|action1link=Talk:Archaeoraptor/GA1
1684+
|action1result=listed
1685+
|action1oldid=220708372
1686+
|topic=Biology
1687+
1688+
|action2 = GAR
1689+
|action2date = ~~~~~
1690+
|action2link = Wikipedia:Good article reassessment/Archaeoraptor/1
1691+
|action2result = kept
1692+
|action2oldid = 1111
1693+
|currentstatus = GA
1694+
}}`;
1695+
expect( wg.updateArticleHistory( keepOrDelist, wikicode, garPageTitle, oldid, oldid ) ).toBe( output );
1696+
} );
1697+
} );
1698+
1699+
describe( 'firstTemplateInsertCode(wikicode, templateNameRegExNoDelimiters, codeToInsert)', () => {
1700+
test( '{{Article history}}', () => {
1701+
const wikicode =
1702+
`{{Article history
1703+
|action1=FAC
1704+
|action1date=14 January 2004
1705+
|action1link=Wikipedia:Featured_article_candidates/Archived_nominations/Index/June_2003_to_January_2004#Bacteria
1706+
|action1result=failed
1707+
|action1oldid=47350127
1708+
}}`;
1709+
const templateNameRegExNoDelimiters = 'Article ?history';
1710+
const codeToInsert =
1711+
`|action2 = GAN
1712+
|action2date = ~~~~~
1713+
|action2link = Talk:Agriculture/GA2
1714+
|action2result = listed
1715+
|currentstatus = GA
1716+
|topic = Natural Sciences`;
1717+
const output =
1718+
`{{Article history
1719+
|action1=FAC
1720+
|action1date=14 January 2004
1721+
|action1link=Wikipedia:Featured_article_candidates/Archived_nominations/Index/June_2003_to_January_2004#Bacteria
1722+
|action1result=failed
1723+
|action1oldid=47350127
1724+
1725+
|action2 = GAN
1726+
|action2date = ~~~~~
1727+
|action2link = Talk:Agriculture/GA2
1728+
|action2result = listed
1729+
|currentstatus = GA
1730+
|topic = Natural Sciences
1731+
}}`;
1732+
expect( wg.firstTemplateInsertCode( wikicode, templateNameRegExNoDelimiters, codeToInsert ) ).toBe( output );
1733+
} );
1734+
1735+
test( 'should be case insensitive', () => {
1736+
const wikicode =
1737+
`{{ArticleHistory
1738+
|topic = Physics and astronomy
1739+
}}
1740+
`;
1741+
const templateNameRegExNoDelimiters = 'Article ?history';
1742+
const codeToInsert =
1743+
`|action12 = GAN
1744+
|action12date = ~~~~~
1745+
|action12link = Talk:SpaceX Starship/GA1
1746+
|action12result = failed
1747+
|currentstatus = DGA`;
1748+
const output =
1749+
`{{ArticleHistory
1750+
|topic = Physics and astronomy
1751+
1752+
|action12 = GAN
1753+
|action12date = ~~~~~
1754+
|action12link = Talk:SpaceX Starship/GA1
1755+
|action12result = failed
1756+
|currentstatus = DGA
1757+
}}
1758+
`;
1759+
expect( wg.firstTemplateInsertCode( wikicode, templateNameRegExNoDelimiters, codeToInsert ) ).toBe( output );
1760+
} );
1761+
} );
1762+
1763+
describe( 'firstTemplateGetParameterValue(wikicode, template, parameter)', () => {
1764+
test( 'param exists', () => {
1765+
const wikicode =
1766+
`{{Article history
1767+
|action1=AFD
1768+
|action1date=6 June 2007
1769+
|action1link=Wikipedia:Articles for deletion/Cow tipping
1770+
|action1result=kept
1771+
1772+
|action2=GAN
1773+
|action2date=~~~~~
1774+
|action2link=Talk:Cow tipping/GA1
1775+
|action2result=listed
1776+
|currentstatus=GA
1777+
|topic=agriculture
1778+
}}`;
1779+
const template = 'Article history';
1780+
const parameter = 'topic';
1781+
const output = 'agriculture';
1782+
expect( wg.firstTemplateGetParameterValue( wikicode, template, parameter ) ).toBe( output );
1783+
} );
1784+
1785+
test( 'param does not exist', () => {
1786+
const wikicode =
1787+
`{{Article history
1788+
|action1=AFD
1789+
|action1date=6 June 2007
1790+
|action1link=Wikipedia:Articles for deletion/Cow tipping
1791+
|action1result=kept
1792+
}}`;
1793+
const template = 'Article history';
1794+
const parameter = 'topic';
1795+
const output = null;
1796+
expect( wg.firstTemplateGetParameterValue( wikicode, template, parameter ) ).toBe( output );
1797+
} );
1798+
} );
1799+
1800+
describe( 'firstTemplateDeleteParameter(wikicode, template, parameter)', () => {
1801+
test( 'param exists', () => {
1802+
const wikicode =
1803+
`{{Article history
1804+
|action1=AFD
1805+
|action1date=6 June 2007
1806+
|action1link=Wikipedia:Articles for deletion/Cow tipping
1807+
|action1result=kept
1808+
1809+
|action2=GAN
1810+
|action2date=~~~~~
1811+
|action2link=Talk:Cow tipping/GA1
1812+
|action2result=listed
1813+
|currentstatus=GA
1814+
|topic=agriculture
1815+
}}`;
1816+
const template = 'Article history';
1817+
const parameter = 'topic';
1818+
const output =
1819+
`{{Article history
1820+
|action1=AFD
1821+
|action1date=6 June 2007
1822+
|action1link=Wikipedia:Articles for deletion/Cow tipping
1823+
|action1result=kept
1824+
1825+
|action2=GAN
1826+
|action2date=~~~~~
1827+
|action2link=Talk:Cow tipping/GA1
1828+
|action2result=listed
1829+
|currentstatus=GA
1830+
}}`;
1831+
expect( wg.firstTemplateDeleteParameter( wikicode, template, parameter ) ).toBe( output );
1832+
} );
1833+
1834+
test( 'param does not exist', () => {
1835+
const wikicode =
1836+
`{{Article history
1837+
|action1=AFD
1838+
|action1date=6 June 2007
1839+
|action1link=Wikipedia:Articles for deletion/Cow tipping
1840+
|action1result=kept
1841+
}}`;
1842+
const template = 'Article history';
1843+
const parameter = 'topic';
1844+
const output =
1845+
`{{Article history
1846+
|action1=AFD
1847+
|action1date=6 June 2007
1848+
|action1link=Wikipedia:Articles for deletion/Cow tipping
1849+
|action1result=kept
1850+
}}`;
1851+
expect( wg.firstTemplateDeleteParameter( wikicode, template, parameter ) ).toBe( output );
1852+
} );
1853+
1854+
test( 'edge case', () => {
1855+
const wikicode =
1856+
`{{Article history
1857+
|action1=FAC
1858+
|action1date=14 January 2004
1859+
|action1link=Wikipedia:Featured_article_candidates/Archived_nominations/Index/June_2003_to_January_2004#Bacteria
1860+
|action1result=failed
1861+
|action1oldid=47350127
1862+
|currentstatus=FFAC
1863+
}}`;
1864+
const template = 'Article history';
1865+
const parameter = 'currentstatus';
1866+
const output =
1867+
`{{Article history
1868+
|action1=FAC
1869+
|action1date=14 January 2004
1870+
|action1link=Wikipedia:Featured_article_candidates/Archived_nominations/Index/June_2003_to_January_2004#Bacteria
1871+
|action1result=failed
1872+
|action1oldid=47350127
1873+
}}`;
1874+
expect( wg.firstTemplateDeleteParameter( wikicode, template, parameter ) ).toBe( output );
1875+
} );
1876+
} );

0 commit comments

Comments
 (0)