Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 6b9da00

Browse files
committed
DEV: rewrites artifact spec with capybara waiters
Generally speaking we never want to do: ``` expect(element.text).to eq("foo") ``` As these are rspec matchers and do not add further Capybara-style waiting specifically for the text content to become present.
1 parent 3ac2359 commit 6b9da00

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

spec/system/ai_bot/artifact_spec.rb

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,26 @@
4848
find(".ai-artifact__click-to-run button").click
4949

5050
artifact_element_selector = ".ai-artifact[data-ai-artifact-id='#{ai_artifact.id}']"
51-
iframe_selector = "#{artifact_element_selector} iframe"
51+
artifact_element = find(artifact_element_selector)
5252

53-
expect(page).to have_css(iframe_selector)
54-
55-
iframe_element = find(iframe_selector)
56-
expect(iframe_element["data-custom-message"]).to eq("hello-from-post")
57-
expect(iframe_element["data-post-author-id"]).to eq(author.id.to_s)
53+
expect(artifact_element).to have_css("iframe[data-custom-message='hello-from-post']")
54+
expect(artifact_element).to have_css("iframe[data-post-author-id='#{author.id}']")
5855

5956
# note: artifacts are within nested iframes for security reasons
60-
page.within_frame(iframe_element) do
57+
iframe_element = artifact_element.find("iframe")
58+
within_frame(iframe_element) do
6159
inner_iframe = find("iframe")
62-
page.within_frame(inner_iframe) do
63-
data_display_element = find("#data-display")
64-
65-
expect(data_display_element.text).not_to be_empty
66-
expect(data_display_element.text).not_to eq("Waiting for data...")
67-
expect(data_display_element.text).not_to include("Error:")
60+
within_frame(inner_iframe) do
61+
data_selector = "#data-display"
62+
expect(page).to have_selector(data_selector, text: /.+/)
63+
expect(page).to have_no_selector(data_selector, text: "Waiting for data...")
64+
expect(page).to have_no_selector(data_selector, text: "Error:")
6865

69-
artifact_data_json = data_display_element.text
66+
artifact_data_json = find(data_selector).text
7067
artifact_data = JSON.parse(artifact_data_json)
7168

7269
expect(artifact_data["customMessage"]).to eq("hello-from-post")
7370
expect(artifact_data["postAuthorId"]).to eq(author.id.to_s)
74-
7571
expect(artifact_data["username"]).to eq(user.username)
7672
end
7773
end

0 commit comments

Comments
 (0)