Skip to content

Commit

Permalink
Merge branch 'main' of github.com:allyourbot/hostedgpt into check-con…
Browse files Browse the repository at this point in the history
…nection
  • Loading branch information
mattlindsey committed Dec 19, 2024
2 parents 6b1cbad + 07af6cd commit 075827c
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 19 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ group :test do
gem "selenium-webdriver"
gem "minitest-stub_any_instance"
gem "rails-controller-testing"
gem "minitest-retry"
gem "webmock"
end
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ GEM
mini_magick (4.13.2)
mini_mime (1.1.5)
minitest (5.25.1)
minitest-retry (0.2.3)
minitest (>= 5.0)
minitest-stub_any_instance (1.0.3)
mize (0.4.1)
protocol (~> 2.0)
Expand Down Expand Up @@ -507,6 +509,7 @@ DEPENDENCIES
gemini-ai (~> 4.2.0)
image_processing (~> 1.13.0)
importmap-rails
minitest-retry
minitest-stub_any_instance
name_of_person
omniauth (~> 2.1)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/conversations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ConversationsController < ApplicationController
before_action :set_conversation, only: [:show, :edit, :update, :destroy]
before_action :set_conversation
before_action :set_nav_assistants

def index
Expand Down Expand Up @@ -37,7 +37,7 @@ def set_nav_assistants
end

def set_conversation
@conversation = Current.user.conversations.find(params[:id])
@conversation = Current.user.conversations.find_by(id: params[:id] || params[:conversation_id])
end

def conversation_params
Expand Down
2 changes: 1 addition & 1 deletion app/views/messages/_message.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ end %>
> <!-- this inner div is replaced during streaming updates (inner_html of dom_id message) -->
<!-- Left Column -->
<div class="w-7 ml-1 flex">
<div class="w-6 ml-1 flex">
<%= render_avatar_for(message) %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/messages/_nav_column.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
</section>

<turbo-frame id="nav-conversations"
src="<%= conversations_path %>"
src="<%= conversations_path(conversation_id: @conversation&.id) %>"
loading="lazy"
/>
4 changes: 2 additions & 2 deletions test/application_system_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ def click_element(selector_or_element, wait: Capybara.default_max_wait_time)
end

def get_scroll_position(selector)
page.evaluate_script("document.querySelector('#{selector}').scrollTop + document.querySelector('#{selector}').clientHeight")
page.evaluate_script("document.querySelector('#{selector}').scrollTop + document.querySelector('#{selector}').clientHeight").to_i
end

def get_bottom_position(selector)
page.evaluate_script("document.querySelector('#{selector}').scrollHeight")
page.evaluate_script("document.querySelector('#{selector}').scrollHeight").to_i
end

def scroll_to_bottom(selector)
Expand Down
23 changes: 12 additions & 11 deletions test/system/conversations/messages/images_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ConversationMessagesImagesTest < ApplicationSystemTestCase
end

test "images eventually render in messages WHEN NOT pre-processed, clicking opens modal" do
stimulate_image_variant_processing do
simulate_image_variant_processing do
visit_and_scroll_wait conversation_messages_path(@conversation)

image_msg = find_messages.third
Expand Down Expand Up @@ -86,11 +86,11 @@ class ConversationMessagesImagesTest < ApplicationSystemTestCase
end

test "ensure images display a spinner initially if they get a 404 and then eventually get replaced with the image" do
stimulate_image_variant_processing do
simulate_image_variant_processing do
visit_and_scroll_wait conversation_messages_path(@conversation)

image_msg = find_messages.third
image_btn = image_msg.find_role("image-preview")
image_btn = image_msg.find_role("image-preview")
loader = image_btn.find_role("image-loader")
img = image_btn.find("img", visible: :all)
modal_container = image_msg.find_role("image-modal")
Expand All @@ -103,15 +103,14 @@ class ConversationMessagesImagesTest < ApplicationSystemTestCase
refute img.visible?

image_btn.click

2.times do
sleep 0.1
sleep 0.5 if !modal_loader.visible?
sleep 0.1
image_btn.click if !modal_loader.visible?
end # TODO: sometimes modal has not popped up after clicking, why?? Try 2x times before failing the test.

assert_true "modal image loader should be visible", wait: 0.6 do
assert_true "modal image loader should be visible", wait: 3 do
modal_loader.visible?
end
refute modal_img.visible?
Expand All @@ -134,7 +133,7 @@ class ConversationMessagesImagesTest < ApplicationSystemTestCase
end

test "ensure page scrolls back down to the bottom after an image pops in late" do
stimulate_image_variant_processing do
simulate_image_variant_processing do
visit_and_scroll_wait conversation_messages_path(@conversation)

image_msg = find_messages.third
Expand All @@ -156,7 +155,7 @@ class ConversationMessagesImagesTest < ApplicationSystemTestCase

test "images in previous messages remain after submitting a new message, they should not display a new spinner" do
image_msg = img = nil
stimulate_image_variant_processing do
simulate_image_variant_processing do
visit_and_scroll_wait conversation_messages_path(@conversation)

image_msg = find_messages.third
Expand Down Expand Up @@ -189,10 +188,12 @@ def preprocess_all_variants!
end
end

def stimulate_image_variant_processing(&block)
Document.stub_any_instance(:has_file_variant_processed?, false) do
ActiveStorage::PostgresqlController.stub_any_instance(:decode_verified_key, simulate_not_preprocessed) do
yield block
def simulate_image_variant_processing(&block)
stub_custom_config_value(:app_url, "not_nil") do
Document.stub_any_instance(:has_file_variant_processed?, false) do
ActiveStorage::PostgresqlController.stub_any_instance(:decode_verified_key, simulate_not_preprocessed) do
yield block
end
end
end
end
Expand Down
2 changes: 0 additions & 2 deletions test/system/messages/nav_column_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ class NavColumnTest < ApplicationSystemTestCase
end

test "clicking conversation in the left column updates the right and preserves scroll position of the left" do
resize_browser_to(1400, 500)
page.execute_script("document.querySelector('#nav-scrollable').scrollTop = 100") # scroll the nav column down slightly

assert_did_not_scroll "#nav-scrollable" do
click_text conversations(:attachment).title
end
Expand Down
14 changes: 14 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require_relative "../config/environment"
require "rails/test_help"
require "minitest/autorun"
require "minitest/retry"
require "pry"
require "webmock/minitest"

Expand All @@ -21,11 +22,20 @@ def exists?
end
end

Minitest::Retry.use!(
retry_count: 1,
verbose: true,
exceptions_to_retry: [Net::ReadTimeout, Minitest::Assertion]
)

class ActionDispatch::IntegrationTest
include Rails.application.routes.url_helpers

Capybara.default_max_wait_time = 10

WebMock.disable_net_connect!(allow_localhost: true)


def login_as(user_or_person, password = "secret")
user = if user_or_person.is_a?(Person)
user_or_person.user
Expand Down Expand Up @@ -59,3 +69,7 @@ class TestCase
fixtures :all
end
end

class ActionDispatch::SystemTestCase
parallelize(workers: Etc.nprocessors/2)
end

0 comments on commit 075827c

Please sign in to comment.