|
175 | 175 | end |
176 | 176 |
|
177 | 177 | describe "GET :show" do |
| 178 | + shared_examples "renders_run in analysis tab when present" do |run_association, title| |
| 179 | + context "when #{run_association} data is present" do |
| 180 | + let(:run) do |
| 181 | + create( |
| 182 | + run_association, |
| 183 | + score: 0.85, |
| 184 | + reason: "The answer was acceptable.", |
| 185 | + llm_responses: { |
| 186 | + "verdicts" => { "verdicts" => [{ "verdict" => "yes" }] }, |
| 187 | + "reason" => { "reason" => ["The answer was acceptable."] }, |
| 188 | + |
| 189 | + }, |
| 190 | + metrics: { |
| 191 | + "verdicts" => { duration: 1.44445 }, |
| 192 | + "reason" => { duration: 1.55556 }, |
| 193 | + }, |
| 194 | + ) |
| 195 | + end |
| 196 | + let(:question) { run.answer.question } |
| 197 | + |
| 198 | + it "renders #{run_association} details in the analysis tab" do |
| 199 | + get admin_show_question_path(question) |
| 200 | + |
| 201 | + expect(response.body) |
| 202 | + .to have_selector("#analysis-tab", text: title) |
| 203 | + .and have_selector("#analysis-tab", text: /Mean score\s*0\.85/) |
| 204 | + .and have_selector("#analysis-tab", text: /Run 1 score\s*0\.85/) |
| 205 | + .and have_selector("#analysis-tab", text: /Run 1 reason\s*The answer was acceptable\./) |
| 206 | + end |
| 207 | + |
| 208 | + it "renders the runs llm responses" do |
| 209 | + get admin_show_question_path(question) |
| 210 | + |
| 211 | + expect(response.body.squish) |
| 212 | + .to have_content('{ "verdicts": [ { "verdict": "yes" } ] }') |
| 213 | + .and have_content('{ "reason": [ "The answer was acceptable." ] }') |
| 214 | + end |
| 215 | + |
| 216 | + it "renders the runs metrics" do |
| 217 | + get admin_show_question_path(question) |
| 218 | + |
| 219 | + expect(response.body.squish) |
| 220 | + .to have_content("Verdicts") |
| 221 | + .and have_content(/duration.*1\.44445/) |
| 222 | + .and have_content("Reason") |
| 223 | + .and have_content(/duration.*1\.55556/) |
| 224 | + end |
| 225 | + end |
| 226 | + end |
| 227 | + |
| 228 | + it_behaves_like "renders_run in analysis tab when present", :answer_relevancy_run, "Answer relevancy" |
| 229 | + it_behaves_like "renders_run in analysis tab when present", :coherence_run, "Coherence" |
| 230 | + |
178 | 231 | it "renders the page successfully" do |
179 | 232 | question = create(:question) |
180 | 233 | get admin_show_question_path(question) |
|
284 | 337 | .and have_content('"id": "call_dqGpbb39drQDafLsjDLtnbGD"') |
285 | 338 | end |
286 | 339 |
|
287 | | - it "doesn't render the tabs component when there are no topics or auto-eval aggregate data" do |
| 340 | + it "doesn't render the tabs component there is no analysis data" do |
288 | 341 | question = create(:question, :with_answer) |
289 | 342 | get admin_show_question_path(question) |
290 | 343 |
|
|
361 | 414 | .and have_selector("#analysis-tab", text: topics.secondary_topic.capitalize) |
362 | 415 | end |
363 | 416 | end |
364 | | - |
365 | | - context "when answer relevancy aggregate data is present" do |
366 | | - let(:run) do |
367 | | - create( |
368 | | - :answer_relevancy_run, |
369 | | - score: 0.85, |
370 | | - reason: "The answer is relevant to the question.", |
371 | | - llm_responses: { |
372 | | - "statements" => { "statements" => ["The answer is relevant."] }, |
373 | | - "verdicts" => { "verdicts" => [{ "verdict" => "yes" }] }, |
374 | | - }, |
375 | | - metrics: { |
376 | | - "statements" => { duration: 1.55556 }, |
377 | | - "verdicts" => { duration: 1.44445 }, |
378 | | - }, |
379 | | - ) |
380 | | - end |
381 | | - let(:question) { run.answer.question } |
382 | | - |
383 | | - it "renders the answer relevancy aggregate and run details" do |
384 | | - get admin_show_question_path(question) |
385 | | - |
386 | | - expect(response.body.squish) |
387 | | - .to have_content("Answer relevancy") |
388 | | - .and have_content("Run 1 score") |
389 | | - .and have_content("0.85") |
390 | | - .and have_content("Run 1 reason") |
391 | | - .and have_content("The answer is relevant to the question.") |
392 | | - end |
393 | | - |
394 | | - it "renders the runs llm responses" do |
395 | | - get admin_show_question_path(question) |
396 | | - |
397 | | - expect(response.body.squish) |
398 | | - .to have_content('{ "statements": [ "The answer is relevant." ] }') |
399 | | - .and have_content('{ "verdicts": [ { "verdict": "yes" } ] }') |
400 | | - end |
401 | | - |
402 | | - it "renders the runs metrics" do |
403 | | - get admin_show_question_path(question) |
404 | | - |
405 | | - expect(response.body.squish) |
406 | | - .to have_content("Statements") |
407 | | - .and have_content(/duration.*1\.55556/) |
408 | | - .and have_content("Verdicts") |
409 | | - .and have_content(/duration.*1\.44445/) |
410 | | - end |
411 | | - end |
412 | 417 | end |
413 | 418 |
|
414 | 419 | def expect_unprocessable_content_with_date_errors |
|
0 commit comments