From b77c0a57cc089a554ee874ae9ff5ff53e6b5eb99 Mon Sep 17 00:00:00 2001 From: Pitu Date: Mon, 4 Jan 2021 00:48:34 +0900 Subject: feat: add testing capabilities --- src/site/components/footer/Footer.test.js | 25 +++++++++++++++++++++++++ src/tests/api/verify.test.js | 12 ++++++++++++ src/tests/e2e/index.test.js | 20 ++++++++++++++++++++ src/tests/utils.js | 11 +++++++++++ 4 files changed, 68 insertions(+) create mode 100644 src/site/components/footer/Footer.test.js create mode 100644 src/tests/api/verify.test.js create mode 100644 src/tests/e2e/index.test.js create mode 100644 src/tests/utils.js (limited to 'src') diff --git a/src/site/components/footer/Footer.test.js b/src/site/components/footer/Footer.test.js new file mode 100644 index 0000000..379f939 --- /dev/null +++ b/src/site/components/footer/Footer.test.js @@ -0,0 +1,25 @@ +/* eslint-disable no-undef */ +import { shallowMount, createLocalVue } from '@vue/test-utils'; +import Component from './Footer.vue'; +import Vuex from 'vuex'; + +const localVue = createLocalVue(); +localVue.use(Vuex); + +describe('Footer.vue', () => { + const store = new Vuex.Store({ + getters: { + 'auth/isLoggedIn': () => false + }, + state: { + config: {} + } + }); + + it('Should render chibisafe as the instance title', () => { + const wrapper = shallowMount(Component, { store, localVue }); + + const title = wrapper.find('h4'); + expect(title.text()).toBe('chibisafe'); + }); +}); diff --git a/src/tests/api/verify.test.js b/src/tests/api/verify.test.js new file mode 100644 index 0000000..34bc45e --- /dev/null +++ b/src/tests/api/verify.test.js @@ -0,0 +1,12 @@ +/* eslint-disable no-undef */ +import { axios } from '../utils'; + +// This should never succeed as we are not passing a token. We are expecting a 401 +test('Verify token', async () => { + try { + await axios.get('/api/verify'); + expect(true).toBe(false); + } catch (err) { + expect(err.response.status).toBe(401); + } +}); diff --git a/src/tests/e2e/index.test.js b/src/tests/e2e/index.test.js new file mode 100644 index 0000000..ca45efd --- /dev/null +++ b/src/tests/e2e/index.test.js @@ -0,0 +1,20 @@ +/* eslint-disable no-undef */ +const puppeteer = require('puppeteer'); + +test('Check the logo renders', async () => { + const browser = await puppeteer.launch({ + headless: true + }); + const page = await browser.newPage(); + + await page.goto('http://localhost:5000', { + timeout: 45000, + waitUntil: ['networkidle2'] + }); + + // Check the logo exists + const logo = await page.waitForSelector('.logoContainer'); + await browser.close(); + + expect(logo).toBeTruthy(); +}); diff --git a/src/tests/utils.js b/src/tests/utils.js new file mode 100644 index 0000000..3634ed9 --- /dev/null +++ b/src/tests/utils.js @@ -0,0 +1,11 @@ +const axios = require('axios'); +const instance = axios.create({ + baseURL: 'http://localhost:5000', + headers: { + common: { + accept: 'application/vnd.chibisafe.json' + } + } +}); + +module.exports.axios = instance; -- cgit v1.2.3