Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions spec/system/ai_bot/artifact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,26 @@
find(".ai-artifact__click-to-run button").click

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

expect(page).to have_css(iframe_selector)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are doing a find at tnetx step so I don't think that's necessary, we will fail on the find if it doesn’t exist


iframe_element = find(iframe_selector)
expect(iframe_element["data-custom-message"]).to eq("hello-from-post")
expect(iframe_element["data-post-author-id"]).to eq(author.id.to_s)
expect(artifact_element).to have_css("iframe[data-custom-message='hello-from-post']")
expect(artifact_element).to have_css("iframe[data-post-author-id='#{author.id}']")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't check data attributes on the element itself in capybara, so the best way is to do this.


# note: artifacts are within nested iframes for security reasons
page.within_frame(iframe_element) do
iframe_element = artifact_element.find("iframe")
within_frame(iframe_element) do
inner_iframe = find("iframe")
page.within_frame(inner_iframe) do
data_display_element = find("#data-display")

expect(data_display_element.text).not_to be_empty
expect(data_display_element.text).not_to eq("Waiting for data...")
expect(data_display_element.text).not_to include("Error:")
within_frame(inner_iframe) do
data_selector = "#data-display"
expect(page).to have_selector(data_selector, text: /.+/)
expect(page).to have_no_selector(data_selector, text: "Waiting for data...")
expect(page).to have_no_selector(data_selector, text: "Error:")
Comment on lines +62 to +64
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to use rspec matcher on dom elements, they are not waiting correctly


artifact_data_json = data_display_element.text
artifact_data_json = find(data_selector).text
artifact_data = JSON.parse(artifact_data_json)

expect(artifact_data["customMessage"]).to eq("hello-from-post")
expect(artifact_data["postAuthorId"]).to eq(author.id.to_s)

expect(artifact_data["username"]).to eq(user.username)
end
end
Expand Down
Loading