require_relative '../integration_test_helper'

class ArtefactCreateTest < ActionDispatch::IntegrationTest

  setup do
    create_test_user
  end

  should "allow the use of deep slugs when creating a whitehall artefact" do
    visit "/artefacts"
    click_on "Add Whitehall artefact"

    within("form#edit_artefact") do
      fill_in "Name", :with => "British Embassy Legoland"
      fill_in "Description", :with => "Some information on the British Embassy in Legoland"
      fill_in "Slug", :with => "government/world/organisations/british-embassy-legoland"
      select "Worldwide priority", :from => "Kind"
      click_on "Save and continue editing"

      artefact = Artefact.where(:slug => 'government/world/organisations/british-embassy-legoland').last

      assert_equal "/artefacts/#{artefact.to_param}/edit", current_path 
    end

    assert page.has_link?("View on site")
    within(".alert.alert-error") do 
      assert page.has_no_css?("li"), "No form errors were expected"
    end

  end

  should "not allow the use of invalid slugs when creating a whitehall artefact" do
    visit "/artefacts"
    click_on "Add Whitehall artefact"

    within("form#edit_artefact") do
      fill_in "Name", :with => "British Embassy Legoland"
      fill_in "Description", :with => "Some information on the British Embassy in Legoland"
      fill_in "Slug", :with => "government/world/.organi$ation$/briti$h~embassy~legoland"
      select "Worldwide priority", :from => "Kind"
      click_on "Save and continue editing"
    end

    assert_equal "/artefacts", current_path
    
    within(".alert.alert-error") do
      assert page.has_content?("Slug must be usable in a URL") 
    end

  end

end

Test creating whitehall artefacts with deep slugs
Test creating whitehall artefacts with deep slugs
