Commit
•
597b27e
1
Parent(s):
ea37cf1
fix: Feedback button test
Browse files
test/medical_transcription_web/components/feedback_button_test.exs
CHANGED
@@ -4,42 +4,62 @@ defmodule Medicode.FeedbackButtonTest do
|
|
4 |
import Phoenix.LiveViewTest
|
5 |
|
6 |
import Medicode.{
|
|
|
7 |
TranscriptionChunksFixtures,
|
|
|
8 |
CodeVectorsFixtures,
|
9 |
CodeFeedbacksFixtures
|
10 |
}
|
11 |
|
12 |
-
alias
|
|
|
13 |
|
14 |
describe "feedback_button" do
|
15 |
setup do
|
16 |
insert_code_vector_fixtures()
|
17 |
|
|
|
18 |
chunk = transcription_chunk_fixture()
|
19 |
code_vector = code_vector_fixture()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
positive_code_feedback = code_feedback_fixture(%{response: true})
|
21 |
negative_code_feedback = code_feedback_fixture(%{response: false})
|
22 |
|
23 |
%{
|
|
|
24 |
chunk: chunk,
|
25 |
code_vector: code_vector,
|
|
|
26 |
positive_code_feedback: positive_code_feedback,
|
27 |
negative_code_feedback: negative_code_feedback
|
28 |
}
|
29 |
end
|
30 |
|
31 |
test "renders code vector text", %{
|
|
|
32 |
chunk: chunk,
|
33 |
-
code_vector: code_vector
|
|
|
34 |
} do
|
35 |
component =
|
36 |
-
render_component(
|
|
|
37 |
code_feedback: nil,
|
38 |
chunk_id: chunk.id,
|
39 |
-
|
40 |
score: 1.0,
|
41 |
text: chunk.text,
|
42 |
-
weighting: [1.0]
|
|
|
|
|
|
|
43 |
)
|
44 |
|
45 |
assert component =~ chunk.text
|
@@ -51,36 +71,44 @@ defmodule Medicode.FeedbackButtonTest do
|
|
51 |
end
|
52 |
|
53 |
test "renders feedback button as selected for user with positive code feedback", %{
|
|
|
54 |
chunk: chunk,
|
55 |
-
|
56 |
positive_code_feedback: code_feedback
|
57 |
} do
|
58 |
component =
|
59 |
-
render_component(
|
60 |
-
|
61 |
chunk_id: chunk.id,
|
62 |
-
|
63 |
score: 1.0,
|
64 |
text: chunk.text,
|
65 |
-
weighting: [1.0]
|
|
|
|
|
|
|
66 |
)
|
67 |
|
68 |
assert component =~ ~s(<button data-feedback="positive")
|
69 |
end
|
70 |
|
71 |
test "renders feedback button as de-selected for user with negative code feedback", %{
|
|
|
72 |
chunk: chunk,
|
73 |
-
|
74 |
negative_code_feedback: code_feedback
|
75 |
} do
|
76 |
component =
|
77 |
-
render_component(
|
78 |
-
|
79 |
chunk_id: chunk.id,
|
80 |
-
|
81 |
score: 1.0,
|
82 |
text: chunk.text,
|
83 |
-
weighting: [1.0]
|
|
|
|
|
|
|
84 |
)
|
85 |
|
86 |
assert component =~ ~s(<button data-feedback="negative")
|
|
|
4 |
import Phoenix.LiveViewTest
|
5 |
|
6 |
import Medicode.{
|
7 |
+
AccountsFixtures,
|
8 |
TranscriptionChunksFixtures,
|
9 |
+
TranscriptionChunkCodeVectorsFixtures,
|
10 |
CodeVectorsFixtures,
|
11 |
CodeFeedbacksFixtures
|
12 |
}
|
13 |
|
14 |
+
alias Medicode.Repo
|
15 |
+
alias MedicodeWeb.Components.TranscriptionTextCodingsComponent
|
16 |
|
17 |
describe "feedback_button" do
|
18 |
setup do
|
19 |
insert_code_vector_fixtures()
|
20 |
|
21 |
+
user = user_fixture()
|
22 |
chunk = transcription_chunk_fixture()
|
23 |
code_vector = code_vector_fixture()
|
24 |
+
|
25 |
+
transcription_chunk_code_vector =
|
26 |
+
transcription_chunk_code_vector_fixture(%{
|
27 |
+
chunk_id: chunk.id,
|
28 |
+
code_vector_id: code_vector.id
|
29 |
+
})
|
30 |
+
|> Repo.preload([:code_vector, :assigned_by_user])
|
31 |
+
|
32 |
positive_code_feedback = code_feedback_fixture(%{response: true})
|
33 |
negative_code_feedback = code_feedback_fixture(%{response: false})
|
34 |
|
35 |
%{
|
36 |
+
user: user,
|
37 |
chunk: chunk,
|
38 |
code_vector: code_vector,
|
39 |
+
transcription_chunk_code_vector: transcription_chunk_code_vector,
|
40 |
positive_code_feedback: positive_code_feedback,
|
41 |
negative_code_feedback: negative_code_feedback
|
42 |
}
|
43 |
end
|
44 |
|
45 |
test "renders code vector text", %{
|
46 |
+
user: user,
|
47 |
chunk: chunk,
|
48 |
+
code_vector: code_vector,
|
49 |
+
transcription_chunk_code_vector: transcription_chunk_code_vector
|
50 |
} do
|
51 |
component =
|
52 |
+
render_component(TranscriptionTextCodingsComponent,
|
53 |
+
id: transcription_chunk_code_vector.id,
|
54 |
code_feedback: nil,
|
55 |
chunk_id: chunk.id,
|
56 |
+
code_vectors_with_feedback: [{transcription_chunk_code_vector, nil}],
|
57 |
score: 1.0,
|
58 |
text: chunk.text,
|
59 |
+
weighting: [1.0],
|
60 |
+
assigned_by_user: nil,
|
61 |
+
current_user: user,
|
62 |
+
myself: transcription_chunk_code_vector.id
|
63 |
)
|
64 |
|
65 |
assert component =~ chunk.text
|
|
|
71 |
end
|
72 |
|
73 |
test "renders feedback button as selected for user with positive code feedback", %{
|
74 |
+
user: user,
|
75 |
chunk: chunk,
|
76 |
+
transcription_chunk_code_vector: transcription_chunk_code_vector,
|
77 |
positive_code_feedback: code_feedback
|
78 |
} do
|
79 |
component =
|
80 |
+
render_component(TranscriptionTextCodingsComponent,
|
81 |
+
id: transcription_chunk_code_vector.id,
|
82 |
chunk_id: chunk.id,
|
83 |
+
code_vectors_with_feedback: [{transcription_chunk_code_vector, code_feedback}],
|
84 |
score: 1.0,
|
85 |
text: chunk.text,
|
86 |
+
weighting: [1.0],
|
87 |
+
assigned_by_user: nil,
|
88 |
+
current_user: user,
|
89 |
+
myself: transcription_chunk_code_vector.id
|
90 |
)
|
91 |
|
92 |
assert component =~ ~s(<button data-feedback="positive")
|
93 |
end
|
94 |
|
95 |
test "renders feedback button as de-selected for user with negative code feedback", %{
|
96 |
+
user: user,
|
97 |
chunk: chunk,
|
98 |
+
transcription_chunk_code_vector: transcription_chunk_code_vector,
|
99 |
negative_code_feedback: code_feedback
|
100 |
} do
|
101 |
component =
|
102 |
+
render_component(TranscriptionTextCodingsComponent,
|
103 |
+
id: transcription_chunk_code_vector.id,
|
104 |
chunk_id: chunk.id,
|
105 |
+
code_vectors_with_feedback: [{transcription_chunk_code_vector, code_feedback}],
|
106 |
score: 1.0,
|
107 |
text: chunk.text,
|
108 |
+
weighting: [1.0],
|
109 |
+
assigned_by_user: nil,
|
110 |
+
current_user: user,
|
111 |
+
myself: transcription_chunk_code_vector.id
|
112 |
)
|
113 |
|
114 |
assert component =~ ~s(<button data-feedback="negative")
|
test/support/fixtures/transcription_chunk_code_vectors_fixtures.ex
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
defmodule Medicode.TranscriptionChunkCodeVectorsFixtures do
|
2 |
+
@moduledoc """
|
3 |
+
This module defines test helpers for creating %TranscriptionChunkCodeVector{}
|
4 |
+
entities via the `Medicode.Transcriptions` context.
|
5 |
+
"""
|
6 |
+
|
7 |
+
import Medicode.TranscriptionChunksFixtures
|
8 |
+
import Medicode.CodeVectorsFixtures
|
9 |
+
|
10 |
+
@doc """
|
11 |
+
Generate a transcription chunk code vector.
|
12 |
+
"""
|
13 |
+
def transcription_chunk_code_vector_fixture(attrs \\ %{}) do
|
14 |
+
transcription_chunk_id =
|
15 |
+
cond do
|
16 |
+
Map.has_key?(attrs, :transcription_chunk_id) -> attrs.transcription_chunk_id
|
17 |
+
Map.has_key?(attrs, :transcription_chunk) -> attrs.transcription_chunk
|
18 |
+
true -> transcription_chunk_fixture().id
|
19 |
+
end
|
20 |
+
|
21 |
+
code_vector_id =
|
22 |
+
cond do
|
23 |
+
Map.has_key?(attrs, :code_vector_id) -> attrs.code_vector_id
|
24 |
+
Map.has_key?(attrs, :code_vector) -> attrs.code_vector
|
25 |
+
true -> code_vector_fixture().id
|
26 |
+
end
|
27 |
+
|
28 |
+
{:ok, transcription_chunk_code_vector} =
|
29 |
+
attrs
|
30 |
+
|> Enum.into(%{
|
31 |
+
transcription_chunk_id: transcription_chunk_id,
|
32 |
+
code_vector_id: code_vector_id,
|
33 |
+
cosine_similarity: 1.0
|
34 |
+
})
|
35 |
+
|> Medicode.Transcriptions.upsert_code_vector_for_transcription_chunk()
|
36 |
+
|
37 |
+
transcription_chunk_code_vector
|
38 |
+
end
|
39 |
+
end
|