import { formatBody , formatExpandable , formatRegionTag , formatViolations , formatMatchingViolation , } from '../src/utils' ; import { Violation } from '../src/violations' ; import { RegionTagLocation } from '../src/region-tag-parser' ; import assert from 'assert' ; import { describe , it } from 'mocha' ; const loc = { type : 'add' , regionTag : 'tag' , owner : 'owner' , repo : 'repo' , file : 'file' , sha : 'sha' , line : 42 , } ; describe ( 'formatBody' , ( ) => { const commentMark = '<!-- commentMark>' ; const originalBody = 'original body' ; const shouldBeTrimmed = 'should be trimmed' ; const addition = 'addition' ; it ( 'should format the body with the commentMark' , ( ) => { const result = formatBody ( `${ originalBody }${ commentMark }${ shouldBeTrimmed }` , commentMark , addition ) ; assert ( result . includes ( originalBody ) ) ; assert ( result . includes ( commentMark ) ) ; assert ( result . includes ( addition ) ) ; assert ( ! result . includes ( shouldBeTrimmed ) ) ; assert ( result . includes ( 'https://github.com/googleapis/repo-automation-bots/issues' ) ) ; } ) ; } ) ; describe ( 'formatExpandable' , ( ) => { it ( 'should format as an expandable component in the UI' , ( ) => { const result = formatExpandable ( 'summary' , 'detail' ) ; assert ( result . includes ( '<summary>summary</summary>' ) ) ; assert ( result . includes ( 'detail\n</details>' ) ) ; } ) ; } ) ; describe ( 'formatRegionTag' , ( ) => { it ( 'should format a RegionTagLocation with a link' , ( ) => { const result = formatRegionTag ( loc ) ; assert ( result . includes ( 'https://github.com/owner/repo/blob/sha/file#L42' ) ) ; assert ( result . includes ( '[file:42]' ) ) ; assert ( result . includes ( 'tag' ) ) ; } ) ; } ) ; describe ( 'formatViolations' , ( ) => { it ( 'should format an array of Violation' , ( ) => { const violations = new Array < Violation > ( ) ; violations . push ( { location : loc , violationType : 'REMOVE_USED_TAG' , devsite_urls : [ 'https://example.com/example.html' ] , } ) ; const result = formatViolations ( violations , 'summary of violations' ) ; assert ( result . includes ( 'summary of violations' ) ) ; assert ( result . includes ( 'https://example.com/example.html' ) ) ; } ) ; } ) ; describe ( 'formatMatchingViolation' , ( ) => { it ( 'should report not having a matching start tag' , ( ) => { const violation = { location : loc , violationType : 'NO_MATCHING_START_TAG' , devsite_urls : [ 'https://example.com/example.html' ] , } ; const result = formatMatchingViolation ( violation ) ; assert ( result . includes ( "doesn't have a matching start tag." ) ) ; } ) ; it ( 'should report not having a matching end tag' , ( ) => { const violation = { location : loc , violationType : 'NO_MATCHING_END_TAG' , devsite_urls : [ 'https://example.com/example.html' ] , } ; const result = formatMatchingViolation ( violation ) ; assert ( result . includes ( "doesn't have a matching end tag." ) ) ; } ) ; it ( 'should report the tag is already started' , ( ) => { const violation = { location : loc , violationType : 'TAG_ALREADY_STARTED' , devsite_urls : [ 'https://example.com/example.html' ] , } ; const result = formatMatchingViolation ( violation ) ; assert ( result . includes ( 'already started.' ) ) ; } ) ; } ) ;