io.github.frikit.twirlspec

Members list

Type members

Classlikes

Every rule module and the message-file matchers, in one mixin.

Every rule module and the message-file matchers, in one mixin.

trait ViewSpecBase extends AnyWordSpec with Matchers with TwirlSpec with AllChecks

Mix the modules in individually instead when a project wants some and not others — a project not using the GOV.UK Design System has no use for io.github.frikit.twirlspec.govuk.GovukChecks.

Attributes

Source
AllChecks.scala
Supertypes
trait I18nChecks
trait HtmlChecks
trait AriaChecks
trait GovukChecks
trait WcagChecks
trait TwirlSpecDsl
class Object
trait Matchable
class Any
Show all
Known subtypes

AllChecks for a GOV.UK transactional service: every rule, less the ones about search results, and with the platform's own head script left alone.

AllChecks for a GOV.UK transactional service: every rule, less the ones about search results, and with the platform's own head script left alone.

trait ViewSpecBase extends AnyWordSpec with Matchers with TwirlSpec with GovukServiceChecks

A service is reached from GOV.UK rather than from a search engine, often keeps its pages out of search on purpose, and titles every page in the Design System's "Page - Service - GOV.UK" pattern, so io.github.frikit.twirlspec.quality.MetadataStandards.searchRules would warn on every page it has. And scripts-are-deferred would warn on every page that carries HMRC's tracking-consent script, which the platform puts in the head on purpose, so here it leaves GovukServiceChecks.platformScripts alone and still reports the service's own. Everything else AllChecks runs, this runs.

Mix it in after any rule trait of your own: a trait mixed in later adds its rules after this one has filtered.

Attributes

Companion
object
Source
GovukServiceChecks.scala
Supertypes
trait AllChecks
trait I18nChecks
trait HtmlChecks
trait AriaChecks
trait GovukChecks
trait WcagChecks
trait TwirlSpecDsl
class Object
trait Matchable
class Any
Show all
Known subtypes

What GovukServiceChecks knows about a GOV.UK service's platform.

What GovukServiceChecks knows about a GOV.UK service's platform.

Attributes

Companion
trait
Source
GovukServiceChecks.scala
Supertypes
class Object
trait Matchable
class Any
Self type

What HmrcServiceChecks knows about play-frontend-hmrc's markup.

What HmrcServiceChecks knows about play-frontend-hmrc's markup.

Attributes

Companion
trait
Source
HmrcServiceChecks.scala
Supertypes
class Object
trait Matchable
class Any
Self type

GovukServiceChecks for an HMRC service built on play-frontend-hmrc, with what every such service would otherwise write on its spec base:

GovukServiceChecks for an HMRC service built on play-frontend-hmrc, with what every such service would otherwise write on its spec base:

trait ViewSpecBase extends AnyWordSpec with Matchers with TwirlSpec with HmrcServiceChecks

The report-a-problem link every page inherits is left out of coverage, in whichever language it reads, and "HMRC" may read the same in every language. The link's own layout deserves a test of its own, and the rules still check it.

Attributes

Companion
object
Source
HmrcServiceChecks.scala
Supertypes
trait AllChecks
trait I18nChecks
trait HtmlChecks
trait AriaChecks
trait GovukChecks
trait WcagChecks
trait TwirlSpecDsl
class Object
trait Matchable
class Any
Show all
final case class PageCase(label: String, states: List[PageState], standardsExcept: Seq[String] = ..., translationExcept: Seq[String] = ...)

A page in a catalogue, and the rules it is excused from.

A page in a catalogue, and the rules it is excused from.

Value parameters

label

what its tests are called

standardsExcept

the standards rules it is excused from

states

the ways it is rendered, at least one

translationExcept

the language comparison rules it is excused from

Attributes

Source
PageCatalogue.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
trait PageCases extends TwirlSpec, I18nChecks

