Commit 65076246 authored by Justin Ho's avatar Justin Ho

Add specs for sign in / add buttons

And update some eslint issues
parent 0262c6b2
...@@ -19,23 +19,27 @@ export default { ...@@ -19,23 +19,27 @@ export default {
GlModalDirective, GlModalDirective,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
data() {
return {
location: '',
};
},
inject: { inject: {
usersPath: { usersPath: {
default: '', default: '',
}, },
}, },
data() {
return {
location: '',
};
},
computed: { computed: {
...mapState(['errorMessage']), ...mapState(['errorMessage']),
showNewUI() { showNewUI() {
return this.glFeatures.newJiraConnectUi; return this.glFeatures.newJiraConnectUi;
}, },
usersPathWithReturnTo() { usersPathWithReturnTo() {
return `${this.usersPath}?return_to=${this.location}`; if (this.location) {
return `${this.usersPath}?return_to=${this.location}`;
}
return this.usersPath;
}, },
}, },
modal: { modal: {
...@@ -49,7 +53,6 @@ export default { ...@@ -49,7 +53,6 @@ export default {
methods: { methods: {
async setLocation() { async setLocation() {
this.location = await getLocation(); this.location = await getLocation();
console.log(this.location);
}, },
}, },
}; };
...@@ -65,7 +68,7 @@ export default { ...@@ -65,7 +68,7 @@ export default {
<div <div
v-if="showNewUI" v-if="showNewUI"
class="gl-display-flex gl-justify-content-space-between gl-my-5 gl-pb-4 gl-border-b-solid gl-border-b-1 gl-border-b-gray-200" class="gl-display-flex gl-justify-content-space-between gl-my-7 gl-pb-4 gl-border-b-solid gl-border-b-1 gl-border-b-gray-200"
> >
<h5 class="gl-align-self-center gl-mb-0" data-testid="new-jira-connect-ui-heading"> <h5 class="gl-align-self-center gl-mb-0" data-testid="new-jira-connect-ui-heading">
{{ s__('Integrations|Linked namespaces') }} {{ s__('Integrations|Linked namespaces') }}
......
import Vue from 'vue';
import Vuex from 'vuex';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import { GlAlert } from '@gitlab/ui'; import { GlAlert, GlButton, GlModal } from '@gitlab/ui';
import JiraConnectApp from '~/jira_connect/components/app.vue'; import JiraConnectApp from '~/jira_connect/components/app.vue';
import createStore from '~/jira_connect/store'; import createStore from '~/jira_connect/store';
import { SET_ERROR_MESSAGE } from '~/jira_connect/store/mutation_types'; import { SET_ERROR_MESSAGE } from '~/jira_connect/store/mutation_types';
Vue.use(Vuex); jest.mock('~/jira_connect/api');
describe('JiraConnectApp', () => { describe('JiraConnectApp', () => {
let wrapper; let wrapper;
let store; let store;
const findAlert = () => wrapper.findComponent(GlAlert); const findAlert = () => wrapper.findComponent(GlAlert);
const findGlButton = () => wrapper.findComponent(GlButton);
const findGlModal = () => wrapper.findComponent(GlModal);
const findHeader = () => wrapper.findByTestId('new-jira-connect-ui-heading'); const findHeader = () => wrapper.findByTestId('new-jira-connect-ui-heading');
const findHeaderText = () => findHeader().text(); const findHeaderText = () => findHeader().text();
...@@ -44,6 +45,33 @@ describe('JiraConnectApp', () => { ...@@ -44,6 +45,33 @@ describe('JiraConnectApp', () => {
expect(findHeaderText()).toBe('Linked namespaces'); expect(findHeaderText()).toBe('Linked namespaces');
}); });
describe('when user is not logged in', () => {
beforeEach(() => {
createComponent({
provide: {
glFeatures: { newJiraConnectUi: true },
usersPath: '/users',
},
});
});
it('renders "Sign in" button', () => {
expect(findGlButton().text()).toBe('Sign in to add namespaces');
expect(findGlModal().exists()).toBe(false);
});
});
describe('when user is logged in', () => {
beforeEach(() => {
createComponent();
});
it('renders "Add" button and modal', () => {
expect(findGlButton().text()).toBe('Add namespace');
expect(findGlModal().exists()).toBe(true);
});
});
describe('newJiraConnectUi is false', () => { describe('newJiraConnectUi is false', () => {
it('does not render new UI', () => { it('does not render new UI', () => {
createComponent({ createComponent({
......
...@@ -5,20 +5,42 @@ require 'spec_helper' ...@@ -5,20 +5,42 @@ require 'spec_helper'
RSpec.describe JiraConnectHelper do RSpec.describe JiraConnectHelper do
describe '#jira_connect_app_data' do describe '#jira_connect_app_data' do
let_it_be(:subscription) { create(:jira_connect_subscription) } let_it_be(:subscription) { create(:jira_connect_subscription) }
let(:user) { create(:user) }
subject { helper.jira_connect_app_data([subscription]) } subject { helper.jira_connect_app_data([subscription]) }
it 'includes Jira Connect app attributes' do context 'user is not logged in' do
is_expected.to include( before do
:groups_path, allow(view).to receive(:current_user).and_return(nil)
:subscriptions_path end
)
it 'includes Jira Connect app attributes' do
is_expected.to include(
:groups_path,
:subscriptions_path,
:users_path
)
end
it 'assigns users_path with value' do
expect(subject[:users_path]).to eq(jira_connect_users_path)
end
it 'passes group as "skip_groups" param' do
skip_groups_param = CGI.escape('skip_groups[]')
expect(subject[:groups_path]).to include("#{skip_groups_param}=#{subscription.namespace.id}")
end
end end
it 'passes group as "skip_groups" param' do context 'user is logged in' do
skip_groups_param = CGI.escape('skip_groups[]') before do
allow(view).to receive(:current_user).and_return(user)
end
expect(subject[:groups_path]).to include("#{skip_groups_param}=#{subscription.namespace.id}") it 'assigns users_path to nil' do
expect(subject[:users_path]).to be_nil
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