BigW Consortium Gitlab

variables_spec.rb 2.77 KB
Newer Older
1 2
require 'spec_helper'

3 4 5
describe 'Project variables', js: true do
  let(:user)     { create(:user) }
  let(:project)  { create(:project) }
6
  let(:variable) { create(:ci_variable, key: 'test_key', value: 'test value') }
7 8 9 10 11 12

  before do
    login_as(user)
    project.team << [user, :master]
    project.variables << variable

13
    visit namespace_project_settings_ci_cd_path(project.namespace, project)
14 15
  end

16
  it 'shows list of variables' do
17 18 19 20 21
    page.within('.variables-table') do
      expect(page).to have_content(variable.key)
    end
  end

22
  it 'adds new variable' do
Rémy Coutable committed
23 24
    fill_in('variable_key', with: 'key')
    fill_in('variable_value', with: 'key value')
25 26
    click_button('Add new variable')

Rémy Coutable committed
27
    expect(page).to have_content('Variables were successfully updated.')
28
    page.within('.variables-table') do
Rémy Coutable committed
29
      expect(page).to have_content('key')
30 31 32 33 34 35 36 37
    end
  end

  it 'adds empty variable' do
    fill_in('variable_key', with: 'new_key')
    fill_in('variable_value', with: '')
    click_button('Add new variable')

Rémy Coutable committed
38
    expect(page).to have_content('Variables were successfully updated.')
39 40
    page.within('.variables-table') do
      expect(page).to have_content('new_key')
41 42 43
    end
  end

44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  it 'reveals and hides new variable' do
    fill_in('variable_key', with: 'key')
    fill_in('variable_value', with: 'key value')
    click_button('Add new variable')

    page.within('.variables-table') do
      expect(page).to have_content('key')
      expect(page).to have_content('******')
    end

    click_button('Reveal Values')

    page.within('.variables-table') do
      expect(page).to have_content('key')
      expect(page).to have_content('key value')
    end

    click_button('Hide Values')

    page.within('.variables-table') do
      expect(page).to have_content('key')
      expect(page).to have_content('******')
    end
  end

69
  it 'deletes variable' do
70 71 72 73
    page.within('.variables-table') do
      find('.btn-variable-delete').click
    end

74
    expect(page).not_to have_selector('variables-table')
75 76
  end

77
  it 'edits variable' do
78 79
    page.within('.variables-table') do
      find('.btn-variable-edit').click
80 81
    end

Phil Hughes committed
82
    expect(page).to have_content('Update variable')
Rémy Coutable committed
83 84
    fill_in('variable_key', with: 'key')
    fill_in('variable_value', with: 'key value')
85
    click_button('Save variable')
86

Rémy Coutable committed
87 88
    expect(page).to have_content('Variable was successfully updated.')
    expect(project.variables.first.value).to eq('key value')
89 90 91 92 93 94 95 96 97 98 99
  end

  it 'edits variable with empty value' do
    page.within('.variables-table') do
      find('.btn-variable-edit').click
    end

    expect(page).to have_content('Update variable')
    fill_in('variable_value', with: '')
    click_button('Save variable')

Rémy Coutable committed
100 101
    expect(page).to have_content('Variable was successfully updated.')
    expect(project.variables.first.value).to eq('')
102 103
  end
end