|
| 1 | +require "test_helper" |
| 2 | + |
| 3 | +class Games::ShareCardRendererTest < ActiveSupport::TestCase |
| 4 | + test "card markup repeats the badges, the comment and the free spots of the games list" do |
| 5 | + game = games(:feed_upcoming) |
| 6 | + # Корт из фикстуры разрешает не любое покрытие, а карточке важны только атрибуты игры. |
| 7 | + game.assign_attributes( |
| 8 | + kind: "training", |
| 9 | + sport: "tennis", |
| 10 | + surface: "hard", |
| 11 | + environment: "outdoor", |
| 12 | + skill_level: "intermediate", |
| 13 | + with_coach: true, |
| 14 | + recurring: true, |
| 15 | + urgent_player_search: true, |
| 16 | + comment: "Ракетки и мячи свои" |
| 17 | + ) |
| 18 | + |
| 19 | + svg = markup_for(game) |
| 20 | + |
| 21 | + assert_includes svg, "Feed Court" |
| 22 | + assert_includes svg, "Tennis" |
| 23 | + assert_includes svg, "Intermediate" |
| 24 | + assert_includes svg, "Hard" |
| 25 | + assert_includes svg, "Outdoor" |
| 26 | + assert_includes svg, I18n.t("games.badges.training", locale: :en) |
| 27 | + assert_includes svg, I18n.t("games.badges.coach", locale: :en) |
| 28 | + assert_includes svg, I18n.t("games.badges.weekly", locale: :en) |
| 29 | + assert_includes svg, I18n.t("games.badges.player_search", locale: :en) |
| 30 | + assert_includes svg, "Ракетки и мячи свои" |
| 31 | + assert_includes svg, I18n.t("games.card.spots_left", count: 4, locale: :en) |
| 32 | + end |
| 33 | + |
| 34 | + test "weather badge is skipped for indoor games" do |
| 35 | + game = games(:feed_upcoming) |
| 36 | + game.assign_attributes(environment: "indoor") |
| 37 | + |
| 38 | + called = false |
| 39 | + stub_singleton(Weather::GoogleForecast, :for_game, ->(*) { called = true; nil }) do |
| 40 | + Games::ShareCardRenderer.send(:svg_markup, game, locale: :en) |
| 41 | + end |
| 42 | + |
| 43 | + assert_not called, "indoor game must not go to the forecast" |
| 44 | + end |
| 45 | + |
| 46 | + test "renders a png" do |
| 47 | + data = markup_free_render(games(:feed_upcoming)) |
| 48 | + |
| 49 | + assert_equal "\x89PNG\r\n\x1A\n".b, data[0, 8].b |
| 50 | + end |
| 51 | + |
| 52 | + private |
| 53 | + |
| 54 | + def markup_for(game) |
| 55 | + stub_singleton(Weather::GoogleForecast, :for_game, nil) do |
| 56 | + Games::ShareCardRenderer.send(:svg_markup, game, locale: :en) |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + def markup_free_render(game) |
| 61 | + stub_singleton(Weather::GoogleForecast, :for_game, nil) do |
| 62 | + Games::ShareCardRenderer.render_data(game, locale: :en) |
| 63 | + end |
| 64 | + end |
| 65 | +end |
0 commit comments