current_color_spec.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket: #current_state_color' do # rubocop:disable RSpec/DescribeClass
  4. let(:ticket) { create(:ticket) }
  5. shared_examples 'returns correct hex color code' do |expected_color_code|
  6. it "returns correct hex color code #{expected_color_code}" do
  7. expect(ticket.current_state_color).to eq(expected_color_code)
  8. end
  9. end
  10. context 'when state is open' do
  11. before do
  12. ticket.update!(state: Ticket::State.find_by(name: 'open'))
  13. end
  14. include_examples 'returns correct hex color code', '#faab00'
  15. end
  16. context 'when state is new' do
  17. before do
  18. ticket.update!(state: Ticket::State.find_by(name: 'new'))
  19. end
  20. include_examples 'returns correct hex color code', '#faab00'
  21. end
  22. context 'when state is closed' do
  23. before do
  24. ticket.update!(state: Ticket::State.find_by(name: 'closed'))
  25. end
  26. include_examples 'returns correct hex color code', '#38ad69'
  27. end
  28. context 'when state is pending reminder' do
  29. before do
  30. ticket.update!(state: Ticket::State.find_by(name: 'open'))
  31. end
  32. context 'when pending time is reached' do
  33. before do
  34. ticket.update!(state: Ticket::State.find_by(name: 'pending reminder'), pending_time: 1.day.ago)
  35. end
  36. include_examples 'returns correct hex color code', '#faab00'
  37. end
  38. context 'when pending time is not reached' do
  39. before do
  40. ticket.update!(state: Ticket::State.find_by(name: 'pending reminder'), pending_time: 1.day.since)
  41. end
  42. include_examples 'returns correct hex color code', '#000000'
  43. end
  44. end
  45. context 'when ticket is escalated' do
  46. before do
  47. ticket.update!(state: Ticket::State.find_by(name: 'pending reminder'), escalation_at: 1.day.since)
  48. end
  49. include_examples 'returns correct hex color code', '#000000'
  50. end
  51. end