require "rails_helper"

describe Shared::TagListComponent do
  let(:user_tag) { create(:tag, name: "user tag") }
  let(:ml_tag) { create(:tag, name: "machine learning tag") }
  let(:proposal) { create(:proposal, tag_list: [user_tag], ml_tag_list: [ml_tag]) }
  let(:component) { Shared::TagListComponent.new(proposal, limit: nil) }

  before do
    Setting["feature.machine_learning"] = true
    Setting["machine_learning.tags"] = true
  end

  it "displays machine learning tags when machine learning is enabled" do
    render_inline component

    expect(page).not_to have_link "user tag"
    expect(page).to have_link "machine learning tag"
    expect(page).to have_content "Content generated by AI / Machine Learning"
  end

  it "displays user tags when machine learning is disabled" do
    Setting["feature.machine_learning"] = false

    render_inline component

    expect(page).to have_link "user tag"
    expect(page).not_to have_link "machine learning tag"
    expect(page).not_to have_content "Content generated by AI / Machine Learning"
  end

  it "displays user tags when machine learning tags are disabled" do
    Setting["machine_learning.tags"] = false

    render_inline component

    expect(page).to have_link "user tag"
    expect(page).not_to have_link "machine learning tag"
    expect(page).not_to have_content "Content generated by AI / Machine Learning"
  end

  it "is not rendered when there are no tags" do
    render_inline Shared::TagListComponent.new(Proposal.new, limit: nil)

    expect(page).not_to be_rendered
  end
end
