|
73 | 73 | } ); |
74 | 74 | } ); |
75 | 75 |
|
| 76 | +describe( 'insertAtSection(wikicode, needle, section)', () => { |
| 77 | + test( 'Section does not exist yet', () => { |
| 78 | + const mopf = new MOSOrderPositionFinder(); |
| 79 | + const wikicode = |
| 80 | +`{{Short description|test}} |
| 81 | +
|
| 82 | +Lead |
| 83 | +
|
| 84 | +== First heading == |
| 85 | +Body |
| 86 | +`; |
| 87 | + const needle = '{{Taxonbar}}'; |
| 88 | + const section = 'taxonBar'; |
| 89 | + const output = |
| 90 | +`{{Short description|test}} |
| 91 | +
|
| 92 | +Lead |
| 93 | +
|
| 94 | +== First heading == |
| 95 | +Body |
| 96 | +
|
| 97 | +{{Taxonbar}} |
| 98 | +`; |
| 99 | + expect( mopf.insertAtSection( wikicode, needle, section ) ).toBe( output ); |
| 100 | + } ); |
| 101 | + |
| 102 | + test( 'Section already exists', () => { |
| 103 | + const mopf = new MOSOrderPositionFinder(); |
| 104 | + const wikicode = |
| 105 | +`{{Short description|test}} |
| 106 | +{{Copy edit}} |
| 107 | +
|
| 108 | +Lead |
| 109 | +
|
| 110 | +== First heading == |
| 111 | +Body |
| 112 | +`; |
| 113 | + const needle = '{{Close paraphrasing}}'; |
| 114 | + const section = 'maintenanceTags'; |
| 115 | + const output = |
| 116 | +`{{Short description|test}} |
| 117 | +
|
| 118 | +{{Close paraphrasing}} |
| 119 | +{{Copy edit}} |
| 120 | +
|
| 121 | +Lead |
| 122 | +
|
| 123 | +== First heading == |
| 124 | +Body |
| 125 | +`; |
| 126 | + expect( mopf.insertAtSection( wikicode, needle, section ) ).toBe( output ); |
| 127 | + } ); |
| 128 | + |
| 129 | + test( 'Invalid section name throws error', () => { |
| 130 | + const mopf = new MOSOrderPositionFinder(); |
| 131 | + const wikicode = 'Test'; |
| 132 | + const needle = '{{test}}'; |
| 133 | + const section = 'invalidSection'; |
| 134 | + expect( () => { |
| 135 | + mopf.insertAtSection( wikicode, needle, section ); |
| 136 | + } ).toThrowError( 'MOSOrderPositionFinder: Invalid section name.' ); |
| 137 | + } ); |
| 138 | +} ); |
| 139 | + |
76 | 140 | describe( 'getAllExistingSectionPositions(wikicode)', () => { |
77 | 141 | test( 'simple', () => { |
78 | 142 | const mopf = new MOSOrderPositionFinder(); |
@@ -101,15 +165,17 @@ Body |
101 | 165 | const wikicode = |
102 | 166 | `{{AfC Comment}}<!-- do not remove this line--> |
103 | 167 |
|
104 | | -Lead`; |
| 168 | +Lead |
| 169 | +`; |
105 | 170 | const needle = '{{Speciesbox}}'; |
106 | 171 | const section = 'infoboxes'; |
107 | 172 | const output = |
108 | 173 | `{{AfC Comment}}<!-- do not remove this line--> |
109 | 174 |
|
110 | 175 | {{Speciesbox}} |
111 | 176 |
|
112 | | -Lead`; |
| 177 | +Lead |
| 178 | +`; |
113 | 179 | expect( mopf.insertAtSection( wikicode, needle, section ) ).toStrictEqual( output ); |
114 | 180 | } ); |
115 | 181 | } ); |
0 commit comments