<commit_before>require "test_helper"

class CatalogAdmin::ItemTypesTest < ActionDispatch::IntegrationTest
  test "create an item type" do
    log_in_as("<EMAIL>", "password")
    visit("/two/admin")
    click_on("New item type")
    fill_in("item_type[name_en]", :with => "Book")
    fill_in("item_type[name_plural_en]", :with => "Books")
    fill_in("Slug (plural)", :with => "books")

    assert_difference("catalogs(:two).item_types.count") do
      click_on("Create item type")
    end

    type = catalogs(:two).item_types.where(:slug => "books").first!
    assert_equal("Book", type.name)
    assert_equal("Books", type.name_plural)
  end

  test "edit an item type" do
    log_in_as("<EMAIL>", "password")
    visit("/two/admin")
    click_on("Author")
    click_on("Edit item type")
    fill_in("item_type[name_en]", :with => "Writer")

    assert_no_difference("catalogs(:two).item_types.count") do
      click_on("Save item type")
    end

    type = item_types(:two_author)
    assert_equal("Writer", type.name)
  end

  test "delete an item type" do
    log_in_as("<EMAIL>", "password")
    visit("/two/admin")
    click_on("Author")
    click_on("Edit item type")

    assert_difference("catalogs(:two).item_types.count", -1) do
      click_on("Delete this item type")
    end

    type = item_types(:two_author)
    refute(type.active?)
  end
end
<commit_msg>Test for data entry with no item types defined<commit_after>require "test_helper"

class CatalogAdmin::ItemTypesTest < ActionDispatch::IntegrationTest
  test "create an item type" do
    log_in_as("<EMAIL>", "password")
    visit("/two/admin")
    click_on("New item type")
    fill_in("item_type[name_en]", :with => "Book")
    fill_in("item_type[name_plural_en]", :with => "Books")
    fill_in("Slug (plural)", :with => "books")

    assert_difference("catalogs(:two).item_types.count") do
      click_on("Create item type")
    end

    type = catalogs(:two).item_types.where(:slug => "books").first!
    assert_equal("Book", type.name)
    assert_equal("Books", type.name_plural)
  end

  test "edit an item type" do
    log_in_as("<EMAIL>", "password")
    visit("/two/admin")
    click_on("Author")
    click_on("Edit item type")
    fill_in("item_type[name_en]", :with => "Writer")

    assert_no_difference("catalogs(:two).item_types.count") do
      click_on("Save item type")
    end

    type = item_types(:two_author)
    assert_equal("Writer", type.name)
  end

  test "delete an item type" do
    log_in_as("<EMAIL>", "password")
    visit("/two/admin")
    click_on("Author")
    click_on("Edit item type")

    assert_difference("catalogs(:two).item_types.count", -1) do
      click_on("Delete this item type")
    end

    type = item_types(:two_author)
    refute(type.active?)
  end

  test "data entry without item types defined" do
    log_in_as("<EMAIL>", "password")
    visit("/admin")
    click_on("New catalog")
    fill_in("Name", :with => "Integration test empty catalog")
    fill_in("Slug", :with => "int-test-empty-catalog")
    select("English", :from => "Primary language")
    click_on("Create catalog")
    visit('/int-test-empty-catalog/admin')
    click_on("Data")
    assert(page.has_content?("No item types are defined yet."))
  end
end

{'fraction_non_alphanumeric': 0.1566635887965528, 'fraction_numerical': 0.0006155740227762388, 'mean_word_length': 3.977029096477795, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3394918', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1072, 'n_words': 233}