Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Select and view the newest email if "autoselect" checkbox is turned on #336

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions assets/javascripts/mailcatcher.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ class MailCatcher
selectedMessage: ->
$("#messages tr.selected").data "message-id"

autoselectLatestMessage: ->
$("input[name='autoselect']").attr('checked') == true

searchMessages: (query) ->
selector = (":icontains('#{token}')" for token in query.split /\s+/).join("")
$rows = $("#messages tbody tr")
Expand Down Expand Up @@ -298,6 +301,8 @@ class MailCatcher
@websocket = new WebSocket("#{protocol}://#{window.location.host}/messages")
@websocket.onmessage = (event) =>
@addMessage $.parseJSON event.data
if @autoselectLatestMessage()
@loadMessage $("#messages tbody tr[data-message-id]:first").data("message-id")

subscribePoll: ->
unless @refreshInterval?
Expand Down
4 changes: 4 additions & 0 deletions assets/stylesheets/mailcatcher.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,7 @@ iframe
-webkit-box-flex: 1
box-flex: 1
background: #fff

.autoselect-checkbox
padding: 0
margin: 0 4px 0 0
29 changes: 29 additions & 0 deletions spec/acceptance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ def message_row_element
messages_element.find_element(:xpath, ".//table/tbody/tr[1]")
end

def message_selected_row_element
begin
messages_element.find_element(:css, "table tbody tr.selected")
rescue Selenium::WebDriver::Error::NoSuchElementError
return nil
end
end

def message_from_element
message_row_element.find_element(:xpath, ".//td[1]")
end
Expand All @@ -70,6 +78,11 @@ def message_subject_element
message_row_element.find_element(:xpath, ".//td[3]")
end

def selected_message_subject_element
# if not found, message_selected_row_element returns nil... and it goes wonky from there
message_selected_row_element.find_element(:xpath, ".//td[3]")
end

def message_received_element
message_row_element.find_element(:xpath, ".//td[4]")
end
Expand Down Expand Up @@ -224,4 +237,20 @@ def body_element

skip
end

it "selected newest mail when autoselect checkbox is on" do
deliver_example("plainmail")
message_selected_row_element.must_be_nil

# turn on the autoselect
selenium.find_element(:css, "input[name='autoselect']").click

# send first email
deliver_example("plainmail")
selected_message_subject_element.text.must_equal "Plain mail"

# send another
deliver_example("htmlmail")
selected_message_subject_element.text.must_equal "Test HTML Mail"
end
end
1 change: 1 addition & 0 deletions views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<h1><a href="http://mailcatcher.me" target="_blank">MailCatcher</a></h1>
<nav class="app">
<ul>
<li class="autoselect"><a href="#" title="Select incoming email"><label><input type="checkbox" name="autoselect" class="autoselect-checkbox">Autoselect</label></a></li>
<li class="search"><input type="search" name="search" placeholder="Search messages..." incremental="true" /></li>
<li class="clear"><a href="#" title="Clear all messages">Clear</a></li>
<% if MailCatcher.quittable? %>
Expand Down