A service's pages as data, and the checks every page needs, for any test style: all at once, by checkStandards and checkTranslation, or one by one, by checksOf. PageCatalogue is the same for AnyWordSpec, with a test written for each check.

A service's pages as data, and the checks every page needs, for any test style: all at once, by checkStandards and checkTranslation, or one by one, by checksOf. PageCatalogue is the same for AnyWordSpec, with a test written for each check.

Nothing is rendered until a check runs, so each state renders in the language being checked. A check runs every state in every language, and its failure reports each that went wrong, by state and language.

Attributes

Source
PageCatalogue.scala
Supertypes
trait I18nChecks
trait TwirlSpec
trait SuiteMixin
trait TwirlSpecDsl
class Object
trait Matchable
class Any
Show all
Known subtypes
Self type
Suite & Alerting
trait PageCatalogue extends AnyWordSpecLike, PageCases

A table of a service's pages, with a test for each check on each page, so the report lists what was checked:

A table of a service's pages, with a test for each check on each page, so the report lists what was checked:

class EveryPageSpec extends ViewSpecBase with PageCatalogue {
 catalogue(
   staticPage("Info")(inject[InfoView](draftId)),
   formPage("Name", nameForm)(inject[NameView](_, draftId)),
   formPage("Date of birth", dobForm, "part of a date" -> Map("value.day" -> "1"))(
     inject[DateOfBirthView](_, draftId)
   ),
   staticPage("Not found")(inject[PageNotFoundView]())
     .exceptTranslation("i18n-same-links")
 )
}
Name
- must render blank, in en
- must render with errors, in en
- must meet one-h1 in en: a page has exactly one
=
- must render blank, in cy
- must meet one-h1 in cy: a page has exactly one
=
- must translate consistently by i18n-same-links, cy against en: every language links to the same places

It writes its tests in the AnyWordSpec style. For another style, mix in PageCases and call its checks from tests of your own.

Attributes

Source
PageCatalogue.scala
Supertypes
trait PageCases
trait I18nChecks
trait TwirlSpec
trait SuiteMixin
trait TwirlSpecDsl
trait AnyWordSpecLike
trait Documenting
trait Alerting
trait Notifying
trait Informing
trait CanVerb
trait MustVerb
trait ShouldVerb
trait TestRegistration
trait TestSuite
trait Suite
trait Serializable
trait Assertions
trait TripleEquals
trait TripleEqualsSupport
class Object
trait Matchable
class Any
Show all
final case class PageCheck(name: String, run: () => Unit)

One of a page's checks on its own: its name, as a test's name reads after the page's label and must, and the check.

One of a page's checks on its own: its name, as a test's name reads after the page's label and must, and the check.

Attributes

Source
PageCatalogue.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class PageState(name: String, render: () => Html)

One way a page can be rendered.

One way a page can be rendered.

Attributes

Source
PageCatalogue.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
trait SuiteLifecycle extends SuiteMixin

Starts each run of a suite with a clean coverage and exclusion record, and drops both once it has finished, so a spec run again in the same JVM — from an sbt shell, say — cannot pass assertEverything or unusedExclusions on what an earlier run asserted.

Starts each run of a suite with a clean coverage and exclusion record, and drops both once it has finished, so a spec run again in the same JVM — from an sbt shell, say — cannot pass assertEverything or unusedExclusions on what an earlier run asserted.

TwirlSpec mixes it in. A spec base built on TwirlSpecDsl mixes it in itself:

trait ViewSpecBase extends AnyWordSpec with Matchers with GuiceOneAppPerSuite
 with TwirlSpecDsl with SuiteLifecycle

The run OneInstancePerTest (and so ParallelTestExecution) makes for each test on its own instance leaves the records alone, since the suite's other tests are still adding to them; ScalaTest marks that run with runTestInNewInstance. A BeforeAndAfterAll mixed in after this trait runs its afterAll once the records have been dropped.

Attributes

