# frozen_string_literal: true

# This code is part of Karafka Pro, a commercial component not licensed under LGPL.
# See LICENSE for details.

RSpec.describe_current do
  subject(:app) { Karafka::Web::Pro::Ui::App }

  let(:topic) { create_topic(partitions: partitions) }
  let(:partitions) { 1 }

  describe '#show' do
    context 'when trying to read configs of a non-existing topic' do
      before { get "topics/#{generate_topic_name}/replication" }

      it do
        expect(response).not_to be_ok
        expect(status).to eq(404)
      end
    end

    context 'when getting replication of an existing topic with single partition' do
      before { get "topics/#{topic}/replication" }

      it do
        expect(response).to be_ok
        expect(body).to include(breadcrumbs)
        expect(body).not_to include(pagination)
        expect(body).not_to include(support_message)
        expect(body).to include(topic)
        expect(body).to include('Replica Count')
        expect(body).to include('In Sync Brokers')
      end

      it 'shows partition details' do
        expect(body).to include('Partition')
        expect(body).to include('Leader')
        expect(body).to include('0') # First partition
      end
    end

    context 'when topic has multiple partitions' do
      let(:partitions) { 5 }

      before { get "topics/#{topic}/replication" }

      it 'displays all partitions' do
        expect(response).to be_ok
        expect(body).to include(topic)
        expect(body).to include('0')
        expect(body).to include('1')
        expect(body).to include('2')
        expect(body).to include('3')
        expect(body).to include('4')
      end

      it 'shows replication details for each partition' do
        expect(body).to include('Replica Count')
        expect(body).to include('In Sync Brokers')
        expect(body).to include('Leader')
      end
    end
  end
end
