|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe Baseballbot::Templates::Components::PickTheStick do |
| 4 | + let(:bot) { Baseballbot.new(user_agent: 'Baseballbot Tests') } |
| 5 | + let(:subreddit) do |
| 6 | + Baseballbot::Subreddit.new( |
| 7 | + { name: 'dodgers', team_code: 'LAD', team_id: 119, options: {} }, |
| 8 | + bot:, |
| 9 | + bot_account: Baseballbot::Bot.new(bot:, name: 'RSpecTestBot', access: '') |
| 10 | + ) |
| 11 | + end |
| 12 | + |
| 13 | + before { stub_requests! with_response: true } |
| 14 | + |
| 15 | + describe '#to_s' do |
| 16 | + it 'returns a fallback markdown link when team is not configured' do |
| 17 | + no_team_subreddit = Baseballbot::Subreddit.new( |
| 18 | + { name: 'baseball', team_id: nil, options: {} }, |
| 19 | + bot:, |
| 20 | + bot_account: Baseballbot::Bot.new(bot:, name: 'RSpecTestBot', access: '') |
| 21 | + ) |
| 22 | + |
| 23 | + expect(described_class.new(no_team_subreddit).to_s).to eq '[](/pickthestick "Team not configured")' |
| 24 | + end |
| 25 | + |
| 26 | + it 'renders a standings table from pick the stick data' do |
| 27 | + component = described_class.new(subreddit) |
| 28 | + |
| 29 | + data = (1..11).map do |rank| |
| 30 | + { |
| 31 | + 'ranking' => rank, |
| 32 | + 'username' => "user#{rank}", |
| 33 | + 'points' => 100 - rank, |
| 34 | + 'total_picks' => 20 + rank, |
| 35 | + 'position_change' => "+#{rank}" |
| 36 | + } |
| 37 | + end |
| 38 | + |
| 39 | + allow(component).to receive(:pick_the_stick_data).and_return(data) |
| 40 | + |
| 41 | + output = component.to_s |
| 42 | + |
| 43 | + expect(output).to include('|Rank|User|Points|Total Picks|Position Change|') |
| 44 | + expect(output).to include('|:-:|:-:|:-:|:-:|:-:|') |
| 45 | + expect(output).to include('|1|user1|99|21|+1|') |
| 46 | + expect(output).to include('|10|user10|90|30|+10|') |
| 47 | + expect(output).not_to include('|11|user11|89|31|+11|') |
| 48 | + end |
| 49 | + end |
| 50 | +end |
0 commit comments