@@ -9,7 +9,8 @@ import {CodeAnalyzerConfigFactory} from "../../../src/lib/factories/CodeAnalyzer
99import { EnginePluginsFactory } from '../../../src/lib/factories/EnginePluginsFactory' ;
1010import { ConfigAction , ConfigDependencies , ConfigInput } from '../../../src/lib/actions/ConfigAction' ;
1111import { AnnotatedConfigModel } from '../../../src/lib/models/ConfigModel' ;
12- import { ConfigStyledYamlViewer } from '../../../lib/lib/viewers/ConfigViewer' ;
12+ import { ConfigStyledYamlViewer } from '../../../src/lib/viewers/ConfigViewer' ;
13+ import { ConfigActionSummaryViewer } from '../../../src/lib/viewers/ActionSummaryViewer' ;
1314
1415import { SpyConfigWriter } from '../../stubs/SpyConfigWriter' ;
1516import { DisplayEventType , SpyDisplay } from '../../stubs/SpyDisplay' ;
@@ -36,6 +37,7 @@ describe('ConfigAction tests', () => {
3637 viewer : new ConfigStyledYamlViewer ( spyDisplay ) ,
3738 configFactory : new DefaultStubCodeAnalyzerConfigFactory ( ) ,
3839 modelGenerator : AnnotatedConfigModel . fromSelection ,
40+ actionSummaryViewer : new ConfigActionSummaryViewer ( spyDisplay ) ,
3941 pluginsFactory : new StubEnginePluginFactory ( )
4042 } ;
4143 } ) ;
@@ -159,6 +161,7 @@ describe('ConfigAction tests', () => {
159161 viewer : new ConfigStyledYamlViewer ( spyDisplay ) ,
160162 configFactory : stubConfigFactory ,
161163 modelGenerator : AnnotatedConfigModel . fromSelection ,
164+ actionSummaryViewer : new ConfigActionSummaryViewer ( spyDisplay ) ,
162165 pluginsFactory : new StubEnginePluginFactory ( )
163166 } ;
164167 } ) ;
@@ -389,6 +392,7 @@ describe('ConfigAction tests', () => {
389392 viewer : new ConfigStyledYamlViewer ( spyDisplay ) ,
390393 configFactory : new DefaultStubCodeAnalyzerConfigFactory ( ) ,
391394 modelGenerator : AnnotatedConfigModel . fromSelection ,
395+ actionSummaryViewer : new ConfigActionSummaryViewer ( spyDisplay ) ,
392396 pluginsFactory : new StubEnginePluginFactory ( )
393397 } ;
394398 } ) ;
@@ -406,6 +410,74 @@ describe('ConfigAction tests', () => {
406410 expect ( spyWriter . getCallHistory ( ) ) . toHaveLength ( 1 ) ;
407411 } ) ;
408412 } ) ;
413+
414+ describe ( 'Summary generation' , ( ) => {
415+ beforeEach ( ( ) => {
416+ spyDisplay = new SpyDisplay ( ) ;
417+ dependencies = {
418+ logEventListeners : [ ] ,
419+ progressEventListeners : [ ] ,
420+ viewer : new ConfigStyledYamlViewer ( spyDisplay ) ,
421+ configFactory : new DefaultStubCodeAnalyzerConfigFactory ( ) ,
422+ modelGenerator : AnnotatedConfigModel . fromSelection ,
423+ actionSummaryViewer : new ConfigActionSummaryViewer ( spyDisplay ) ,
424+ pluginsFactory : new StubEnginePluginFactory ( )
425+ }
426+ } ) ;
427+
428+ it ( 'When an Outfile is created, it is mentioned by the Summarizer' , async ( ) => {
429+ // ==== SETUP ====
430+ // Assign a Writer to the dependencies.
431+ dependencies . writer = new SpyConfigWriter ( true ) ;
432+
433+ // ==== TESTED BEHAVIOR ====
434+ // Invoke the action, specifying an outfile.
435+ const action = ConfigAction . createAction ( dependencies ) ;
436+ const input : ConfigInput = {
437+ 'rule-selector' : [ 'all' ] ,
438+ 'output-file' : 'out-config.yml'
439+ } ;
440+ await action . execute ( input ) ;
441+
442+ // ==== ASSERTIONS ====
443+ const displayEvents = spyDisplay . getDisplayEvents ( ) ;
444+ const displayedLogEvents = ansis . strip ( displayEvents
445+ . filter ( e => e . type === DisplayEventType . LOG )
446+ . map ( e => e . data )
447+ . join ( '\n' ) ) ;
448+
449+ const goldfileContents : string = await readGoldFile ( path . join ( PATH_TO_COMPARISON_DIR , 'action-summaries' , 'outfile-created.txt.goldfile' ) ) ;
450+ expect ( displayedLogEvents ) . toContain ( goldfileContents ) ;
451+ } ) ;
452+
453+ it . each ( [
454+ { case : 'an Outfile is specified but not written' , writer : new SpyConfigWriter ( false ) , outfile : 'out-config.yml' } ,
455+ { case : 'an Outfile is not specified at all' , writer : undefined , outfile : undefined }
456+ ] ) ( 'When $case, the Summarizer mentions no outfile' , async ( { writer, outfile} ) => {
457+ // ==== SETUP ====
458+ // Add the specified Writer (or lack-of-Writer) to the dependencies.
459+ dependencies . writer = writer ;
460+
461+ // ==== TESTED BEHAVIOR ====
462+ // Invoke the action, specifying an outfile (or lack of one).
463+ const action = ConfigAction . createAction ( dependencies ) ;
464+ const input : ConfigInput = {
465+ 'rule-selector' : [ 'all' ] ,
466+ 'output-file' : outfile
467+ } ;
468+ await action . execute ( input ) ;
469+
470+ // ==== ASSERTIONS ====
471+ const displayEvents = spyDisplay . getDisplayEvents ( ) ;
472+ const displayedLogEvents = ansis . strip ( displayEvents
473+ . filter ( e => e . type === DisplayEventType . LOG )
474+ . map ( e => e . data )
475+ . join ( '\n' ) ) ;
476+
477+ const goldfileContents : string = await readGoldFile ( path . join ( PATH_TO_COMPARISON_DIR , 'action-summaries' , 'no-outfile-created.txt.goldfile' ) ) ;
478+ expect ( displayedLogEvents ) . toContain ( goldfileContents ) ;
479+ } ) ;
480+ } )
409481 // ====== HELPER FUNCTIONS ======
410482
411483 async function readGoldFile ( goldFilePath : string ) : Promise < string > {
@@ -425,7 +497,6 @@ describe('ConfigAction tests', () => {
425497
426498 // ==== OUTPUT PROCESSING ====
427499 const displayEvents = spyDisplay . getDisplayEvents ( ) ;
428- expect ( displayEvents ) . toHaveLength ( 1 ) ;
429500 expect ( displayEvents [ 0 ] . type ) . toEqual ( DisplayEventType . LOG ) ;
430501 return ansis . strip ( displayEvents [ 0 ] . data ) ;
431502 }
0 commit comments