From 2844d50c561bb91321192112a0a876957ae93488 Mon Sep 17 00:00:00 2001 From: hemanth-hk Date: Mon, 6 Apr 2020 15:01:11 +0530 Subject: [PATCH 1/3] Added e2e tests for LicenseUseCard component --- tests/e2e/specs/LicenseUseCard.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/e2e/specs/LicenseUseCard.js diff --git a/tests/e2e/specs/LicenseUseCard.js b/tests/e2e/specs/LicenseUseCard.js new file mode 100644 index 000000000..b1113ccda --- /dev/null +++ b/tests/e2e/specs/LicenseUseCard.js @@ -0,0 +1,31 @@ +module.exports = { + + 'Check if the main div tag with the class license-use-card is present': function(browser) { + browser + .init() + .assert.elementPresent('.control-label > span') + .click('.control-label > span') + .assert.elementPresent('.pagination-next') + .click('.pagination-next') + .assert.elementPresent('.select') + .click('.select') + .click('option[value="CC BY 4.0"]') + .assert.elementPresent('.pagination-next') + .click('.pagination-next') + .assert.elementPresent('.license-use-card') + }, + 'Check if the elements are present inside the main div': function(browser) { + browser + .assert.elementPresent('.license-use-card h4') + .assert.elementPresent('nav[class="tabs"]') + .assert.elementPresent('.tab-content') + .assert.elementPresent('.license-use-instructions') + .expect.element('.license-use-instructions').text.to.equal('Choose what kind of work you are licensing to get appropriate license code.') + }, + 'Check if the tab items are present in the DOM': function(browser) { + browser + .assert.elementPresent('.tab-item') + .assert.elementPresent('.tab-content > div:nth-child(1)') + .assert.elementPresent('.tab-content > div:nth-child(2)') + } +} From 741661da5985531ac6d72e88cce9151161fd19e0 Mon Sep 17 00:00:00 2001 From: hemanth-hk Date: Mon, 6 Apr 2020 15:01:36 +0530 Subject: [PATCH 2/3] Added unit tests for LicenseUseCard component --- .../specs/components/LicenseUseCard.spec.js | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/unit/specs/components/LicenseUseCard.spec.js diff --git a/tests/unit/specs/components/LicenseUseCard.spec.js b/tests/unit/specs/components/LicenseUseCard.spec.js new file mode 100644 index 000000000..cbb5c190b --- /dev/null +++ b/tests/unit/specs/components/LicenseUseCard.spec.js @@ -0,0 +1,57 @@ +import { shallowMount, createLocalVue, config } from '@vue/test-utils' +import LicenseUseCard from '@/components/LicenseUseCard.vue' +import VueI18n from 'vue-i18n' +import Buefy from 'buefy' + +describe('LicenseUseCard.vue', () => { + let wrapper + + // Always creates a shallow instance of component + beforeEach(() => { + const localVue = createLocalVue() + localVue.use(VueI18n) + localVue.use(Buefy) + const messages = require('@/locales/en.json') + const i18n = new VueI18n({ + locale: 'en', + fallbackLocale: 'en', + messages: messages, + silentTranslationWarn: true + }) + + config.mocks.i18n = i18n + + config.mocks.$t = (key) => { + return i18n.messages[key] + } + wrapper = shallowMount(LicenseUseCard, { + localVue, + i18n + }) + }) + + it('Check if the LicenseUseCard.vue component renders without any errors', () => { + expect(wrapper.isVueInstance()).toBeTruthy() + }) + + // Test for DOM elements which must be present + it('Check if the main div tag with the class license-use-card is present', () => { + expect(wrapper.contains('.license-use-card')).toBe(true) + }) + it('Check if the main header is present in the DOM', () => { + expect(wrapper.contains('.license-use-card h4')).toBe(true) + }) + it('Check if the common instructions are present in the DOM', () => { + expect(wrapper.contains('.license-use-instructions')).toBe(true) + }) + it('Check if the tab and the tab items are present in the DOM', () => { + expect(wrapper.contains('b-tabs-stub')).toBe(true) + expect(wrapper.contains('b-tab-item-stub')).toBe(true) + expect(wrapper.findAll('b-tab-item-stub').length).toBe(2) + }) + + // Snapshot tests + it('LicenseUseCard.vue component has the expected UI', () => { + expect(wrapper).toMatchSnapshot() + }) +}) From 2087a90ecd0f4902223ce493f998b00f6d867df0 Mon Sep 17 00:00:00 2001 From: hemanth-hk Date: Mon, 6 Apr 2020 15:02:11 +0530 Subject: [PATCH 3/3] Generated snap for LicenseUseCard component --- .../__snapshots__/LicenseUseCard.spec.js.snap | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/unit/specs/components/__snapshots__/LicenseUseCard.spec.js.snap diff --git a/tests/unit/specs/components/__snapshots__/LicenseUseCard.spec.js.snap b/tests/unit/specs/components/__snapshots__/LicenseUseCard.spec.js.snap new file mode 100644 index 000000000..643bf2b84 --- /dev/null +++ b/tests/unit/specs/components/__snapshots__/LicenseUseCard.spec.js.snap @@ -0,0 +1,22 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`LicenseUseCard.vue LicenseUseCard.vue component has the expected UI 1`] = ` +
+

+ +

+

+ +

+ + + + + + + + + + +
+`;