diff --git a/test/controllers/contact_controller_test.rb b/test/controllers/contact_controller_test.rb index 99fd3b0eb2d325d8683fb62c14181c3daa18d50d..112d87bd84c3ecca95254f5da266f48a268d35d0 100644 --- a/test/controllers/contact_controller_test.rb +++ b/test/controllers/contact_controller_test.rb @@ -1,8 +1,20 @@ require 'test_helper' -#TODO: write controller test for contact form class ContactControllerTest < ActionDispatch::IntegrationTest - test "should get contactus form" do - + test 'should get contactus form' do + get getintouch_url + assert_response(:success) + assert_select 'form#ContactForm' do + assert_select 'input', 6 # text fields and the sub button + end + end + test 'should accept a properly completed request' do + post submit_contact_url, params: {name: 'Alexis', email: 'lexieb101@gmail.com', telephone: '07809179117', message: '5ecurep@55w0rd'} + assert_redirected_to(root_url) + assert_equal "We'll be in touch", flash[:notice] + end + test 'should reject a malformed request' do + post submit_contact_url, params: {name: 'Alexis', email: '', telephone: '07809179117', message: '5ecurep@55w0rd'} + assert_redirected_to(root_url) + assert_equal 'Supply an email address for response', flash[:alert] end - end