2021-01-29 00:20:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe 'Frequently visited items', :js, feature_category: :shared do
|
2023-06-20 00:43:36 +05:30
|
|
|
include Features::TopNavSpecHelpers
|
2021-09-04 01:27:46 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
context 'for projects' do
|
|
|
|
let_it_be(:project) { create(:project, :public) }
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
it 'increments localStorage counter when visiting the project' do
|
|
|
|
visit project_path(project)
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
frequent_projects = nil
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
wait_for('localStorage frequent-projects') do
|
|
|
|
frequent_projects = page.evaluate_script("localStorage['#{user.username}/frequent-projects']")
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
frequent_projects.present?
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
expect(Gitlab::Json.parse(frequent_projects)).to contain_exactly(a_hash_including('id' => project.id, 'frequency' => 1))
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
context 'for groups' do
|
|
|
|
let_it_be(:group) { create(:group, :public) }
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
it 'increments localStorage counter when visiting the group' do
|
|
|
|
visit group_path(group)
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
frequent_groups = nil
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
wait_for('localStorage frequent-groups') do
|
|
|
|
frequent_groups = page.evaluate_script("localStorage['#{user.username}/frequent-groups']")
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
frequent_groups.present?
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
expect(Gitlab::Json.parse(frequent_groups)).to contain_exactly(a_hash_including('id' => group.id, 'frequency' => 1))
|
|
|
|
end
|
2021-06-08 01:23:25 +05:30
|
|
|
end
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|