1- import { render } from '../file-list-renderer' ;
1+ import { FileListRenderer } from '../file-list-renderer' ;
22import HoganJsUtils from '../hoganjs-utils' ;
3+ import { ColorSchemeType } from '../types' ;
34
4- describe ( 'FileListPrinter ' , ( ) => {
5- describe ( 'generateFileList ' , ( ) => {
5+ describe ( 'FileListRenderer ' , ( ) => {
6+ describe ( 'render ' , ( ) => {
67 it ( 'should expose old and new files to templates' , ( ) => {
78 const hoganUtils = new HoganJsUtils ( {
89 rawTemplates : {
910 'file-summary-wrapper' : '{{{files}}}' ,
1011 'file-summary-line' : '{{oldName}}, {{newName}}, {{fileName}}' ,
1112 } ,
1213 } ) ;
14+ const fileListRenderer = new FileListRenderer ( hoganUtils ) ;
1315 const files = [
1416 {
1517 isCombined : false ,
@@ -55,7 +57,7 @@ describe('FileListPrinter', () => {
5557 } ,
5658 ] ;
5759
58- const fileHtml = render ( files , hoganUtils ) ;
60+ const fileHtml = fileListRenderer . render ( files ) ;
5961
6062 expect ( fileHtml ) . toMatchInlineSnapshot ( `
6163 "my/file/name.js, my/file/name.js, my/file/name.js
@@ -67,6 +69,8 @@ describe('FileListPrinter', () => {
6769
6870 it ( 'should work for all kinds of files' , ( ) => {
6971 const hoganUtils = new HoganJsUtils ( { } ) ;
72+ const fileListRenderer = new FileListRenderer ( hoganUtils ) ;
73+
7074 const files = [
7175 {
7276 isCombined : false ,
@@ -111,9 +115,9 @@ describe('FileListPrinter', () => {
111115 isDeleted : true ,
112116 } ,
113117 ] ;
114- const fileHtml = render ( files , hoganUtils ) ;
118+ const fileHtml = fileListRenderer . render ( files ) ;
115119 expect ( fileHtml ) . toMatchInlineSnapshot ( `
116- "<div class="d2h-file-list-wrapper">
120+ "<div class="d2h-file-list-wrapper d2h-light-color-scheme ">
117121 <div class="d2h-file-list-header">
118122 <span class="d2h-file-list-title">Files changed (4)</span>
119123 <a class="d2h-file-switch d2h-hide">hide</a>
@@ -172,5 +176,97 @@ describe('FileListPrinter', () => {
172176 </div>"
173177 ` ) ;
174178 } ) ;
179+
180+ describe ( 'with dark colorScheme' , ( ) => {
181+ it ( 'should include dark colorScheme' , ( ) => {
182+ const hoganUtils = new HoganJsUtils ( { } ) ;
183+ const fileListRenderer = new FileListRenderer ( hoganUtils , {
184+ colorScheme : ColorSchemeType . DARK ,
185+ } ) ;
186+
187+ const files = [
188+ {
189+ isCombined : false ,
190+ isGitDiff : false ,
191+ blocks : [ ] ,
192+ addedLines : 12 ,
193+ deletedLines : 41 ,
194+ language : 'js' ,
195+ oldName : 'my/file/name.js' ,
196+ newName : 'my/file/name.js' ,
197+ } ,
198+ ] ;
199+ const fileHtml = fileListRenderer . render ( files ) ;
200+ expect ( fileHtml ) . toMatchInlineSnapshot ( `
201+ "<div class="d2h-file-list-wrapper d2h-dark-color-scheme">
202+ <div class="d2h-file-list-header">
203+ <span class="d2h-file-list-title">Files changed (1)</span>
204+ <a class="d2h-file-switch d2h-hide">hide</a>
205+ <a class="d2h-file-switch d2h-show">show</a>
206+ </div>
207+ <ol class="d2h-file-list">
208+ <li class="d2h-file-list-line">
209+ <span class="d2h-file-name-wrapper">
210+ <svg aria-hidden="true" class="d2h-icon d2h-changed" height="16" title="modified" version="1.1"
211+ viewBox="0 0 14 16" width="14">
212+ <path d="M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM4 8c0-1.66 1.34-3 3-3s3 1.34 3 3-1.34 3-3 3-3-1.34-3-3z"></path>
213+ </svg> <a href="#d2h-781444" class="d2h-file-name">my/file/name.js</a>
214+ <span class="d2h-file-stats">
215+ <span class="d2h-lines-added">+12</span>
216+ <span class="d2h-lines-deleted">-41</span>
217+ </span>
218+ </span>
219+ </li>
220+ </ol>
221+ </div>"
222+ ` ) ;
223+ } ) ;
224+ } ) ;
225+
226+ describe ( 'with auto colorScheme' , ( ) => {
227+ it ( 'should include auto colorScheme' , ( ) => {
228+ const hoganUtils = new HoganJsUtils ( { } ) ;
229+ const fileListRenderer = new FileListRenderer ( hoganUtils , {
230+ colorScheme : ColorSchemeType . AUTO ,
231+ } ) ;
232+
233+ const files = [
234+ {
235+ isCombined : false ,
236+ isGitDiff : false ,
237+ blocks : [ ] ,
238+ addedLines : 12 ,
239+ deletedLines : 41 ,
240+ language : 'js' ,
241+ oldName : 'my/file/name.js' ,
242+ newName : 'my/file/name.js' ,
243+ } ,
244+ ] ;
245+ const fileHtml = fileListRenderer . render ( files ) ;
246+ expect ( fileHtml ) . toMatchInlineSnapshot ( `
247+ "<div class="d2h-file-list-wrapper d2h-auto-color-scheme">
248+ <div class="d2h-file-list-header">
249+ <span class="d2h-file-list-title">Files changed (1)</span>
250+ <a class="d2h-file-switch d2h-hide">hide</a>
251+ <a class="d2h-file-switch d2h-show">show</a>
252+ </div>
253+ <ol class="d2h-file-list">
254+ <li class="d2h-file-list-line">
255+ <span class="d2h-file-name-wrapper">
256+ <svg aria-hidden="true" class="d2h-icon d2h-changed" height="16" title="modified" version="1.1"
257+ viewBox="0 0 14 16" width="14">
258+ <path d="M13 1H1C0.45 1 0 1.45 0 2v12c0 0.55 0.45 1 1 1h12c0.55 0 1-0.45 1-1V2c0-0.55-0.45-1-1-1z m0 13H1V2h12v12zM4 8c0-1.66 1.34-3 3-3s3 1.34 3 3-1.34 3-3 3-3-1.34-3-3z"></path>
259+ </svg> <a href="#d2h-781444" class="d2h-file-name">my/file/name.js</a>
260+ <span class="d2h-file-stats">
261+ <span class="d2h-lines-added">+12</span>
262+ <span class="d2h-lines-deleted">-41</span>
263+ </span>
264+ </span>
265+ </li>
266+ </ol>
267+ </div>"
268+ ` ) ;
269+ } ) ;
270+ } ) ;
175271 } ) ;
176272} ) ;
0 commit comments