@@ -4,8 +4,8 @@ import { MOSOrderPositionFinder } from '../modules/MOSOrderPositionFinder.js';
44// Copy package.json and .babelrc from a project that already has this working
55// Babel tutorial: https://www.sitepoint.com/babel-beginners-guide/
66
7- describe ( 'getAllExistingSectionPositions (wikicode)' , ( ) => {
8- test ( 'simple ' , ( ) => {
7+ describe ( 'hasSection (wikicode, section )' , ( ) => {
8+ test ( 'Section exists ' , ( ) => {
99 const mopf = new MOSOrderPositionFinder ( ) ;
1010 const wikicode =
1111`{{Short description|test}}
1616Body
1717
1818{{Navbox}}` ;
19- const output = {
20- top : 0 ,
21- shortDescription : 0 ,
22- lead : 28 ,
23- body : 34 ,
24- navboxes : 60 ,
25- bottom : 70
26- } ;
27- expect ( mopf . getAllExistingSectionPositions ( wikicode ) ) . toStrictEqual ( output ) ;
19+ expect ( mopf . hasSection ( wikicode , 'shortDescription' ) ) . toBe ( true ) ;
2820 } ) ;
29- } ) ;
3021
31- describe ( 'getAllExistingSectionPositions(wikicode)' , ( ) => {
32- test ( 'bug involving putting HTML comments in the wrong place in AFC drafts' , ( ) => {
22+ test ( 'Section does not exist' , ( ) => {
3323 const mopf = new MOSOrderPositionFinder ( ) ;
3424 const wikicode =
35- `{{AfC Comment}}<!-- do not remove this line-->
36-
37- Lead` ;
38- const needle = '{{Speciesbox}}' ;
39- const section = 'infoboxes' ;
40- const output =
41- `{{AfC Comment}}<!-- do not remove this line-->
25+ `Lead
4226
43- {{Speciesbox}}
27+ == First heading ==
28+ Body` ;
29+ expect ( mopf . hasSection ( wikicode , 'shortDescription' ) ) . toBe ( false ) ;
30+ } ) ;
4431
45- Lead` ;
46- expect ( mopf . insertAtSection ( wikicode , needle , section ) ) . toStrictEqual ( output ) ;
32+ test ( 'Invalid section name' , ( ) => {
33+ const mopf = new MOSOrderPositionFinder ( ) ;
34+ const wikicode = 'test' ;
35+ expect ( ( ) => {
36+ mopf . hasSection ( wikicode , 'invalidSection' ) ;
37+ } ) . toThrowError ( 'MOSOrderPositionFinder: Invalid section name.' ) ;
4738 } ) ;
4839} ) ;
4940
8172 } ) . toThrowError ( 'MOSOrderPositionFinder: Invalid section name.' ) ;
8273 } ) ;
8374} ) ;
75+
76+ describe ( 'getAllExistingSectionPositions(wikicode)' , ( ) => {
77+ test ( 'simple' , ( ) => {
78+ const mopf = new MOSOrderPositionFinder ( ) ;
79+ const wikicode =
80+ `{{Short description|test}}
81+
82+ Lead
83+
84+ == First heading ==
85+ Body
86+
87+ {{Navbox}}` ;
88+ const output = {
89+ top : 0 ,
90+ shortDescription : 0 ,
91+ lead : 28 ,
92+ body : 34 ,
93+ navboxes : 60 ,
94+ bottom : 70
95+ } ;
96+ expect ( mopf . getAllExistingSectionPositions ( wikicode ) ) . toStrictEqual ( output ) ;
97+ } ) ;
98+
99+ test ( 'bug involving putting HTML comments in the wrong place in AFC drafts' , ( ) => {
100+ const mopf = new MOSOrderPositionFinder ( ) ;
101+ const wikicode =
102+ `{{AfC Comment}}<!-- do not remove this line-->
103+
104+ Lead` ;
105+ const needle = '{{Speciesbox}}' ;
106+ const section = 'infoboxes' ;
107+ const output =
108+ `{{AfC Comment}}<!-- do not remove this line-->
109+
110+ {{Speciesbox}}
111+
112+ Lead` ;
113+ expect ( mopf . insertAtSection ( wikicode , needle , section ) ) . toStrictEqual ( output ) ;
114+ } ) ;
115+ } ) ;
0 commit comments