summaryrefslogtreecommitdiff
path: root/spec/requests/pwa_controller_spec.rb
blob: a80d083c11fa89a52d07c03bc2262f04439f2054 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe PwaController, feature_category: :navigation do
  describe 'GET #manifest' do
    it 'responds with json' do
      get manifest_path(format: :json)

      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)
    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')
      end

      it 'uses custom values', :aggregate_failures do
        get manifest_path(format: :json)

        expect(Gitlab::Json.parse(response.body)).to include({
                                                               'description' => 'This is a test',
                                                               'name' => 'Long name',
                                                               'short_name' => 'Short name'
                                                             })
        expect(response).to have_gitlab_http_status(:success)
      end
    end

    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
  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