narrativeText method
Compiles all tracked story elements into a single formatted text block.
Pattern-matches each step type to its domain-specific string representation (e.g., mapping GivenScenarioStepData to 'Given...'), applies a nested hierarchy indentation, and appends runtime test results.
Implementation
String narrativeText() {
return steps
.map((step) {
final (prefix, indent, showStatus, status) = switch (step) {
StoryNarrativeData _ => (
'Story is: \'${step.description}\'',
0,
false,
'',
),
AsStepData _ => ('As ${step.description}', _indent1, false, ''),
AsAStepData _ => ('As a ${step.description}', _indent1, false, ''),
ICanStepData _ => (
'I can ${step.description}',
_indent1,
false,
'',
),
IWantStepData _ => (
'I want ${step.description}',
_indent1,
false,
'',
),
SoThatStepData _ => (
'So that ${step.description}',
_indent1,
false,
'',
),
InOrderToStepData _ => (
'In order to ${step.description}',
_indent1,
false,
'',
),
BecauseStepData _ => (
'Because ${step.description}',
_indent1,
false,
'',
),
WhenStepData _ => ('When ${step.description}', _indent1, false, ''),
ScenarioStepData _ => (
'With scenario: ${step.description}',
_indent1,
false,
'',
),
GivenScenarioStepData d => (
'Given ${step.description}',
_indent2,
true,
d.status,
),
WhenScenarioStepData d => (
' When ${step.description}',
_indent2,
true,
d.status,
),
ThenScenarioStepData d => (
' Then ${step.description}',
_indent2,
true,
d.status,
),
AndScenarioStepData d => (
' And ${step.description}',
_indent2,
true,
d.status,
),
};
return _alignText(
prefix,
indent,
showStatus: showStatus,
status: status,
);
})
.join('\n');
}