Skip to content

A platform for community discussion. Free, open, simple.

1.0 KB
Raw Blame
# frozen_string_literal: true

describe "Edit Category General" do
  fab!(:admin)
  fab!(:category)
  let(:category_page) { PageObjects::Pages::Category.new }
  let(:form) { PageObjects::Components::FormKit.new(".form-kit") }

  before { sign_in(admin) }

  context "when changing background color" do
    it "displays an error when the hex code is invalid" do
      category_page.visit_general(category)

      form.field("color").fill_in("ABZ")
      category_page.save_settings
      expect(form.field("color")).to have_errors(
        I18n.t("js.category.color_validations.non_hexdecimal"),
      )

      form.field("color").fill_in("A")
      category_page.save_settings
      expect(form.field("color")).to have_errors(
        I18n.t("js.category.color_validations.incorrect_length"),
      )
    end

    it "saves successfully when the hex code is valid" do
      category_page.visit_general(category)

      form.field("color").fill_in("AB1")
      category_page.save_settings
      expect(form.field("color")).to have_no_errors
    end
  end
end