Skip to content

Commit e2ddeea

Browse files
committed
Updated requirements logic
1 parent c09beaf commit e2ddeea

1 file changed

Lines changed: 44 additions & 18 deletions

File tree

content/assets/js/requirements-table.js

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,32 @@ $(function () {
66
const $rows = $table.find("tr").slice(2);
77

88
function normalize(text) {
9-
return text.replace(/\s+/g, "").toLowerCase();
9+
return text.replace(/\s+/g, " ").trim();
1010
}
1111

1212
function applyFilters() {
1313

14-
const idFilter = normalize($("input[name='filterid']").val() || "");
15-
const ruleFilter = normalize($("input[name='filterrule']").val() || "");
14+
const idFilter = normalize($("input[name='filterid']").val() || "").toLowerCase();
15+
const ruleFilter = normalize($("input[name='filterrule']").val() || "").toLowerCase();
1616

17+
/* Selected expectations (exact tokens) */
1718
const expectations = $("input[name^='expect']:checked")
1819
.map(function () {
19-
return $(this)[0].nextSibling.nodeValue.trim();
20+
return normalize(this.nextSibling.nodeValue);
2021
})
2122
.get();
2223

24+
/* Selected actors */
2325
const actors = $("input[name^='actor']:checked")
24-
.map(function () { return $(this).next("a").text().trim(); })
26+
.map(function () {
27+
return $(this).next("a").text().trim();
28+
})
2529
.get();
2630

31+
/* Selected categories */
2732
const categories = $("input[name^='category']:checked")
2833
.map(function () {
29-
return this.nextSibling.nodeValue.trim();
34+
return normalize(this.nextSibling.nodeValue);
3035
})
3136
.get();
3237

@@ -36,14 +41,32 @@ $(function () {
3641

3742
const $cells = $(this).children("th,td");
3843

39-
const idText = normalize($cells.eq(0).text());
40-
const expectationText = $cells.eq(1).text().replace(/\s+/g, " ").trim();
41-
const conditionalText = $cells.eq(2).text();
42-
const actorText = $cells.eq(3).text();
43-
const categoryText = $cells.eq(4).text();
44-
const ruleText = normalize($cells.eq(5).text());
45-
46-
const hasConditionalX = /\bX\b/.test(conditionalText);
44+
const idText = $cells.eq(0).text().toLowerCase();
45+
const ruleText = $cells.eq(5).text().toLowerCase();
46+
const condText = $cells.eq(2).text();
47+
48+
const hasConditionalX = /\bX\b/.test(condText);
49+
50+
/* Extract expectation tokens (split on <br/>) */
51+
const rowExpectations = $cells.eq(1)
52+
.html()
53+
.split(/<br\s*\/?>/i)
54+
.map(e => normalize($("<div>").html(e).text()))
55+
.filter(Boolean);
56+
57+
/* Extract actors (exact anchor match) */
58+
const rowActors = $cells.eq(3).find("a")
59+
.map(function () {
60+
return $(this).text().trim();
61+
})
62+
.get();
63+
64+
/* Extract categories (exact tokens) */
65+
const rowCategories = $cells.eq(4)
66+
.text()
67+
.split(/\s*[\r\n]+\s*/)
68+
.map(c => c.trim())
69+
.filter(Boolean);
4770

4871
let visible = true;
4972

@@ -52,8 +75,9 @@ $(function () {
5275
visible = false;
5376
}
5477

55-
/* Expectation filter */
56-
if (expectations.length && !expectations.includes(expectationText)) {
78+
/* Expectation filter — exact token match */
79+
if (expectations.length &&
80+
!expectations.some(e => rowExpectations.includes(e))) {
5781
visible = false;
5882
}
5983

@@ -66,12 +90,14 @@ $(function () {
6690
}
6791

6892
/* Actor filter */
69-
if (actors.length && !actors.some(a => actorText.includes(a))) {
93+
if (actors.length &&
94+
!actors.some(a => rowActors.includes(a))) {
7095
visible = false;
7196
}
7297

7398
/* Category filter */
74-
if (categories.length && !categories.some(c => categoryText.includes(c))) {
99+
if (categories.length &&
100+
!categories.some(c => rowCategories.includes(c))) {
75101
visible = false;
76102
}
77103

0 commit comments

Comments
 (0)