Files
redmine_qbo_labels/test/integration/label_jobs_test.rb
T
rickyandClaude Opus 5.5 3e29f14f76 New plugin: print part labels on a Brother QL printer
Print label in the top-right actions of issues, estimates and invoices
prints the customer's last name and the PO number (W/E/I + number) in big
bold letters on a 62mm continuous roll, with a preview of the label and
its status until it's printed. A print agent on the printer's network
(redmine_qbo_label_agent) asks Redmine for labels every couple of seconds
with its printer's token, so labels print from anywhere.

Administration » Label printers: printers, agent tokens and status,
recent labels. Settings: label lengths, capitals, poll interval, how long
a label waits for an offline agent, and logging the agents' requests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 08:42:16 -05:00

93 lines
3.9 KiB
Ruby

#The MIT License (MIT)
#
#Copyright (c) 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require File.expand_path('../test_helper', __dir__)
class LabelJobsTest < Redmine::IntegrationTest
include QboLabelsTestHelper
fixtures :projects, :users, :email_addresses, :members, :member_roles, :roles, :issues, :trackers,
:projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :workflows
def setup
@printer, = create_printer
Role.find(1).add_permission!(:print_labels)
end
def test_print_dialog_for_an_issue
log_user('jsmith', 'jsmith')
get '/label_jobs/new', params: { source_type: 'issue', source_id: 1 }, xhr: true
assert_response :success
assert_includes response.body, 'W1'
assert_includes response.body, 'qbo-label-preview'
end
def test_printing_needs_the_permission
log_user('dlopper', 'foo') # Developer: no Print labels
get '/label_jobs/new', params: { source_type: 'issue', source_id: 1 }, xhr: true
assert_response :forbidden
end
def test_print_dialog_for_something_unseen
log_user('jsmith', 'jsmith')
get '/label_jobs/new', params: { source_type: 'issue', source_id: 999 }, xhr: true
assert_response :not_found
end
def test_print_queues_the_label
log_user('jsmith', 'jsmith')
assert_difference 'LabelJob.count', 1 do
post '/label_jobs', params: { source_type: 'issue', source_id: 1, lines: ['Smith', 'w1'], copies: '2' }, xhr: true
end
assert_response :success
job = LabelJob.last
assert_equal %w[SMITH W1], job.lines
assert_equal 2, job.copies
assert_equal @printer, job.label_printer
assert_equal 'issue', job.source_type
assert_equal '1', job.source_id
assert_includes response.body, "QboLabels.follow"
get "/label_jobs/#{job.id}", headers: { "Accept" => "application/json" }
assert_response :success
assert_equal 'queued', response.parsed_body['status']
assert_equal false, response.parsed_body['finished']
end
def test_an_empty_label_shows_the_dialog_again
log_user('jsmith', 'jsmith')
assert_no_difference 'LabelJob.count' do
post '/label_jobs', params: { source_type: 'issue', source_id: 1, lines: ['', ' '] }, xhr: true
end
assert_response :success
assert_includes response.body, 'errorExplanation'
end
def test_only_your_own_labels_can_be_followed
job = create_job(@printer, user: User.find(3))
log_user('jsmith', 'jsmith')
get "/label_jobs/#{job.id}", headers: { "Accept" => "application/json" }
assert_response :not_found
end
def test_issue_page_has_the_print_label_link
log_user('jsmith', 'jsmith')
get '/issues/1'
assert_response :success
assert_select 'template#qbo-label-issue-link a.icon-qbo-label-print[data-remote=true]'
end
def test_no_link_without_an_active_printer
@printer.update!(active: false)
log_user('jsmith', 'jsmith')
get '/issues/1'
assert_select 'template#qbo-label-issue-link', 0
end
end