Skip to content

Commit 2349b78

Browse files
Keep descriptions when filtering objects
1 parent ca572b3 commit 2349b78

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

src/components/gherkin/TableBody.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react'
22
import { messages } from '@cucumber/messages'
33
import isNumber from './isNumber'
4+
import HighLight from '../app/HighLight'
45

56
interface IProps {
67
rows: messages.GherkinDocument.Feature.ITableRow[]
@@ -16,7 +17,7 @@ const TableBody: React.FunctionComponent<IProps> = ({ rows }) => {
1617
key={j}
1718
style={{ textAlign: isNumber(cell.value) ? 'right' : 'left' }}
1819
>
19-
{cell.value}
20+
<HighLight text={cell.value} />
2021
</td>
2122
))}
2223
</tr>

src/pretty-formatter/pretty.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ export default function pretty(
55
): string {
66
const feature = gherkinDocument.feature
77
let s = feature.keyword + ': ' + feature.name + '\n'
8+
if (feature.description) {
9+
s += feature.description + '\n'
10+
}
811
for (const child of feature.children) {
912
if (child.background) {
1013
s += prettyStepContainer(child.background, ' ')
1114
} else if (child.scenario) {
1215
s += prettyStepContainer(child.scenario, ' ')
1316
} else if (child.rule) {
1417
s += `\n ${child.rule.keyword}: ${child.rule.name}\n`
18+
if (child.rule.description) {
19+
s += child.rule.description + '\n'
20+
}
21+
1522
for (const ruleChild of child.rule.children) {
1623
if (ruleChild.background) {
1724
s += prettyStepContainer(ruleChild.background, ' ')
@@ -30,6 +37,9 @@ function prettyStepContainer(
3037
indent: string
3138
): string {
3239
let s = `\n${indent}${stepContainer.keyword}: ${stepContainer.name}\n`
40+
if (stepContainer.description) {
41+
s += stepContainer.description + '\n\n'
42+
}
3343
for (const step of stepContainer.steps) {
3444
s += `${indent} ${step.keyword}${step.text}\n`
3545
}

src/search/AstWalker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export default class AstWalker {
116116
language: feature.language,
117117
keyword: feature.keyword,
118118
name: feature.name,
119+
description: feature.description ? feature.description : undefined,
119120
})
120121
}
121122

@@ -229,6 +230,7 @@ export default class AstWalker {
229230
location: rule.location,
230231
keyword: rule.keyword,
231232
children: this.filterRuleChildren(rule.children, children),
233+
description: rule.description ? rule.description : undefined,
232234
})
233235
}
234236

@@ -308,6 +310,7 @@ export default class AstWalker {
308310
location: background.location,
309311
keyword: background.keyword,
310312
steps: background.steps.map((step) => this.copyStep(step)),
313+
description: background.description ? background.description : undefined,
311314
})
312315
}
313316

@@ -336,6 +339,7 @@ export default class AstWalker {
336339
examples: scenario.examples,
337340
steps: scenario.steps.map((step) => this.copyStep(step)),
338341
tags: scenario.tags,
342+
description: scenario.description ? scenario.description : undefined,
339343
})
340344
}
341345

test/search/AstWalkerTest.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('AstWalker', () => {
6363

6464
it('filters one scenario', () => {
6565
const gherkinDocument = parse(`Feature: Solar System
66+
The solar system is kind of a nice place
6667
6768
Scenario: Saturn
6869
Given is the sixth planet from the Sun
@@ -78,6 +79,7 @@ describe('AstWalker', () => {
7879
const newGherkinDocument = walker.walkGherkinDocument(gherkinDocument)
7980
const newSource = pretty(newGherkinDocument)
8081
const expectedNewSource = `Feature: Solar System
82+
The solar system is kind of a nice place
8183
8284
Scenario: Earth
8385
Given is a planet with liquid water
@@ -161,6 +163,8 @@ describe('AstWalker', () => {
161163
Given space is real
162164
163165
Rule: Galaxy
166+
A galaxy is a place where big stuff floats
167+
164168
Background: Milky Way
165169
Given it contains our system
166170
@@ -183,6 +187,7 @@ describe('AstWalker', () => {
183187
Given space is real
184188
185189
Rule: Galaxy
190+
A galaxy is a place where big stuff floats
186191
187192
Background: Milky Way
188193
Given it contains our system
@@ -198,6 +203,8 @@ describe('AstWalker', () => {
198203
199204
Rule: Galaxy
200205
Background: Milky Way
206+
The Milky way (with a capital) is not simply a snack
207+
201208
Given it contains our system
202209
203210
Rule: Black Hole
@@ -219,6 +226,8 @@ describe('AstWalker', () => {
219226
Rule: Galaxy
220227
221228
Background: Milky Way
229+
The Milky way (with a capital) is not simply a snack
230+
222231
Given it contains our system
223232
224233
Rule: Black Hole
@@ -241,6 +250,8 @@ describe('AstWalker', () => {
241250
Given it contains our system
242251
243252
Scenario: Andromeda
253+
Nebula Chain !!!
254+
244255
Given it exists
245256
`)
246257

@@ -258,6 +269,8 @@ describe('AstWalker', () => {
258269
Given it's a black hole
259270
260271
Scenario: Andromeda
272+
Nebula Chain !!!
273+
261274
Given it exists
262275
`
263276
assert.strictEqual(newSource, expectedNewSource)

0 commit comments

Comments
 (0)