Commit dbad2b00 authored by Justin Ho's avatar Justin Ho

Fix feature specs to work with feature flag

- All specs should have JS enabled since it's what renders
most of the form now.
- Some name / id changes to to new markup
- Add event hub events to allow passing state from JS to
Vue to enable proper form validations on submit.
parent 14685ed3
<script> <script>
import eventHub from '../event_hub';
import { capitalize, lowerCase, isEmpty } from 'lodash'; import { capitalize, lowerCase, isEmpty } from 'lodash';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import { GlFormGroup, GlFormCheckbox, GlFormInput, GlFormSelect, GlFormTextarea } from '@gitlab/ui'; import { GlFormGroup, GlFormCheckbox, GlFormInput, GlFormSelect, GlFormTextarea } from '@gitlab/ui';
...@@ -54,6 +55,7 @@ export default { ...@@ -54,6 +55,7 @@ export default {
data() { data() {
return { return {
model: this.value, model: this.value,
validated: false,
}; };
}, },
computed: { computed: {
...@@ -106,17 +108,45 @@ export default { ...@@ -106,17 +108,45 @@ export default {
name: this.fieldName, name: this.fieldName,
}; };
}, },
valid() {
if (!this.required) {
return true;
}
if (this.model) {
return true;
}
if (!this.validated) {
return true;
}
return false;
},
}, },
created() { created() {
if (this.isNonEmptyPassword) { if (this.isNonEmptyPassword) {
this.model = null; this.model = null;
} }
eventHub.$on('validateForm', this.validateForm);
},
beforeDestroy() {
eventHub.$off('validateForm', this.validateForm);
},
methods: {
validateForm() {
this.validated = true;
},
}, },
}; };
</script> </script>
<template> <template>
<gl-form-group :label="label" :label-for="fieldId" :description="help"> <gl-form-group
:label="label"
:label-for="fieldId"
:invalid-feedback="__('This field is required.')"
:state="valid"
:description="help"
>
<template v-if="isCheckbox"> <template v-if="isCheckbox">
<input :name="fieldName" type="hidden" value="false" /> <input :name="fieldName" type="hidden" value="false" />
<gl-form-checkbox v-model="model" v-bind="sharedProps"> <gl-form-checkbox v-model="model" v-bind="sharedProps">
......
...@@ -45,11 +45,16 @@ export default class IntegrationSettingsForm { ...@@ -45,11 +45,16 @@ export default class IntegrationSettingsForm {
// 2) If this service can be tested // 2) If this service can be tested
// If both conditions are true, we override form submission // If both conditions are true, we override form submission
// and test the service using provided configuration. // and test the service using provided configuration.
if (this.$form.get(0).checkValidity() && this.canTestService) { if (this.$form.get(0).checkValidity()) {
if (this.canTestService) {
e.preventDefault(); e.preventDefault();
// eslint-disable-next-line no-jquery/no-serialize // eslint-disable-next-line no-jquery/no-serialize
this.testSettings(this.$form.serialize()); this.testSettings(this.$form.serialize());
} }
} else {
e.preventDefault();
eventHub.$emit('validateForm');
}
} }
handleServiceToggle() { handleServiceToggle() {
......
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
require 'spec_helper' require 'spec_helper'
describe 'Admin activates Prometheus' do describe 'Admin activates Prometheus', :js do
let(:admin) { create(:user, :admin) } let(:admin) { create(:user, :admin) }
before do before do
stub_feature_flags(integration_form_refactor: false)
sign_in(admin) sign_in(admin)
visit(admin_application_settings_services_path) visit(admin_application_settings_services_path)
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Disable individual triggers' do RSpec.describe 'Disable individual triggers', :js do
include_context 'project service activation' include_context 'project service activation'
let(:checkbox_selector) { 'input[type=checkbox][id$=_events]' } let(:checkbox_selector) { 'input[type=checkbox][name$="_events]"]' }
before do before do
visit_project_integration(service_name) visit_project_integration(service_name)
......
...@@ -23,6 +23,6 @@ RSpec.describe 'User activates Atlassian Bamboo CI' do ...@@ -23,6 +23,6 @@ RSpec.describe 'User activates Atlassian Bamboo CI' do
# Password field should not be filled in. # Password field should not be filled in.
click_link('Atlassian Bamboo CI') click_link('Atlassian Bamboo CI')
expect(find_field('Enter new password').value).to be_blank expect(find_field('Enter new Password').value).to be_blank
end end
end end
...@@ -12,7 +12,7 @@ RSpec.describe 'User activates JetBrains TeamCity CI' do ...@@ -12,7 +12,7 @@ RSpec.describe 'User activates JetBrains TeamCity CI' do
it 'activates service', :js do it 'activates service', :js do
visit_project_integration('JetBrains TeamCity CI') visit_project_integration('JetBrains TeamCity CI')
check('Push') check('Push')
check('Merge request') check('Merge Request')
fill_in('Teamcity url', with: 'http://teamcity.example.com') fill_in('Teamcity url', with: 'http://teamcity.example.com')
fill_in('Build type', with: 'GitlabTest_Build') fill_in('Build type', with: 'GitlabTest_Build')
fill_in('Username', with: 'user') fill_in('Username', with: 'user')
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'User activates Slack notifications' do RSpec.describe 'User activates Slack notifications', :js do
include_context 'project service activation' include_context 'project service activation'
context 'when service is not configured yet' do context 'when service is not configured yet' do
...@@ -10,7 +10,7 @@ RSpec.describe 'User activates Slack notifications' do ...@@ -10,7 +10,7 @@ RSpec.describe 'User activates Slack notifications' do
visit_project_integration('Slack notifications') visit_project_integration('Slack notifications')
end end
it 'activates service', :js do it 'activates service' do
fill_in('Webhook', with: 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685') fill_in('Webhook', with: 'https://hooks.slack.com/services/SVRWFV0VVAR97N/B02R25XN3/ZBqu7xMupaEEICInN685')
click_test_then_save_integration click_test_then_save_integration
...@@ -38,13 +38,13 @@ RSpec.describe 'User activates Slack notifications' do ...@@ -38,13 +38,13 @@ RSpec.describe 'User activates Slack notifications' do
end end
it 'filters events by channel' do it 'filters events by channel' do
expect(page.find_field('service_push_channel').value).to have_content('1') expect(page.find_field(name: 'service[push_channel]').value).to have_content('1')
expect(page.find_field('service_issue_channel').value).to have_content('2') expect(page.find_field(name: 'service[issue_channel]').value).to have_content('2')
expect(page.find_field('service_merge_request_channel').value).to have_content('3') expect(page.find_field(name: 'service[merge_request_channel]').value).to have_content('3')
expect(page.find_field('service_note_channel').value).to have_content('4') expect(page.find_field(name: 'service[note_channel]').value).to have_content('4')
expect(page.find_field('service_tag_push_channel').value).to have_content('5') expect(page.find_field(name: 'service[tag_push_channel]').value).to have_content('5')
expect(page.find_field('service_pipeline_channel').value).to have_content('6') expect(page.find_field(name: 'service[pipeline_channel]').value).to have_content('6')
expect(page.find_field('service_wiki_page_channel').value).to have_content('7') expect(page.find_field(name: 'service[wiki_page_channel]').value).to have_content('7')
end end
end end
end end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Slack slash commands' do RSpec.describe 'Slack slash commands', :js do
include_context 'project service activation' include_context 'project service activation'
before do before do
...@@ -10,7 +10,7 @@ RSpec.describe 'Slack slash commands' do ...@@ -10,7 +10,7 @@ RSpec.describe 'Slack slash commands' do
end end
it 'shows a token placeholder' do it 'shows a token placeholder' do
token_placeholder = find_field('service_token')['placeholder'] token_placeholder = find_field('Token')['placeholder']
expect(token_placeholder).to eq('XXxxXXxxXXxxXXxxXXxxXXxx') expect(token_placeholder).to eq('XXxxXXxxXXxxXXxxXXxxXXxx')
end end
...@@ -19,8 +19,8 @@ RSpec.describe 'Slack slash commands' do ...@@ -19,8 +19,8 @@ RSpec.describe 'Slack slash commands' do
expect(page).to have_content('This service allows users to perform common') expect(page).to have_content('This service allows users to perform common')
end end
it 'redirects to the integrations page after saving but not activating', :js do it 'redirects to the integrations page after saving but not activating' do
fill_in 'service_token', with: 'token' fill_in 'Token', with: 'token'
click_active_toggle click_active_toggle
click_on 'Save' click_on 'Save'
...@@ -28,8 +28,8 @@ RSpec.describe 'Slack slash commands' do ...@@ -28,8 +28,8 @@ RSpec.describe 'Slack slash commands' do
expect(page).to have_content('Slack slash commands settings saved, but not activated.') expect(page).to have_content('Slack slash commands settings saved, but not activated.')
end end
it 'redirects to the integrations page after activating', :js do it 'redirects to the integrations page after activating' do
fill_in 'service_token', with: 'token' fill_in 'Token', with: 'token'
click_on 'Save' click_on 'Save'
expect(current_path).to eq(project_settings_integrations_path(project)) expect(current_path).to eq(project_settings_integrations_path(project))
......
...@@ -5,7 +5,6 @@ shared_context 'project service activation' do ...@@ -5,7 +5,6 @@ shared_context 'project service activation' do
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
stub_feature_flags(integration_form_refactor: false)
project.add_maintainer(user) project.add_maintainer(user)
sign_in(user) sign_in(user)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment