From 935d8241127e04cddfdec0ff7d815ed7afbe5282 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 9 Apr 2019 22:07:07 +0100 Subject: [PATCH] Add tests for AppBreadcrumb component Fixes #8 --- src/components/AppBreadcrumb.vue | 18 ++++++------ tests/unit/.eslintrc.js | 2 +- tests/unit/api_client.spec.js | 2 +- tests/unit/app_breadcrumb.spec.js | 47 +++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 tests/unit/app_breadcrumb.spec.js diff --git a/src/components/AppBreadcrumb.vue b/src/components/AppBreadcrumb.vue index c637f3e..75c06ec 100644 --- a/src/components/AppBreadcrumb.vue +++ b/src/components/AppBreadcrumb.vue @@ -40,11 +40,19 @@ export default { }, computed: { - selectedApplication: function () { + selectedOrganisation: function () { if (!this.application) { return 'All' } + return 'Rebuilding Acquia' + }, + + selectedApplication: function () { + if (!this.application) { + return null + } + return this.application.name }, @@ -58,14 +66,6 @@ export default { } return this.environment.name - }, - - selectedOrganisation: function () { - if (!this.application) { - return null - } - - return 'Rebuilding Acquia' } } } diff --git a/tests/unit/.eslintrc.js b/tests/unit/.eslintrc.js index 013a195..958d51b 100644 --- a/tests/unit/.eslintrc.js +++ b/tests/unit/.eslintrc.js @@ -2,4 +2,4 @@ module.exports = { env: { jest: true } -} \ No newline at end of file +} diff --git a/tests/unit/api_client.spec.js b/tests/unit/api_client.spec.js index 7ca8dff..ecd0e4a 100644 --- a/tests/unit/api_client.spec.js +++ b/tests/unit/api_client.spec.js @@ -153,7 +153,7 @@ test('it can get the type of an application', () => { }, symfony: { type: 'symfony' - }, + } } _.forEach(applications, (application, expected) => { diff --git a/tests/unit/app_breadcrumb.spec.js b/tests/unit/app_breadcrumb.spec.js new file mode 100644 index 0000000..86f08b9 --- /dev/null +++ b/tests/unit/app_breadcrumb.spec.js @@ -0,0 +1,47 @@ +import AppBreadcrumb from '@/components/AppBreadcrumb.vue' +import { RouterLinkStub, shallowMount } from '@vue/test-utils' + +const stubs = { + RouterLink: RouterLinkStub +} + +test('it returns default values', () => { + const wrapper = shallowMount(AppBreadcrumb, { stubs }) + + expect(wrapper.vm.selectedOrganisation).toBe('All') + expect(wrapper.vm.selectedApplication).toBe(null) + expect(wrapper.vm.selectedEnvironment).toBe(null) +}) + +test('it returns the organisation and application names', () => { + const wrapper = shallowMount(AppBreadcrumb, { + propsData: { + application: { + name: 'Oliver Davies' + } + }, + stubs + }) + + expect(wrapper.vm.selectedOrganisation).toBe('Rebuilding Acquia') + expect(wrapper.vm.selectedApplication).toBe('Oliver Davies') + expect(wrapper.vm.selectedEnvironment).toBe('All') +}) + +test('it returns the environment name', () => { + const wrapper = shallowMount(AppBreadcrumb, { + propsData: { + application: { + name: 'Oliver Davies' + }, + environment: { + name: 'Dev' + } + }, + stubs + }) + + expect(wrapper.vm.selectedOrganisation).toBe('Rebuilding Acquia') + expect(wrapper.vm.selectedApplication).toBe('Oliver Davies') + expect(wrapper.vm.selectedEnvironment).toBe('Dev') +})