Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-26 00:10:59 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-26 00:10:59 +0300
commita53c0ca02cc35bd485af15b46ace3c9c2ac48c64 (patch)
tree431f1db1af18a00010516d5b389e02ebc3d79547 /spec
parent01ae05ffd11edc648e94c44007fced664bc089ea (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/profile/account/components/update_username_spec.js33
1 files changed, 31 insertions, 2 deletions
diff --git a/spec/frontend/profile/account/components/update_username_spec.js b/spec/frontend/profile/account/components/update_username_spec.js
index 8295d1d43cf..a3d7b63373c 100644
--- a/spec/frontend/profile/account/components/update_username_spec.js
+++ b/spec/frontend/profile/account/components/update_username_spec.js
@@ -2,10 +2,13 @@ import { GlModal } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter';
import { TEST_HOST } from 'helpers/test_constants';
+import { deprecatedCreateFlash as createFlash } from '~/flash';
import axios from '~/lib/utils/axios_utils';
import UpdateUsername from '~/profile/account/components/update_username.vue';
+jest.mock('~/flash');
+
describe('UpdateUsername component', () => {
const rootUrl = TEST_HOST;
const actionUrl = `${TEST_HOST}/update/username`;
@@ -105,7 +108,8 @@ describe('UpdateUsername component', () => {
axiosMock.onPut(actionUrl).replyOnce(() => {
expect(input.attributes('disabled')).toBe('disabled');
- expect(openModalBtn.props('disabled')).toBe(true);
+ expect(openModalBtn.props('disabled')).toBe(false);
+ expect(openModalBtn.props('loading')).toBe(true);
return [200, { message: 'Username changed' }];
});
@@ -115,6 +119,7 @@ describe('UpdateUsername component', () => {
expect(input.attributes('disabled')).toBe(undefined);
expect(openModalBtn.props('disabled')).toBe(true);
+ expect(openModalBtn.props('loading')).toBe(false);
});
it('does not set the username after a erroneous update', async () => {
@@ -122,7 +127,8 @@ describe('UpdateUsername component', () => {
axiosMock.onPut(actionUrl).replyOnce(() => {
expect(input.attributes('disabled')).toBe('disabled');
- expect(openModalBtn.props('disabled')).toBe(true);
+ expect(openModalBtn.props('disabled')).toBe(false);
+ expect(openModalBtn.props('loading')).toBe(true);
return [400, { message: 'Invalid username' }];
});
@@ -130,6 +136,29 @@ describe('UpdateUsername component', () => {
await expect(wrapper.vm.onConfirm()).rejects.toThrow();
expect(input.attributes('disabled')).toBe(undefined);
expect(openModalBtn.props('disabled')).toBe(false);
+ expect(openModalBtn.props('loading')).toBe(false);
+ });
+
+ it('shows an error message if the error response has a `message` property', async () => {
+ axiosMock.onPut(actionUrl).replyOnce(() => {
+ return [400, { message: 'Invalid username' }];
+ });
+
+ await expect(wrapper.vm.onConfirm()).rejects.toThrow();
+
+ expect(createFlash).toBeCalledWith('Invalid username');
+ });
+
+ it("shows a fallback error message if the error response doesn't have a `message` property", async () => {
+ axiosMock.onPut(actionUrl).replyOnce(() => {
+ return [400];
+ });
+
+ await expect(wrapper.vm.onConfirm()).rejects.toThrow();
+
+ expect(createFlash).toBeCalledWith(
+ 'An error occurred while updating your username, please try again.',
+ );
});
});
});