Commit a4677886 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Share JS code for all paths in trials

Namespace select stops working if a customer receives
an error on applying the trial plan. This happens due to
redirect on error to `select` path but the app
loads the select's code on `apply` path only. To solve that problem
we share this code to both paths.

Closes https://gitlab.com/gitlab-org/gitlab/issues/33740
parent 1bea9238
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';
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 'ee/pages/trials/namespace_select';
......@@ -84,13 +84,14 @@ describe 'Trial Select Namespace', :js do
click_button 'Start your free trial'
message = page.find('#new_group_name').native.attribute('validationMessage')
expect(message).to eq('Please fill out this field.')
expect(current_path).to eq(select_trials_path)
end
end
end
context 'selects an existing user' do
context 'selects an existing group' do
before do
visit select_trials_path
wait_for_all_requests
......@@ -98,20 +99,42 @@ describe 'Trial Select Namespace', :js do
select2 user.namespace.id, from: '#namespace_id'
end
it 'does not show the new group name input' do
expect(page).not_to have_field('New Group Name')
end
context 'without trial plan' do
it 'does not show the new group name input' do
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_any_instance_of(GitlabSubscriptions::ApplyTrialService).to receive(:execute) do
{ success: true }
expect(current_path).to eq("/#{user.namespace.path}")
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
......
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