Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danirod committed Jun 12, 2024
1 parent 0dc4196 commit cdb066f
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 29 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require:
- rubocop-factory_bot
- rubocop-rake
- rubocop-rspec
- rubocop-rspec_rails

AllCops:
TargetRubyVersion: '3.2'
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ end
# Test tools
group :test do
gem 'capybara', '~> 3.40.0'
gem 'capybara-screenshot', '~> 1.0.26'
gem 'selenium-webdriver', '~> 4.10'
gem 'webdrivers', '~> 5.3.1'
end
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
capybara-screenshot (1.0.26)
capybara (>= 1.0, < 4)
launchy
childprocess (5.0.0)
chroma (0.2.0)
climate_control (1.2.0)
Expand Down Expand Up @@ -225,6 +228,9 @@ GEM
mime-types
terrapin (>= 0.6.0, < 2.0)
language_server-protocol (3.17.0.3)
launchy (3.0.1)
addressable (~> 2.8)
childprocess (~> 5.0)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -498,6 +504,7 @@ DEPENDENCIES
bootstrap-kaminari-views (~> 0.0.5)
byebug
capybara (~> 3.40.0)
capybara-screenshot (~> 1.0.26)
chroma
delayed_job (~> 4.1.11)
delayed_job_active_record
Expand Down
5 changes: 3 additions & 2 deletions app/components/dashboard/dashboard_statistic_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Dashboard
class DashboardStatisticComponent < ViewComponent::Base
def initialize(label:, value:, increment:)
super
@label = label
@value = value
@increment = increment
Expand All @@ -13,9 +14,9 @@ def initialize(label:, value:, increment:)
attr_reader :label, :value, :increment

def pill_class
if increment > 0
if increment.positive?
'text-bg-success'
elsif increment < 0
elsif increment.negative?
'text-bg-warning'
else
'text-bg-secondary'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/dashboard/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
private

def fetch_statistics
Plausible::Integration.last_30_days(true)
Plausible::Integration.last_30_days(compare: true)
rescue Net::HTTPError
nil
end
Expand Down
16 changes: 9 additions & 7 deletions app/javascript/dashboard/shownotes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* global YT */

const iframe = document.getElementById("dashboard-video-player");
if (iframe) {
let player;
Expand All @@ -10,25 +12,25 @@ if (iframe) {
tag.src = "https://www.youtube.com/player_api";
document.head.appendChild(tag);

function onPlayPause() {
const onPlayPause = () => {
if (player.getPlayerState() == 1) {
player.pauseVideo();
} else {
player.playVideo();
}
}
};

function onRewind() {
const onRewind = () => {
const current = player.getCurrentTime();
const next = current >= 15 ? current - 15 : 0;
player.seekTo(next);
}
};

function onChangeSpeed(amount) {
const onChangeSpeed = (amount) => {
const current = player.getPlaybackRate();
next = current + amount;
const next = current + amount;
player.setPlaybackRate(next);
}
};

document.addEventListener("keydown", (e) => {
if (e.shiftKey) {
Expand Down
5 changes: 4 additions & 1 deletion app/javascript/six/components/article.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
}

@include desktop-layout {
&__taxonomy, &__title, &__summary, &__meta {
&__taxonomy,
&__title,
&__summary,
&__meta {
max-width: 60ch;
margin-left: auto;
margin-right: auto;
Expand Down
2 changes: 1 addition & 1 deletion app/services/plausible/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def self.client
Plausible::Integration.new.client
end

def self.last_30_days(compare = false)
def self.last_30_days(compare: false)
data = Rails.cache.fetch('plausible:last_30_days', expires_in: 2.hours) do
client.time_series
end
Expand Down
19 changes: 10 additions & 9 deletions app/services/plausible/month_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ def month_forecast

def fold_comparison(this, previous, key)
delta = (((this[key].to_f / previous[key]) - 1) * 100).round
{ value: this[key], previous: previous[key], delta: delta }
{ value: this[key], previous: previous[key], delta: }
end

def reduce_month_step(total, day)
duration = day['visit_duration'] * day['visits']
{ pageviews: total[:pageviews] + day['pageviews'],
visit_duration: total[:visit_duration] + duration,
visits: total[:visits] + day['visits'] }
end

def reduce_month(month)
accum = month.reduce(Hash::new(0)) do |total, day|
duration = day["visit_duration"] * day["visits"]
{ pageviews: total[:pageviews] + day["pageviews"],
visit_duration: total[:visit_duration] + duration,
visits: total[:visits] + day["visits"] }
end
accum[:visit_duration] = (accum[:visit_duration].to_f / accum[:visits]).round
accum
accum = month.reduce(Hash.new(0), &method(:reduce_month_step))
accum.tap { |a| a[:visit_duration] = (a[:visit_duration].to_f / a[:visits]).round }
end
end
end
8 changes: 0 additions & 8 deletions spec/features/videos/video_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@
let(:playlist) { create(:playlist, topic:) }
let(:show_note) { build(:show_note, documentable: nil) }
let(:video) { create(:video, playlist:, show_note:) }

it 'presents the show notes' do
visit_video video

within("//div[@class='videoinfo__shownotes']") do
expect(page).to have_content show_note.content
end
end
end

describe 'when the video is not published' do
Expand Down
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require 'spec_helper'
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara-screenshot/rspec'
require 'selenium/webdriver'
require 'view_component/test_helpers'
require 'webdrivers/chromedriver'
Expand Down

0 comments on commit cdb066f

Please sign in to comment.