Commit 4a33589a authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'vslobodin/fix-apply-trial' into 'master'

Share JS code for all paths in trials

Closes #33740

See merge request gitlab-org/gitlab!18378
parents 760cc92c a4677886
import 'ee/pages/trials/namespace_select';
import $ from 'jquery';
document.addEventListener('DOMContentLoaded', () => {
const namespaceId = $('#namespace_id');
const newGroupName = $('#group_name');
namespaceId.on('change', () => {
const enableNewGroupName = namespaceId.val() === '0';
newGroupName
.toggleClass('hidden', !enableNewGroupName)
.find('input')
.prop('required', enableNewGroupName);
});
namespaceId.trigger('change');
});
import $ from 'jquery'; import 'ee/pages/trials/namespace_select';
document.addEventListener('DOMContentLoaded', () => {
const namespaceId = $('#namespace_id');
const newGroupName = $('#group_name');
namespaceId.on('change', () => {
const enableNewGroupName = namespaceId.val() === '0';
newGroupName
.toggleClass('hidden', !enableNewGroupName)
.find('input')
.prop('required', enableNewGroupName);
});
namespaceId.trigger('change');
});
...@@ -84,13 +84,14 @@ describe 'Trial Select Namespace', :js do ...@@ -84,13 +84,14 @@ describe 'Trial Select Namespace', :js do
click_button 'Start your free trial' click_button 'Start your free trial'
message = page.find('#new_group_name').native.attribute('validationMessage') message = page.find('#new_group_name').native.attribute('validationMessage')
expect(message).to eq('Please fill out this field.') expect(message).to eq('Please fill out this field.')
expect(current_path).to eq(select_trials_path) expect(current_path).to eq(select_trials_path)
end end
end end
end end
context 'selects an existing user' do context 'selects an existing group' do
before do before do
visit select_trials_path visit select_trials_path
wait_for_all_requests wait_for_all_requests
...@@ -98,20 +99,42 @@ describe 'Trial Select Namespace', :js do ...@@ -98,20 +99,42 @@ describe 'Trial Select Namespace', :js do
select2 user.namespace.id, from: '#namespace_id' select2 user.namespace.id, from: '#namespace_id'
end end
it 'does not show the new group name input' do context 'without trial plan' do
expect(page).not_to have_field('New Group Name') it 'does not show the new group name input' do
end expect(page).not_to have_field('New Group Name')
end
it 'applies trial and redirects to dashboard' do
expect_any_instance_of(GitlabSubscriptions::ApplyTrialService).to receive(:execute) do
{ success: true }
end
click_button 'Start your free trial'
wait_for_requests
it 'applies trial and redirects to dashboard' do expect(current_path).to eq("/#{user.namespace.path}")
expect_any_instance_of(GitlabSubscriptions::ApplyTrialService).to receive(:execute) do
{ success: true }
end end
end
click_button 'Start your free trial' context 'with trial plan' do
let!(:error_message) { 'Validation failed: Gl namespace can have only one trial' }
wait_for_requests it 'shows validation error' do
expect_any_instance_of(GitlabSubscriptions::ApplyTrialService).to receive(:execute) do
{ success: false, errors: error_message }
end
click_button 'Start your free trial'
expect(current_path).to eq("/#{user.namespace.path}") expect(find('.flash-text')).to have_text(error_message)
expect(current_path).to eq(apply_trials_path)
# new group name should be functional
select2 '0', from: '#namespace_id'
expect(page).to have_field('New Group Name')
end
end end
end end
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