Source
SuiteLifecycle.scala
Supertypes
trait SuiteMixin
class Object
trait Matchable
class Any
Known subtypes
trait TwirlSpec
trait PageCases
Self type
Suite

ScalaTest matchers over a rendered page.

ScalaTest matchers over a rendered page.

Attributes

Source
TwirlMatchers.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
Self type

The batteries-included entry point: an application, the implicits a Twirl view needs, and language switching, on top of the TwirlSpecDsl surface.

The batteries-included entry point: an application, the implicits a Twirl view needs, and language switching, on top of the TwirlSpecDsl surface.

Attributes

Source
TwirlSpec.scala
Supertypes
trait SuiteMixin
trait TwirlSpecDsl
class Object
trait Matchable
class Any
Show all
Known subtypes
trait PageCases
Self type
Suite & Alerting

The whole authoring surface. Declares no implicits and builds no application, so it drops into an existing spec base.

The whole authoring surface. Declares no implicits and builds no application, so it drops into an existing spec base.

Attributes

Source
TwirlSpecDsl.scala
Supertypes
class Object
trait Matchable
class Any
Show all
Known subtypes

How TwirlSpecReporter lays a run out.

How TwirlSpecReporter lays a run out.

Attributes

Companion
class
Source
TwirlSpecReporter.scala
Supertypes
class Object
trait Matchable
class Any
Self type
class TwirlSpecReporter(directory: Path) extends Reporter

A report of a test run, as a page to read and as Markdown for a CI summary: how many tests passed, failed, warned and were cancelled, how long they took, and each suite's tests, with a catalogue's checks laid out as a table of rules by language and every failure's message beside it.

A report of a test run, as a page to read and as Markdown for a CI summary: how many tests passed, failed, warned and were cancelled, how long they took, and each suite's tests, with a catalogue's checks laid out as a table of rules by language and every failure's message beside it.

Add it to a run, in build.sbt:

Test / testOptions += Tests.Argument(
 TestFrameworks.ScalaTest, "-C", "io.github.frikit.twirlspec.TwirlSpecReporter"
)

It writes index.html and report.md to target/twirl-spec-report, or to the directory the twirlspec.report.dir system property or the TWIRLSPEC_REPORT_DIR environment variable names, as each suite finishes and when the run does, and then says where.

Attributes

Companion
object
Source
TwirlSpecReporter.scala
Supertypes
trait Reporter
class Object
trait Matchable
class Any
trait TwirlSuite extends FunSuite, TwirlSpecDsl, I18nChecks

twirl-spec for MUnit: what TwirlSpec gives a ScalaTest spec, for an MUnit suite. An application shared across the JVM, inject[View], languages, the expectation DSL, assertions over the same matchers, and the page catalogue as a test for each check:

twirl-spec for MUnit: what TwirlSpec gives a ScalaTest spec, for an MUnit suite. An application shared across the JVM, inject[View], languages, the expectation DSL, assertions over the same matchers, and the page catalogue as a test for each check:

class NameViewSuite extends TwirlSuite with HmrcServiceChecks {
 private val view = inject[NameView]
 private val form = Form(single("value" -> text))

 cataloguePage(formPage("NameView", form)(view(_))) {
   test("NameView asks for the name") {
     assertDisplays(renderPage(view(form)), heading("name.heading"))
   }
 }
}

Its rules are those its rule traits give, as in a ScalaTest spec, and its failures are MUnit's, with the same messages. ScalaTest stays on the class path, as the rules and matchers are built on it, but nothing here runs it.

Attributes

Source
TwirlSuite.scala
Supertypes
trait I18nChecks
trait TwirlSpecDsl
class FunSuite
trait BaseFunSuite
trait EventuallyTransforms
trait ValueTransforms
trait SuiteTransforms
trait TestTransforms
trait TestOptionsConversions
trait FunFixtures
trait Assertions
trait CompileErrorMacro
class Suite
trait PlatformSuite
class Object
trait Matchable
class Any
Show all