Skip to content

Commit 2d4aff2

Browse files
committed
fix copilot concerns and unit tests
1 parent 1aae029 commit 2d4aff2

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

app/javascript/__tests__/dashboard.test.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ describe('defineCaseContactsTable', () => {
132132
expect(columns[0].searchable).toBe(false)
133133
})
134134

135-
it('renders filled bell icon when has_followup is true', () => {
136-
const rendered = columns[0].render(true, 'display', {})
135+
it('renders filled bell icon when has_followup is "true"', () => {
136+
const rendered = columns[0].render("true", 'display', {})
137137

138138
expect(rendered).toBe('<i class="fas fa-bell"></i>')
139139
})
140140

141-
it('renders faded bell icon when has_followup is false', () => {
142-
const rendered = columns[0].render(false, 'display', {})
141+
it('renders faded bell icon when has_followup is "false"', () => {
142+
const rendered = columns[0].render("false", 'display', {})
143143

144144
expect(rendered).toBe('<i class="fas fa-bell" style="opacity: 0.3;"></i>')
145145
})
@@ -262,43 +262,43 @@ describe('defineCaseContactsTable', () => {
262262
})
263263

264264
it('renders checkmark icon when contact was made', () => {
265-
const row = { contact_made: true, duration_minutes: null }
266-
const rendered = columns[7].render(true, 'display', row)
265+
const row = { contact_made: "true", duration_minutes: null }
266+
const rendered = columns[7].render("true", 'display', row)
267267

268268
expect(rendered).toContain('<i class="lni lni-checkmark-circle" style="color: green;"></i>')
269269
})
270270

271271
it('renders cross icon when contact was not made', () => {
272-
const row = { contact_made: false, duration_minutes: null }
273-
const rendered = columns[7].render(false, 'display', row)
272+
const row = { contact_made: "false", duration_minutes: null }
273+
const rendered = columns[7].render("false", 'display', row)
274274

275275
expect(rendered).toContain('<i class="lni lni-cross-circle" style="color: orange;"></i>')
276276
})
277277

278278
it('includes formatted duration when present', () => {
279-
const row = { contact_made: true, duration_minutes: 90 }
280-
const rendered = columns[7].render(true, 'display', row)
279+
const row = { contact_made: "true", duration_minutes: 90 }
280+
const rendered = columns[7].render("true", 'display', row)
281281

282282
expect(rendered).toContain('(01:30)')
283283
})
284284

285285
it('formats duration with leading zeros', () => {
286-
const row = { contact_made: true, duration_minutes: 5 }
287-
const rendered = columns[7].render(true, 'display', row)
286+
const row = { contact_made: "true", duration_minutes: 5 }
287+
const rendered = columns[7].render("true", 'display', row)
288288

289289
expect(rendered).toContain('(00:05)')
290290
})
291291

292292
it('handles hours and minutes correctly', () => {
293-
const row = { contact_made: true, duration_minutes: 125 }
294-
const rendered = columns[7].render(true, 'display', row)
293+
const row = { contact_made: "true", duration_minutes: 125 }
294+
const rendered = columns[7].render("true", 'display', row)
295295

296296
expect(rendered).toContain('(02:05)')
297297
})
298298

299299
it('does not include duration when not present', () => {
300-
const row = { contact_made: true, duration_minutes: null }
301-
const rendered = columns[7].render(true, 'display', row)
300+
const row = { contact_made: "true", duration_minutes: null }
301+
const rendered = columns[7].render("true", 'display', row)
302302

303303
expect(rendered).not.toContain('(')
304304
})
@@ -338,11 +338,11 @@ describe('defineCaseContactsTable', () => {
338338
expect(rendered).toBe('<span class="badge badge-pill light-bg text-black" data-testid="draft-badge">Draft</span>')
339339
})
340340

341-
it('handles string "false" as truthy (because it is a non-empty string)', () => {
341+
it('handles string "false" as falsy (explicit check for "true")', () => {
342342
const rendered = columns[9].render('false', 'display', {})
343343

344-
// In JavaScript, the string "false" is truthy, so this will render the badge
345-
expect(rendered).toBe('<span class="badge badge-pill light-bg text-black" data-testid="draft-badge">Draft</span>')
344+
// With explicit check for === true || === "true", string "false" should not render badge
345+
expect(rendered).toBe('')
346346
})
347347

348348
it('handles empty string as falsy', () => {

app/javascript/src/dashboard.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ const defineCaseContactsTable = function () {
7979
editPath = `/volunteers/${data.id}/edit`
8080
}
8181

82-
return `<a href="${editPath}" data-turbo="false">${data.display_name}</a>`
82+
return $('<a>')
83+
.attr('href', editPath)
84+
.attr('data-turbo', 'false')
85+
.text(data.display_name)
86+
.prop('outerHTML')
8387
}
8488
},
8589
{ // Contacted column (index 7)
@@ -108,7 +112,7 @@ const defineCaseContactsTable = function () {
108112
data: 'is_draft',
109113
orderable: false,
110114
render: (data) => {
111-
return data
115+
return (data === true || data === "true")
112116
? '<span class="badge badge-pill light-bg text-black" data-testid="draft-badge">Draft</span>'
113117
: ''
114118
}

spec/datatables/case_contact_datatable_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
expect(contact_data[:id]).to eq(case_contact.id.to_s)
6262
expect(contact_data[:contact_made]).to eq("true")
63-
expect(contact_data[:medium_type]).to eq("In-person")
63+
expect(contact_data[:medium_type]).to eq("In Person")
6464
expect(contact_data[:duration_minutes]).to eq("60")
6565
end
6666

0 commit comments

Comments
 (0)