Commit a7a5d85f authored by Tom Quirk's avatar Tom Quirk

Improve Jira Connect app_spec.js

- consolidate template specs into a single
spec table.
parent b000e175
...@@ -4,6 +4,7 @@ import { mount, shallowMount } from '@vue/test-utils'; ...@@ -4,6 +4,7 @@ import { mount, shallowMount } from '@vue/test-utils';
import JiraConnectApp from '~/jira_connect/subscriptions/components/app.vue'; import JiraConnectApp from '~/jira_connect/subscriptions/components/app.vue';
import AddNamespaceButton from '~/jira_connect/subscriptions/components/add_namespace_button.vue'; import AddNamespaceButton from '~/jira_connect/subscriptions/components/add_namespace_button.vue';
import SignInButton from '~/jira_connect/subscriptions/components/sign_in_button.vue'; import SignInButton from '~/jira_connect/subscriptions/components/sign_in_button.vue';
import SubscriptionsList from '~/jira_connect/subscriptions/components/subscriptions_list.vue';
import createStore from '~/jira_connect/subscriptions/store'; import createStore from '~/jira_connect/subscriptions/store';
import { SET_ALERT } from '~/jira_connect/subscriptions/store/mutation_types'; import { SET_ALERT } from '~/jira_connect/subscriptions/store/mutation_types';
import { __ } from '~/locale'; import { __ } from '~/locale';
...@@ -21,6 +22,7 @@ describe('JiraConnectApp', () => { ...@@ -21,6 +22,7 @@ describe('JiraConnectApp', () => {
const findAlertLink = () => findAlert().findComponent(GlLink); const findAlertLink = () => findAlert().findComponent(GlLink);
const findSignInButton = () => wrapper.findComponent(SignInButton); const findSignInButton = () => wrapper.findComponent(SignInButton);
const findAddNamespaceButton = () => wrapper.findComponent(AddNamespaceButton); const findAddNamespaceButton = () => wrapper.findComponent(AddNamespaceButton);
const findSubscriptionsList = () => wrapper.findComponent(SubscriptionsList);
const findEmptyState = () => wrapper.findComponent(GlEmptyState); const findEmptyState = () => wrapper.findComponent(GlEmptyState);
const createComponent = ({ provide, mountFn = shallowMount } = {}) => { const createComponent = ({ provide, mountFn = shallowMount } = {}) => {
...@@ -36,54 +38,51 @@ describe('JiraConnectApp', () => { ...@@ -36,54 +38,51 @@ describe('JiraConnectApp', () => {
wrapper.destroy(); wrapper.destroy();
}); });
describe('with subscriptions', () => { describe('template', () => {
describe.each` describe.each`
scenario | usersPath | expectSignInButton | expectNamespaceButton scenario | usersPath | subscriptions | expectSignInButton | expectEmptyState | expectNamespaceButton | expectSubscriptionsList
${'user is not signed in'} | ${'/users'} | ${true} | ${false} ${'user is not signed in with subscriptions'} | ${'/users'} | ${[mockSubscription]} | ${true} | ${false} | ${false} | ${true}
${'user is signed in'} | ${undefined} | ${false} | ${true} ${'user is not signed in without subscriptions'} | ${'/users'} | ${undefined} | ${true} | ${false} | ${false} | ${false}
`('when $scenario', ({ usersPath, expectSignInButton, expectNamespaceButton }) => { ${'user is signed in with subscriptions'} | ${undefined} | ${[mockSubscription]} | ${false} | ${false} | ${true} | ${true}
${'user is signed in without subscriptions'} | ${undefined} | ${undefined} | ${false} | ${true} | ${false} | ${false}
`(
'when $scenario',
({
usersPath,
expectSignInButton,
subscriptions,
expectEmptyState,
expectNamespaceButton,
expectSubscriptionsList,
}) => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
provide: { provide: {
usersPath, usersPath,
subscriptions: [mockSubscription], subscriptions,
}, },
}); });
}); });
it('renders sign in button as expected', () => { it(`${expectSignInButton ? 'renders' : 'does not render'} sign in button`, () => {
expect(findSignInButton().exists()).toBe(expectSignInButton); expect(findSignInButton().exists()).toBe(expectSignInButton);
}); });
it('renders "Add Namespace" button as expected', () => { it(`${expectEmptyState ? 'renders' : 'does not render'} empty state`, () => {
expect(findAddNamespaceButton().exists()).toBe(expectNamespaceButton); expect(findEmptyState().exists()).toBe(expectEmptyState);
});
});
});
describe('with no subscriptions', () => {
describe.each`
scenario | usersPath | expectSignInButton | expectEmptyState
${'user is not signed in'} | ${'/users'} | ${true} | ${false}
${'user is signed in'} | ${undefined} | ${false} | ${true}
`('when $scenario', ({ usersPath, expectSignInButton, expectEmptyState }) => {
beforeEach(() => {
createComponent({
provide: {
usersPath,
subscriptions: [],
},
});
}); });
it('renders sign in button as expected', () => { it(`${
expect(findSignInButton().exists()).toBe(expectSignInButton); expectNamespaceButton ? 'renders' : 'does not render'
} button to add namespace`, () => {
expect(findAddNamespaceButton().exists()).toBe(expectNamespaceButton);
}); });
it('renders empty state as expected', () => { it(`${expectSubscriptionsList ? 'renders' : 'does not render'} subscriptions list`, () => {
expect(findEmptyState().exists()).toBe(expectEmptyState); expect(findSubscriptionsList().exists()).toBe(expectSubscriptionsList);
});
}); });
},
);
}); });
describe('alert', () => { describe('alert', () => {
......
...@@ -7,7 +7,7 @@ RSpec.describe 'jira_connect/subscriptions/index.html.haml' do ...@@ -7,7 +7,7 @@ RSpec.describe 'jira_connect/subscriptions/index.html.haml' do
before do before do
allow(view).to receive(:current_user).and_return(user) allow(view).to receive(:current_user).and_return(user)
assign(:subscriptions, []) assign(:subscriptions, create_list(:jira_connect_subscription, 1))
end end
context 'when the user is signed in' do context 'when the user is signed in' do
......
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