|
defmodule Medicode.FeedbackButtonTest do |
|
use MedicodeWeb.ConnCase, async: true |
|
|
|
import Phoenix.LiveViewTest |
|
|
|
import Medicode.{ |
|
TranscriptionChunksFixtures, |
|
CodeVectorsFixtures, |
|
CodeFeedbacksFixtures |
|
} |
|
|
|
alias MedicodeWeb.Components |
|
|
|
describe "feedback_button" do |
|
setup do |
|
insert_code_vector_fixtures() |
|
|
|
chunk = transcription_chunk_fixture() |
|
code_vector = code_vector_fixture() |
|
positive_code_feedback = code_feedback_fixture(%{response: true}) |
|
negative_code_feedback = code_feedback_fixture(%{response: false}) |
|
|
|
%{ |
|
chunk: chunk, |
|
code_vector: code_vector, |
|
positive_code_feedback: positive_code_feedback, |
|
negative_code_feedback: negative_code_feedback |
|
} |
|
end |
|
|
|
test "renders code vector text", %{ |
|
chunk: chunk, |
|
code_vector: code_vector |
|
} do |
|
component = |
|
render_component(&Components.tag_result/1, |
|
code_feedback: nil, |
|
chunk_id: chunk.id, |
|
code_vector: code_vector, |
|
score: 1.0, |
|
text: chunk.text, |
|
weighting: [1.0] |
|
) |
|
|
|
assert component =~ chunk.text |
|
assert component =~ code_vector.description |
|
assert component =~ code_vector.code |
|
assert component =~ ~s(title="Similarity score: 1.0. Weighting: 1.0 \(1\)") |
|
assert component =~ ~s(<img src="/images/thumbs-up.svg") |
|
assert component =~ ~s(<img src="/images/thumbs-down.svg") |
|
end |
|
|
|
test "renders feedback button as selected for user with positive code feedback", %{ |
|
chunk: chunk, |
|
code_vector: code_vector, |
|
positive_code_feedback: code_feedback |
|
} do |
|
component = |
|
render_component(&Components.tag_result/1, |
|
code_feedback: code_feedback, |
|
chunk_id: chunk.id, |
|
code_vector: code_vector, |
|
score: 1.0, |
|
text: chunk.text, |
|
weighting: [1.0] |
|
) |
|
|
|
assert component =~ ~s(<button data-feedback="positive") |
|
end |
|
|
|
test "renders feedback button as de-selected for user with negative code feedback", %{ |
|
chunk: chunk, |
|
code_vector: code_vector, |
|
negative_code_feedback: code_feedback |
|
} do |
|
component = |
|
render_component(&Components.tag_result/1, |
|
code_feedback: code_feedback, |
|
chunk_id: chunk.id, |
|
code_vector: code_vector, |
|
score: 1.0, |
|
text: chunk.text, |
|
weighting: [1.0] |
|
) |
|
|
|
assert component =~ ~s(<button data-feedback="negative") |
|
end |
|
end |
|
end |
|
|