Skip to content

Commit 4e2e9a8

Browse files
Also search in step datatable
1 parent 4612092 commit 4e2e9a8

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

react/javascript/src/search/StepSearch.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ interface SearchableStep {
55
id: string
66
keyword: string
77
text: string
8-
docstring?: string
8+
docString?: string
9+
dataTable?: string
910
}
1011

1112
export default class StepSearch {
1213
private readonly index = elasticlunr<SearchableStep>((ctx) => {
1314
ctx.addField('keyword')
1415
ctx.addField('text')
15-
ctx.addField('docstring')
16+
ctx.addField('docString')
17+
ctx.addField('dataTable')
1618
ctx.setRef('id')
1719
ctx.saveDocument(true)
1820
})
@@ -23,7 +25,8 @@ export default class StepSearch {
2325
id: step.id,
2426
keyword: step.keyword,
2527
text: step.text,
26-
docstring: this.docstringToString(step),
28+
docString: this.docStringToString(step),
29+
dataTable: this.dataTableToString(step),
2730
}
2831

2932
this.index.addDoc(doc)
@@ -35,16 +38,27 @@ export default class StepSearch {
3538
fields: {
3639
keyword: { bool: 'OR', expand: true, boost: 1 },
3740
text: { bool: 'OR', expand: true, boost: 2 },
38-
docstring: { bool: 'OR', expand: true, boost: 1 },
41+
docString: { bool: 'OR', expand: true, boost: 1 },
42+
dataTable: { bool: 'OR', expand: true, boost: 1 },
3943
},
4044
})
4145

4246
return results.map((result) => this.stepById.get(result.ref))
4347
}
4448

45-
private docstringToString(
49+
private docStringToString(
4650
step: messages.GherkinDocument.Feature.IStep
4751
): string {
4852
return step.docString ? step.docString.content : ''
4953
}
54+
55+
private dataTableToString(
56+
step: messages.GherkinDocument.Feature.IStep
57+
): string {
58+
return step.dataTable
59+
? step.dataTable.rows
60+
.map((row) => row.cells.map((cell) => cell.value).join(' '))
61+
.join(' ')
62+
: undefined
63+
}
5064
}

react/javascript/test/search/StepSearchTest.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ describe('StepSearch', () => {
1313
steps = [
1414
makeStep('Given', 'a passed step', 'There is a docstring here'),
1515
makeStep('When', 'another passed step'),
16-
makeStep('Then', 'a failed step'),
16+
makeStep('Then', 'a failed step', '', [
17+
['name', 'value'],
18+
['errorType', 'NullPointerException'],
19+
['message', 'Something really bad hapenned here'],
20+
]),
1721
]
1822

1923
for (const step of steps) {
@@ -55,5 +59,10 @@ describe('StepSearch', () => {
5559
const searchResults = stepSearch.search('docstring')
5660
assert.deepStrictEqual(searchResults, [steps[0]])
5761
})
62+
63+
it('returns step which datatable matches the query', () => {
64+
const searchResults = stepSearch.search('NullPointerException')
65+
assert.deepStrictEqual(searchResults, [steps[2]])
66+
})
5867
})
5968
})

react/javascript/test/search/utils.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,36 @@ function makeScenario(
5353
function makeStep(
5454
keyword: string,
5555
text: string,
56-
docstring = ''
56+
docstring = '',
57+
datatable: ReadonlyArray<ReadonlyArray<string>> = []
5758
): messages.GherkinDocument.Feature.IStep {
5859
const idGenerator = IdGenerator.uuid()
5960
const docStringParam = docstring
6061
? messages.GherkinDocument.Feature.Step.DocString.create({
6162
content: docstring,
6263
})
6364
: undefined
65+
const datatableParam =
66+
datatable.length > 0
67+
? messages.GherkinDocument.Feature.Step.DataTable.create({
68+
rows: datatable.map((row) =>
69+
messages.GherkinDocument.Feature.TableRow.create({
70+
cells: row.map((cell) =>
71+
messages.GherkinDocument.Feature.TableRow.TableCell.create({
72+
value: cell,
73+
})
74+
),
75+
})
76+
),
77+
})
78+
: undefined
6479

6580
return messages.GherkinDocument.Feature.Step.create({
6681
id: idGenerator(),
6782
keyword: keyword,
6883
text: text,
6984
docString: docStringParam,
85+
dataTable: datatableParam,
7086
})
7187
}
7288

0 commit comments

Comments
 (0)