diff options
Diffstat (limited to 'spec/requests/pwa_controller_spec.rb')
-rw-r--r-- | spec/requests/pwa_controller_spec.rb | 84 |
1 files changed, 61 insertions, 23 deletions
diff --git a/spec/requests/pwa_controller_spec.rb b/spec/requests/pwa_controller_spec.rb index a80d083c11f..08eeefd1dc4 100644 --- a/spec/requests/pwa_controller_spec.rb +++ b/spec/requests/pwa_controller_spec.rb @@ -4,27 +4,74 @@ require 'spec_helper' RSpec.describe PwaController, feature_category: :navigation do describe 'GET #manifest' do - it 'responds with json' do - get manifest_path(format: :json) + shared_examples 'text values' do |params, result| + let_it_be(:appearance) { create(:appearance, **params) } - expect(response.body).to include('The complete DevOps platform.') - expect(Gitlab::Json.parse(response.body)).to include({ 'short_name' => 'GitLab' }) - expect(response).to have_gitlab_http_status(:success) + 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.' + } end context 'with customized appearance' do - let_it_be(:appearance) do - create(:appearance, title: 'Long name', pwa_short_name: 'Short name', description: 'This is a test') + 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' } end - it 'uses custom values', :aggregate_failures do - get manifest_path(format: :json) + 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 - expect(Gitlab::Json.parse(response.body)).to include({ - 'description' => 'This is a test', - 'name' => 'Long name', - 'short_name' => 'Short name' - }) + 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') expect(response).to have_gitlab_http_status(:success) end end @@ -46,13 +93,4 @@ RSpec.describe PwaController, feature_category: :navigation do end 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') - expect(response).to have_gitlab_http_status(:success) - end - end end |