2020-10-29 08:08:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Frequently visited items', :js do
|
2021-05-31 17:09:39 -04:00
|
|
|
include Spec::Support::Helpers::Features::TopNavSpecHelpers
|
|
|
|
|
2020-10-29 08:08:50 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2020-10-29 08:08:50 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
context 'for projects' do
|
|
|
|
let_it_be(:project) { create(:project, :public) }
|
2020-10-29 08:08:50 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
it 'increments localStorage counter when visiting the project' do
|
|
|
|
visit project_path(project)
|
2020-10-29 08:08:50 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
frequent_projects = nil
|
2020-10-29 08:08:50 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
wait_for('localStorage frequent-projects') do
|
|
|
|
frequent_projects = page.evaluate_script("localStorage['#{user.username}/frequent-projects']")
|
2020-10-29 08:08:50 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
frequent_projects.present?
|
2021-05-12 17:10:13 -04:00
|
|
|
end
|
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
expect(Gitlab::Json.parse(frequent_projects)).to contain_exactly(a_hash_including('id' => project.id, 'frequency' => 1))
|
2021-05-12 17:10:13 -04:00
|
|
|
end
|
|
|
|
end
|
2020-10-29 08:08:50 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
context 'for groups' do
|
|
|
|
let_it_be(:group) { create(:group, :public) }
|
2021-05-12 17:10:13 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
it 'increments localStorage counter when visiting the group' do
|
|
|
|
visit group_path(group)
|
2021-05-12 17:10:13 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
frequent_groups = nil
|
2021-05-12 17:10:13 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
wait_for('localStorage frequent-groups') do
|
|
|
|
frequent_groups = page.evaluate_script("localStorage['#{user.username}/frequent-groups']")
|
2021-05-12 17:10:13 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
frequent_groups.present?
|
|
|
|
end
|
2021-05-12 17:10:13 -04:00
|
|
|
|
2021-07-21 17:10:10 -04:00
|
|
|
expect(Gitlab::Json.parse(frequent_groups)).to contain_exactly(a_hash_including('id' => group.id, 'frequency' => 1))
|
|
|
|
end
|
2021-05-12 17:10:13 -04:00
|
|
|
end
|
2020-10-29 08:08:50 -04:00
|
|
|
end
|