Skip to content

Commit

Permalink
Add tests for HtmlGanttDiagramReporter
Browse files Browse the repository at this point in the history
  • Loading branch information
platan committed Nov 1, 2023
1 parent 6c540c0 commit 4e7ebc3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data class HtmlConfig(override val enabled: Boolean, override val outputLocation
private const val DEFAULT_MERMAID_SCRIPT_SRC =
"https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js"

@JvmStatic
fun getSrcDefault(): String = DEFAULT_MERMAID_SCRIPT_SRC
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.github.platan.tests_execution_chart.reporters.html

import io.github.platan.tests_execution_chart.report.TestExecutionScheduleReportBuilder
import spock.lang.Specification
import spock.lang.Subject
import spock.lang.TempDir

class HtmlGanttDiagramReporterTest extends Specification {

@Subject
def htmlGanttDiagramReporter = new HtmlGanttDiagramReporter()
def configOutputLocation = "my-output-location"

def setup() {
htmlGanttDiagramReporter.setLogger { println(it) }
}

@TempDir
File baseDir

def "should embed script file"() {
given:
def script = new HtmlConfig.Script(HtmlConfig.Script.getSrcDefault(), true, new HtmlConfig.Script.Options(10_000))
htmlGanttDiagramReporter.setConfiguration(new HtmlConfig(true, configOutputLocation, script))
def report = new TestExecutionScheduleReportBuilder().build()

when:
htmlGanttDiagramReporter.report(report, baseDir, 'my-task')

then:
def reportContent = new File(baseDir, "$configOutputLocation/my-task.html").text
reportContent.contains '<script src="mermaid.min.js"></script>'
}

def "should not embed script file"() {
given:
def scriptSource = HtmlConfig.Script.getSrcDefault()
def script = new HtmlConfig.Script(scriptSource, false, new HtmlConfig.Script.Options(10_000))
htmlGanttDiagramReporter.setConfiguration(new HtmlConfig(true, configOutputLocation, script))
def report = new TestExecutionScheduleReportBuilder().build()

when:
htmlGanttDiagramReporter.report(report, baseDir, 'my-task')

then:
def reportContent = new File(baseDir, "$configOutputLocation/my-task.html").text
reportContent.contains """<script src="$scriptSource"></script>"""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class JsonReporterTest extends Specification {

def "should generate report in json"() {
given:
def configOutputLocation = "reports/tests-execution/json"
def configOutputLocation = "my-output-location"
def report = new TestExecutionScheduleReport([
new TimedTestResult('class', 'test', toEpochMilli('2023-03-10T19:00:02Z'), toEpochMilli('2023-03-10T19:00:05Z'), 'passed', TEST)
], [new Mark('mark1', toEpochMilli('2023-03-10T19:00:05Z'))])
Expand Down

0 comments on commit 4e7ebc3

Please sign in to comment.