2022-07-16 23:28:13 +05:30
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
|
RSpec.describe PwaController, feature_category: :navigation do
|
2022-07-23 23:45:48 +05:30
|
|
|
|
describe 'GET #manifest' do
|
2023-04-23 21:23:45 +05:30
|
|
|
|
shared_examples 'text values' do |params, result|
|
|
|
|
|
let_it_be(:appearance) { create(:appearance, **params) }
|
2022-07-23 23:45:48 +05:30
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
|
it 'uses custom values', :aggregate_failures do
|
|
|
|
|
get manifest_path(format: :json)
|
|
|
|
|
|
|
|
|
|
expect(Gitlab::Json.parse(response.body)).to include(result)
|
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with default appearance' do
|
|
|
|
|
it_behaves_like 'text values', {}, {
|
|
|
|
|
'name' => 'GitLab',
|
|
|
|
|
'short_name' => 'GitLab',
|
|
|
|
|
'description' => 'The complete DevOps platform. ' \
|
|
|
|
|
'One application with endless possibilities. ' \
|
|
|
|
|
'Organizations rely on GitLab’s source code management, ' \
|
|
|
|
|
'CI/CD, security, and more to deliver software rapidly.'
|
|
|
|
|
}
|
2022-07-23 23:45:48 +05:30
|
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
|
|
context 'with customized appearance' do
|
2023-04-23 21:23:45 +05:30
|
|
|
|
context 'with custom text values' do
|
|
|
|
|
it_behaves_like 'text values', { pwa_name: 'PWA name' }, { 'name' => 'PWA name' }
|
|
|
|
|
it_behaves_like 'text values', { pwa_short_name: 'Short name' }, { 'short_name' => 'Short name' }
|
|
|
|
|
it_behaves_like 'text values', { pwa_description: 'This is a test' }, { 'description' => 'This is a test' }
|
2023-03-04 22:38:38 +05:30
|
|
|
|
end
|
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
|
shared_examples 'icon paths' do
|
|
|
|
|
it 'returns expected icon paths', :aggregate_failures do
|
|
|
|
|
get manifest_path(format: :json)
|
|
|
|
|
|
|
|
|
|
expect(Gitlab::Json.parse(response.body)["icons"]).to match_array(result)
|
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with custom icon' do
|
|
|
|
|
let_it_be(:appearance) { create(:appearance, :with_pwa_icon) }
|
|
|
|
|
let_it_be(:result) do
|
|
|
|
|
[{ "src" => "/uploads/-/system/appearance/pwa_icon/#{appearance.id}/dk.png?width=192", "sizes" => "192x192",
|
|
|
|
|
"type" => "image/png" },
|
|
|
|
|
{ "src" => "/uploads/-/system/appearance/pwa_icon/#{appearance.id}/dk.png?width=512", "sizes" => "512x512",
|
|
|
|
|
"type" => "image/png" }]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'icon paths'
|
|
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
|
context 'with no custom icon' do
|
|
|
|
|
let_it_be(:appearance) { create(:appearance) }
|
|
|
|
|
let_it_be(:result) do
|
|
|
|
|
[{ "src" => "/-/pwa-icons/logo-192.png", "sizes" => "192x192", "type" => "image/png" },
|
|
|
|
|
{ "src" => "/-/pwa-icons/logo-512.png", "sizes" => "512x512", "type" => "image/png" },
|
|
|
|
|
{ "src" => "/-/pwa-icons/maskable-logo.png", "sizes" => "512x512", "type" => "image/png",
|
|
|
|
|
"purpose" => "maskable" }]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'icon paths'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'GET #offline' do
|
|
|
|
|
it 'responds with static HTML page' do
|
|
|
|
|
get offline_path
|
|
|
|
|
|
|
|
|
|
expect(response.body).to include('You are currently offline')
|
2023-03-04 22:38:38 +05:30
|
|
|
|
expect(response).to have_gitlab_http_status(:success)
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-03-17 16:20:25 +05:30
|
|
|
|
|
|
|
|
|
context 'when user is signed in' do
|
|
|
|
|
before do
|
|
|
|
|
user = create(:user)
|
|
|
|
|
allow(user).to receive(:role_required?).and_return(true)
|
|
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'skips the required signup info storing of user location' do
|
|
|
|
|
expect_next_instance_of(described_class) do |instance|
|
|
|
|
|
expect(instance).not_to receive(:store_location_for).with(:user, manifest_path(format: :json))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
get manifest_path(format: :json)
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-07-23 23:45:48 +05:30
|
|
|
|
end
|
2022-07-16 23:28:13 +05:30
|
|
|
|
end
|