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 {
GlModalDirective,
},
mixins: [glFeatureFlagsMixin()],
data() {
return {
location: '',
};
},
inject: {
usersPath: {
default: '',
},
},
data() {
return {
location: '',
};
},
computed: {
...mapState(['errorMessage']),
showNewUI() {
return this.glFeatures.newJiraConnectUi;
},
usersPathWithReturnTo() {
return `${this.usersPath}?return_to=${this.location}`;
if (this.location) {
return `${this.usersPath}?return_to=${this.location}`;
}
return this.usersPath;
},
},
modal: {
......@@ -49,7 +53,6 @@ export default {
methods: {
async setLocation() {
this.location = await getLocation();
console.log(this.location);
},
},
};
......@@ -65,7 +68,7 @@ export default {
<div
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">
{{ s__('Integrations|Linked namespaces') }}
......
import Vue from 'vue';
import Vuex from 'vuex';
import { shallowMount } from '@vue/test-utils';
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 createStore from '~/jira_connect/store';
import { SET_ERROR_MESSAGE } from '~/jira_connect/store/mutation_types';
Vue.use(Vuex);
jest.mock('~/jira_connect/api');
describe('JiraConnectApp', () => {
let wrapper;
let store;
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 findHeaderText = () => findHeader().text();
......@@ -44,6 +45,33 @@ describe('JiraConnectApp', () => {
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', () => {
it('does not render new UI', () => {
createComponent({
......
......@@ -5,20 +5,42 @@ require 'spec_helper'
RSpec.describe JiraConnectHelper do
describe '#jira_connect_app_data' do
let_it_be(:subscription) { create(:jira_connect_subscription) }
let(:user) { create(:user) }
subject { helper.jira_connect_app_data([subscription]) }
it 'includes Jira Connect app attributes' do
is_expected.to include(
:groups_path,
:subscriptions_path
)
context 'user is not logged in' do
before do
allow(view).to receive(:current_user).and_return(nil)
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
it 'passes group as "skip_groups" param' do
skip_groups_param = CGI.escape('skip_groups[]')
context 'user is logged in' do
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
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