summaryrefslogtreecommitdiff
path: root/engines/support/test/integration/create_ticket_test.rb
blob: fcdc6b8fde593e211ba1a237515ccaa3dcedcca9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require 'test_helper'

class CreateTicketTest < BrowserIntegrationTest

  setup do
    @testcode = InviteCode.new
    @testcode.save!
  end

  teardown do
    Ticket.last.destroy if Ticket.last.present?
  end

  test "can submit ticket anonymously" do
    submit_ticket
    assert_ticket_submitted
  end

  test "get help when creating ticket with invalid email" do
    submit_ticket email: 'invalid data',
      regarding_user: 'some user'
    assert_invalid_submission
    assert_equal 'invaliddata', find_field('Email').value
    assert_equal 'some user', find_field('Regarding User').value
    resubmit_ticket email: 'valid@data.info'
    assert_ticket_submitted
  end

  test "can resubmit after missing description" do
    submit_ticket description: ''
    assert page.has_content?("can't be blank")
    resubmit_ticket description: 'okay, okay... you get a subject'
    assert_ticket_submitted
  end

  test "prefills fields" do
    login FactoryGirl.create(:premium_user, :invite_code => @testcode.invite_code)
    visit '/'
    click_on "Support Tickets"
    click_on "New Ticket"
    email = "#{@user.login}@#{APP_CONFIG[:domain]}"
    assert_equal email, find_field('Email').value
    assert_equal @user.login, find_field('Regarding User').value
  end

  test "no prefill of email without email service" do
    login
    visit '/'
    click_on "Support Tickets"
    click_on "New Ticket"
    assert_equal "", find_field('Email').value
    assert_equal @user.login, find_field('Regarding User').value
  end

  test "cleared email field should remain clear" do
    login FactoryGirl.create(:premium_user, :invite_code => @testcode.invite_code)
    visit '/'
    click_on "Support Tickets"
    click_on "New Ticket"
    fill_in 'Subject', with: 'test ticket'
    fill_in 'Email', with: ''
    fill_in 'Description', with: 'description of the problem goes here'
    click_on 'Submit Ticket'
    ticket = Ticket.last
    assert_equal "", ticket.email
    ticket.destroy
  end

  def submit_ticket(email: nil, regarding_user: nil, description: 'some content')
    visit '/'
    click_on 'Get Help'
    fill_in 'Subject', with: 'test ticket'
    fill_in 'Email', with: email if email
    fill_in 'Regarding User', with: regarding_user if regarding_user
    fill_in 'Description', with: description
    click_on 'Submit Ticket'
  end

  def assert_invalid_submission
    assert page.has_content?("is invalid")
  end

  def resubmit_ticket(email: nil, description: nil)
    fill_in 'Email', with: email if email
    fill_in 'Description', with: description if description
    click_on 'Submit Ticket'
  end

  def assert_ticket_submitted
    assert page.has_content?("Ticket was successfully created.")
    assert page.has_content?("You can later access this ticket at the URL")
    assert page.has_content?(current_url)
  end
end