| 
									
										
										
										
											2021-08-02 15:39:40 +02:00
										 |  |  | const { | 
					
						
							|  |  |  |   ENGLISH_CHALLENGE_NO_FILES | 
					
						
							|  |  |  | } = require('./__fixtures__/challenge-objects'); | 
					
						
							|  |  |  | const { SIMPLE_TRANSLATION } = require('./__mocks__/mock-comments'); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  | const { | 
					
						
							|  |  |  |   translateComments, | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |   translateCommentsInChallenge, | 
					
						
							|  |  |  |   translateGeneric | 
					
						
							| 
									
										
										
										
											2021-02-03 10:46:27 +01:00
										 |  |  | } = require('.'); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | let logSpy; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('translation parser', () => { | 
					
						
							|  |  |  |   beforeEach(() => { | 
					
						
							|  |  |  |     logSpy = jest.spyOn(console, 'warn').mockImplementation(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   afterEach(() => { | 
					
						
							|  |  |  |     logSpy.mockRestore(); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-10-01 15:50:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |   describe('translateGeneric', () => { | 
					
						
							|  |  |  |     it('returns an object containing translated text', () => { | 
					
						
							|  |  |  |       expect.assertions(1); | 
					
						
							|  |  |  |       const seed = `//  Add your code below this line
 | 
					
						
							|  |  |  |       Add your code above this line `;
 | 
					
						
							|  |  |  |       const transSeed = `//  (Chinese) Add your code below this line (Chinese)
 | 
					
						
							|  |  |  |       Add your code above this line `;
 | 
					
						
							|  |  |  |       const knownComments = Object.keys(SIMPLE_TRANSLATION); | 
					
						
							|  |  |  |       const config = { | 
					
						
							|  |  |  |         knownComments, | 
					
						
							|  |  |  |         dict: SIMPLE_TRANSLATION, | 
					
						
							|  |  |  |         lang: 'chinese' | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |       const actual = translateGeneric( | 
					
						
							|  |  |  |         { text: seed, commentCounts: new Map() }, | 
					
						
							|  |  |  |         config, | 
					
						
							|  |  |  |         '((?<!https?:)//\\s*)', | 
					
						
							|  |  |  |         '(\\s*$)' | 
					
						
							| 
									
										
										
										
											2020-03-05 14:03:01 +01:00
										 |  |  |       ); | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |       expect(actual.text).toBe(transSeed); | 
					
						
							| 
									
										
										
										
											2020-03-05 14:03:01 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |     it('returns an object containing a count of the replaced comments', () => { | 
					
						
							|  |  |  |       expect.assertions(1); | 
					
						
							|  |  |  |       const seed = `//  Add your code below this line
 | 
					
						
							|  |  |  |       // Add your code above this line
 | 
					
						
							|  |  |  |       // Add your code below this line
 | 
					
						
							|  |  |  |       `;
 | 
					
						
							|  |  |  |       const expectedCommentCounts = new Map(); | 
					
						
							|  |  |  |       expectedCommentCounts | 
					
						
							|  |  |  |         .set('(Chinese) Add your code below this line (Chinese)', 2) | 
					
						
							|  |  |  |         .set('(Chinese) Add your code above this line (Chinese)', 1); | 
					
						
							|  |  |  |       const knownComments = Object.keys(SIMPLE_TRANSLATION); | 
					
						
							|  |  |  |       const config = { | 
					
						
							|  |  |  |         knownComments, | 
					
						
							|  |  |  |         dict: SIMPLE_TRANSLATION, | 
					
						
							|  |  |  |         lang: 'chinese' | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |       const actual = translateGeneric( | 
					
						
							|  |  |  |         { text: seed, commentCounts: new Map() }, | 
					
						
							|  |  |  |         config, | 
					
						
							|  |  |  |         '((?<!https?:)//\\s*)', | 
					
						
							|  |  |  |         '(\\s*$)' | 
					
						
							| 
									
										
										
										
											2020-08-13 12:25:53 +02:00
										 |  |  |       ); | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |       expect(actual.commentCounts).toEqual(expectedCommentCounts); | 
					
						
							| 
									
										
										
										
											2020-08-13 12:25:53 +02:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('translateCommentsInChallenge', () => { | 
					
						
							|  |  |  |     it('returns a clone of the challenge if there are no comments', () => { | 
					
						
							|  |  |  |       expect( | 
					
						
							|  |  |  |         translateCommentsInChallenge( | 
					
						
							|  |  |  |           ENGLISH_CHALLENGE_NO_FILES, | 
					
						
							|  |  |  |           'chinese', | 
					
						
							|  |  |  |           SIMPLE_TRANSLATION | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       ).toEqual(ENGLISH_CHALLENGE_NO_FILES); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   describe('translateComments', () => { | 
					
						
							|  |  |  |     it('replaces single line English comments with their translations', () => { | 
					
						
							|  |  |  |       const seed = `//  Add your code below this line
 | 
					
						
							|  |  |  |          Add your code above this line `;
 | 
					
						
							|  |  |  |       const transSeed = `//  (Chinese) Add your code below this line (Chinese)
 | 
					
						
							|  |  |  |          Add your code above this line `;
 | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |       expect( | 
					
						
							|  |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'js').text | 
					
						
							|  |  |  |       ).toBe(transSeed); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-24 15:05:18 +01:00
										 |  |  |     it('does not translate urls', () => { | 
					
						
							|  |  |  |       const seed = `http:// Add your code below this line
 | 
					
						
							|  |  |  |       Add your code above this line `;
 | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |       expect( | 
					
						
							|  |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'js').text | 
					
						
							|  |  |  |       ).toBe(seed); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:05:18 +01:00
										 |  |  |       const seedS = `https:// Add your code below this line
 | 
					
						
							|  |  |  |       Add your code above this line `;
 | 
					
						
							|  |  |  |       expect( | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |         translateComments(seedS, 'chinese', SIMPLE_TRANSLATION, 'js').text | 
					
						
							| 
									
										
										
										
											2020-02-24 15:05:18 +01:00
										 |  |  |       ).toBe(seedS); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     it('replaces inline English comments with their translations', () => { | 
					
						
							|  |  |  |       const seed = `inline comment //  Add your code below this line
 | 
					
						
							|  |  |  |          Add your code above this line `;
 | 
					
						
							|  |  |  |       const transSeed = `inline comment //  (Chinese) Add your code below this line (Chinese)
 | 
					
						
							|  |  |  |          Add your code above this line `;
 | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |       expect( | 
					
						
							|  |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'js').text | 
					
						
							|  |  |  |       ).toBe(transSeed); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('replaces multiple English comments with their translations', () => { | 
					
						
							|  |  |  |       const seed = `inline comment //  Add your code below this line
 | 
					
						
							|  |  |  |          // Add your code below this line `;
 | 
					
						
							|  |  |  |       const transSeed = `inline comment //  (Chinese) Add your code below this line (Chinese)
 | 
					
						
							|  |  |  |          // (Chinese) Add your code below this line (Chinese) `;
 | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |       expect( | 
					
						
							|  |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'js').text | 
					
						
							|  |  |  |       ).toBe(transSeed); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('replaces multiline English comments with their translations', () => { | 
					
						
							|  |  |  |       const seed = `multiline comment /*  Add your code below this line */
 | 
					
						
							|  |  |  |          /* Add your code above this line */ change code below this line  `;
 | 
					
						
							|  |  |  |       const transSeed = `multiline comment /*  (Chinese) Add your code below this line (Chinese) */
 | 
					
						
							|  |  |  |          /* (Chinese) Add your code above this line (Chinese) */ change code below this line  `;
 | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |       expect( | 
					
						
							|  |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'js').text | 
					
						
							|  |  |  |       ).toBe(transSeed); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('replaces repeated multiline comments with their translations', () => { | 
					
						
							|  |  |  |       const seed = `multiline comment /*  Add your code below this line */
 | 
					
						
							|  |  |  |          /* Add your code below this line */ change code below this line  `;
 | 
					
						
							|  |  |  |       const transSeed = `multiline comment /*  (Chinese) Add your code below this line (Chinese) */
 | 
					
						
							|  |  |  |          /* (Chinese) Add your code below this line (Chinese) */ change code below this line  `;
 | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |       expect( | 
					
						
							|  |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'js').text | 
					
						
							|  |  |  |       ).toBe(transSeed); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |     it('ignores empty comments', () => { | 
					
						
							|  |  |  |       expect.assertions(1); | 
					
						
							|  |  |  |       const seed = '//'; | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |       expect( | 
					
						
							|  |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'js').text | 
					
						
							|  |  |  |       ).toBe(seed); | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     it('only replaces text inside comments, not between them', () => { | 
					
						
							|  |  |  |       const seed = `multiline comment /*  Add your code below this line */
 | 
					
						
							|  |  |  |          /* Add your code above this line */ Add your code below this line /* */  `;
 | 
					
						
							|  |  |  |       const transSeed = `multiline comment /*  (Chinese) Add your code below this line (Chinese) */
 | 
					
						
							|  |  |  |          /* (Chinese) Add your code above this line (Chinese) */ Add your code below this line /* */  `;
 | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |       expect( | 
					
						
							|  |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'js').text | 
					
						
							|  |  |  |       ).toBe(transSeed); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const seedTwo = `multiline /* */  Add your code below this line /* */  `; | 
					
						
							|  |  |  |       expect( | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |         translateComments(seedTwo, 'chinese', SIMPLE_TRANSLATION, 'js').text | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       ).toBe(seedTwo); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('replaces English html comments with their translations', () => { | 
					
						
							|  |  |  |       const seed = `<div> <!--  Add your code below this line -->
 | 
					
						
							|  |  |  |          <!-- Add your code above this line --> <span>change code below this line</span>  `; | 
					
						
							|  |  |  |       const transSeed = `<div> <!--  (Chinese) Add your code below this line (Chinese) -->
 | 
					
						
							|  |  |  |          <!-- (Chinese) Add your code above this line (Chinese) --> <span>change code below this line</span>  `; | 
					
						
							|  |  |  |       expect( | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'html').text | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       ).toBe(transSeed); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('replaces css comments with their translations', () => { | 
					
						
							|  |  |  |       const seed = `<style>
 | 
					
						
							|  |  |  |         /* Add your code below this line */ | 
					
						
							|  |  |  |       </style>`; | 
					
						
							|  |  |  |       const transSeed = `<style>
 | 
					
						
							|  |  |  |         /* (Chinese) Add your code below this line (Chinese) */ | 
					
						
							|  |  |  |       </style>`; | 
					
						
							|  |  |  |       expect( | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'html').text | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       ).toBe(transSeed); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('replaces multiple css comments with their translations', () => { | 
					
						
							|  |  |  |       const seed = `<style>
 | 
					
						
							|  |  |  |         /* Add your code below this line */ | 
					
						
							|  |  |  |         /* Add your code below this line */ | 
					
						
							|  |  |  |       </style>`; | 
					
						
							|  |  |  |       const transSeed = `<style>
 | 
					
						
							|  |  |  |         /* (Chinese) Add your code below this line (Chinese) */ | 
					
						
							|  |  |  |         /* (Chinese) Add your code below this line (Chinese) */ | 
					
						
							|  |  |  |       </style>`; | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |       const commentCounts = new Map(); | 
					
						
							|  |  |  |       commentCounts.set('(Chinese) Add your code below this line (Chinese)', 2); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       expect( | 
					
						
							|  |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'html') | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |       ).toEqual({ text: transSeed, commentCounts }); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('ignores css comments outside style tags', () => { | 
					
						
							|  |  |  |       const seed = `/* Add your code below this line */`; | 
					
						
							|  |  |  |       expect( | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'html').text | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       ).toBe(seed); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('ignores css comments between style tags', () => { | 
					
						
							|  |  |  |       const seed = `<style>
 | 
					
						
							|  |  |  |       </style> | 
					
						
							|  |  |  |       /* Add your code below this line */ | 
					
						
							|  |  |  |       <style> | 
					
						
							|  |  |  |       </style>`; | 
					
						
							|  |  |  |       expect( | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'html').text | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       ).toBe(seed); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('only replaces inside English html comments', () => { | 
					
						
							|  |  |  |       const seed = `<div> <!-- -->  Add your code below this line <!-- -->`; | 
					
						
							|  |  |  |       expect( | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'html').text | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       ).toBe(seed); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('replaces English JSX comments with their translations', () => { | 
					
						
							|  |  |  |       const seed = `{ /*  Add your code below this line */ }
 | 
					
						
							|  |  |  |       { /* Add your code above this line */ } <span>change code below this line</span>  `; | 
					
						
							|  |  |  |       const transSeed = `{ /*  (Chinese) Add your code below this line (Chinese) */ }
 | 
					
						
							|  |  |  |       { /* (Chinese) Add your code above this line (Chinese) */ } <span>change code below this line</span>  `; | 
					
						
							|  |  |  |       expect( | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'jsx').text | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       ).toBe(transSeed); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-28 15:13:18 +02:00
										 |  |  |     it('replaces English script comments with their translations', () => { | 
					
						
							|  |  |  |       const seed = `<script>
 | 
					
						
							|  |  |  |         // Add your code below this line
 | 
					
						
							|  |  |  |       </script>`; | 
					
						
							|  |  |  |       const transSeed = `<script>
 | 
					
						
							|  |  |  |         // (Chinese) Add your code below this line (Chinese)
 | 
					
						
							|  |  |  |       </script>`; | 
					
						
							|  |  |  |       expect( | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'html').text | 
					
						
							| 
									
										
										
										
											2020-09-28 15:13:18 +02:00
										 |  |  |       ).toBe(transSeed); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('replaces multiple script comments with their translations', () => { | 
					
						
							|  |  |  |       const seed = `<script>
 | 
					
						
							|  |  |  |         /* Add your code below this line */ | 
					
						
							|  |  |  |         // Add your code below this line
 | 
					
						
							|  |  |  |       </script>`; | 
					
						
							|  |  |  |       const transSeed = `<script>
 | 
					
						
							|  |  |  |         /* (Chinese) Add your code below this line (Chinese) */ | 
					
						
							|  |  |  |         // (Chinese) Add your code below this line (Chinese)
 | 
					
						
							|  |  |  |       </script>`; | 
					
						
							|  |  |  |       expect( | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'html').text | 
					
						
							| 
									
										
										
										
											2020-09-28 15:13:18 +02:00
										 |  |  |       ).toBe(transSeed); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     it('ignores html comments inside JavaScript', () => { | 
					
						
							|  |  |  |       const seed = `<div> <!--  Add your code below this line
 | 
					
						
							|  |  |  |          Add your code above this line --> <span>change code below this line</span>  `; | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |       expect( | 
					
						
							|  |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'js').text | 
					
						
							|  |  |  |       ).toBe(seed); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('ignores html comments inside jsx', () => { | 
					
						
							|  |  |  |       const seed = `<div> <!--  Add your code below this line
 | 
					
						
							|  |  |  |          Add your code above this line --> <span>change code below this line</span>  `; | 
					
						
							|  |  |  |       expect( | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'jsx').text | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       ).toBe(seed); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |     it('throws if there is not an exact match (js)', () => { | 
					
						
							|  |  |  |       expect.assertions(2); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       const seedMulti = `/*  Add your code below this line
 | 
					
						
							|  |  |  |       Add your code above this line */ <span>change code below this line</span>  `; | 
					
						
							|  |  |  |       const seedInline = `// Add your code below this line, please`; | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |       expect(() => | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |         translateComments(seedMulti, 'chinese', SIMPLE_TRANSLATION, 'js') | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |       ).toThrow(); | 
					
						
							|  |  |  |       expect(() => | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |         translateComments(seedInline, 'chinese', SIMPLE_TRANSLATION, 'js') | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |       ).toThrow(); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('only replaces exact matches (jsx)', () => { | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |       expect.assertions(1); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       const seedMulti = `{ /*  Add your code below this line
 | 
					
						
							|  |  |  |       Add your code above this line */ } <span>change code below this line</span>  `; | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |       expect(() => | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |         translateComments(seedMulti, 'chinese', SIMPLE_TRANSLATION, 'jsx') | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |       ).toThrow(); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('only replaces exact matches (html)', () => { | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |       expect.assertions(1); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       const seed = `<div> <!--  Add your code below this line
 | 
					
						
							|  |  |  |        Add your code above this line --> <span>change code below this line</span>  `; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |       expect(() => | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'html') | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |       ).toThrow(); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('only translates jsx comments once', () => { | 
					
						
							|  |  |  |       const seed = `{ /*  Add your code below this line */ }`; | 
					
						
							|  |  |  |       const transSeed = `{ /*  (Chinese) Add your code below this line (Chinese) */ }`; | 
					
						
							|  |  |  |       expect( | 
					
						
							| 
									
										
										
										
											2021-03-20 07:29:13 +01:00
										 |  |  |         translateComments(seed, 'chinese', SIMPLE_TRANSLATION, 'jsx').text | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       ).toBe(transSeed); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |     it('throws if the comment is not in the dictionary', () => { | 
					
						
							|  |  |  |       expect.assertions(6); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |       const seedJSX = `{ /* this is not a comment */ }`; | 
					
						
							|  |  |  |       const seedInline = `// this is not a comment `; | 
					
						
							|  |  |  |       const seedMulti = `/* this is not a comment */`; | 
					
						
							|  |  |  |       const seedCSS = `<style>
 | 
					
						
							|  |  |  |       /* this is not a comment */ | 
					
						
							|  |  |  |     </style>`; | 
					
						
							|  |  |  |       const seedHTML = `<div> <!--  this is not a comment --> `; | 
					
						
							| 
									
										
										
										
											2020-09-28 15:13:18 +02:00
										 |  |  |       const seedScript = `<script> // this is not a comment </script>`; | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-03 10:43:32 +01:00
										 |  |  |       expect(() => | 
					
						
							|  |  |  |         translateComments(seedJSX, 'chinese', SIMPLE_TRANSLATION, 'jsx') | 
					
						
							|  |  |  |       ).toThrow(); | 
					
						
							|  |  |  |       expect(() => | 
					
						
							|  |  |  |         translateComments(seedInline, 'chinese', SIMPLE_TRANSLATION, 'js') | 
					
						
							|  |  |  |       ).toThrow(); | 
					
						
							|  |  |  |       expect(() => | 
					
						
							|  |  |  |         translateComments(seedMulti, 'chinese', SIMPLE_TRANSLATION, 'js') | 
					
						
							|  |  |  |       ).toThrow(); | 
					
						
							|  |  |  |       expect(() => | 
					
						
							|  |  |  |         translateComments(seedCSS, 'chinese', SIMPLE_TRANSLATION, 'html') | 
					
						
							|  |  |  |       ).toThrow(); | 
					
						
							|  |  |  |       expect(() => | 
					
						
							|  |  |  |         translateComments(seedHTML, 'chinese', SIMPLE_TRANSLATION, 'html') | 
					
						
							|  |  |  |       ).toThrow(); | 
					
						
							|  |  |  |       expect(() => | 
					
						
							|  |  |  |         translateComments(seedScript, 'chinese', SIMPLE_TRANSLATION, 'html') | 
					
						
							|  |  |  |       ).toThrow(); | 
					
						
							| 
									
										
										
										
											2020-02-24 15:03:21 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |