Commit 3d4c40a0 authored by Clement Ho's avatar Clement Ho Committed by Fatih Acet

Replace $.ajax in profile.js with axios

parent 071b0ef3
/* eslint-disable comma-dangle, no-unused-vars, class-methods-use-this, quotes, consistent-return, func-names, prefer-arrow-callback, space-before-function-paren, max-len */ /* eslint-disable comma-dangle, no-unused-vars, class-methods-use-this, quotes, consistent-return, func-names, prefer-arrow-callback, space-before-function-paren, max-len */
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import Flash from '../flash'; import { getPagePath } from '~/lib/utils/common_utils';
import { getPagePath } from '../lib/utils/common_utils'; import axios from '~/lib/utils/axios_utils';
import { __ } from '~/locale';
import flash from '../flash';
((global) => { ((global) => {
class Profile { class Profile {
...@@ -57,8 +59,8 @@ import { getPagePath } from '../lib/utils/common_utils'; ...@@ -57,8 +59,8 @@ import { getPagePath } from '../lib/utils/common_utils';
onUpdateNotifs(e, data) { onUpdateNotifs(e, data) {
return data.saved ? return data.saved ?
new Flash("Notification settings saved", "notice") : flash(__('Notification settings saved'), 'notice') :
new Flash("Failed to save new settings", "alert"); flash(__('Failed to save new settings'));
} }
saveForm() { saveForm() {
...@@ -70,21 +72,18 @@ import { getPagePath } from '../lib/utils/common_utils'; ...@@ -70,21 +72,18 @@ import { getPagePath } from '../lib/utils/common_utils';
formData.append('user[avatar]', avatarBlob, 'avatar.png'); formData.append('user[avatar]', avatarBlob, 'avatar.png');
} }
return $.ajax({ axios({
method: this.form.attr('method'),
url: this.form.attr('action'), url: this.form.attr('action'),
type: this.form.attr('method'),
data: formData, data: formData,
dataType: "json", })
processData: false, .then(({ data }) => flash(data.message, 'notice'))
contentType: false, .then(() => {
success: response => new Flash(response.message, 'notice'),
error: jqXHR => new Flash(jqXHR.responseJSON.message, 'alert'),
complete: () => {
window.scrollTo(0, 0); window.scrollTo(0, 0);
// Enable submit button after requests ends // Enable submit button after requests ends
return self.form.find(':input[disabled]').enable(); self.form.find(':input[disabled]').enable();
} })
}); .catch(error => flash(error.message));
} }
setNewRepoCookie() { setNewRepoCookie() {
......
...@@ -12,4 +12,13 @@ describe 'User visits their profile' do ...@@ -12,4 +12,13 @@ describe 'User visits their profile' do
it 'shows correct menu item' do it 'shows correct menu item' do
expect(page).to have_active_navigation('Profile') expect(page).to have_active_navigation('Profile')
end end
describe 'profile settings', :js do
it 'saves updates' do
fill_in 'user_bio', with: 'bio'
click_button 'Update profile settings'
expect(page).to have_content('Profile was successfully updated')
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