diff options
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/fly_out_nav_browser_spec.js | 9 | ||||
-rw-r--r-- | spec/javascripts/lib/utils/browser_spec.js | 106 | ||||
-rw-r--r-- | spec/javascripts/matchers.js | 7 | ||||
-rw-r--r-- | spec/javascripts/test_bundle.js | 20 | ||||
-rw-r--r-- | spec/javascripts/test_constants.js | 2 |
5 files changed, 20 insertions, 124 deletions
diff --git a/spec/javascripts/fly_out_nav_browser_spec.js b/spec/javascripts/fly_out_nav_browser_spec.js index f84cee72042..f92994594a9 100644 --- a/spec/javascripts/fly_out_nav_browser_spec.js +++ b/spec/javascripts/fly_out_nav_browser_spec.js @@ -157,7 +157,7 @@ describe('Fly out sidebar navigation', () => { '<div class="sidebar-sub-level-items" style="position: absolute; top: 0; left: 100px; height: 200px;"></div>'; }); - it('shows sub-items after 0ms if no menu is open', done => { + it('shows sub-items after 0ms if no menu is open', (done) => { mouseEnterTopItems(el); expect(getHideSubItemsInterval()).toBe(0); @@ -169,7 +169,7 @@ describe('Fly out sidebar navigation', () => { }); }); - it('shows sub-items after 300ms if a menu is currently open', done => { + it('shows sub-items after 300ms if a menu is currently open', (done) => { documentMouseMove({ clientX: el.getBoundingClientRect().left, clientY: el.getBoundingClientRect().top, @@ -255,8 +255,9 @@ describe('Fly out sidebar navigation', () => { showSubLevelItems(el); expect(subItems.style.transform).toBe( - `translate3d(200px, ${Math.floor(el.getBoundingClientRect().top) - - getHeaderHeight()}px, 0px)`, + `translate3d(200px, ${ + Math.floor(el.getBoundingClientRect().top) - getHeaderHeight() + }px, 0px)`, ); }); diff --git a/spec/javascripts/lib/utils/browser_spec.js b/spec/javascripts/lib/utils/browser_spec.js index 6b1074a3b4f..f41fa2503b1 100644 --- a/spec/javascripts/lib/utils/browser_spec.js +++ b/spec/javascripts/lib/utils/browser_spec.js @@ -5,30 +5,8 @@ * https://gitlab.com/groups/gitlab-org/-/epics/895#what-if-theres-a-karma-spec-which-is-simply-unmovable-to-jest-ie-it-is-dependent-on-a-running-browser-environment */ -import MockAdapter from 'axios-mock-adapter'; import { GlBreakpointInstance as breakpointInstance } from '@gitlab/ui/dist/utils'; -import axios from '~/lib/utils/axios_utils'; import * as commonUtils from '~/lib/utils/common_utils'; -import { faviconDataUrl, overlayDataUrl, faviconWithOverlayDataUrl } from './mock_data'; - -const PIXEL_TOLERANCE = 0.2; - -/** - * Loads a data URL as the src of an - * {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image|Image} - * and resolves to that Image once loaded. - * - * @param url - * @returns {Promise} - */ -const urlToImage = url => - new Promise(resolve => { - const img = new Image(); - img.onload = function() { - resolve(img); - }; - img.src = url; - }); describe('common_utils browser specific specs', () => { describe('contentTop', () => { @@ -63,90 +41,6 @@ describe('common_utils browser specific specs', () => { }); }); - describe('createOverlayIcon', () => { - it('should return the favicon with the overlay', done => { - commonUtils - .createOverlayIcon(faviconDataUrl, overlayDataUrl) - .then(url => Promise.all([urlToImage(url), urlToImage(faviconWithOverlayDataUrl)])) - .then(([actual, expected]) => { - expect(actual).toImageDiffEqual(expected, PIXEL_TOLERANCE); - done(); - }) - .catch(done.fail); - }); - }); - - describe('setFaviconOverlay', () => { - beforeEach(() => { - const favicon = document.createElement('link'); - favicon.setAttribute('id', 'favicon'); - favicon.setAttribute('data-original-href', faviconDataUrl); - document.body.appendChild(favicon); - }); - - afterEach(() => { - document.body.removeChild(document.getElementById('favicon')); - }); - - it('should set page favicon to provided favicon overlay', done => { - commonUtils - .setFaviconOverlay(overlayDataUrl) - .then(() => document.getElementById('favicon').getAttribute('href')) - .then(url => Promise.all([urlToImage(url), urlToImage(faviconWithOverlayDataUrl)])) - .then(([actual, expected]) => { - expect(actual).toImageDiffEqual(expected, PIXEL_TOLERANCE); - done(); - }) - .catch(done.fail); - }); - }); - - describe('setCiStatusFavicon', () => { - const BUILD_URL = `${gl.TEST_HOST}/frontend-fixtures/builds-project/-/jobs/1/status.json`; - let mock; - - beforeEach(() => { - const favicon = document.createElement('link'); - favicon.setAttribute('id', 'favicon'); - favicon.setAttribute('href', 'null'); - favicon.setAttribute('data-original-href', faviconDataUrl); - document.body.appendChild(favicon); - mock = new MockAdapter(axios); - }); - - afterEach(() => { - mock.restore(); - document.body.removeChild(document.getElementById('favicon')); - }); - - it('should reset favicon in case of error', done => { - mock.onGet(BUILD_URL).replyOnce(500); - - commonUtils.setCiStatusFavicon(BUILD_URL).catch(() => { - const favicon = document.getElementById('favicon'); - - expect(favicon.getAttribute('href')).toEqual(faviconDataUrl); - done(); - }); - }); - - it('should set page favicon to CI status favicon based on provided status', done => { - mock.onGet(BUILD_URL).reply(200, { - favicon: overlayDataUrl, - }); - - commonUtils - .setCiStatusFavicon(BUILD_URL) - .then(() => document.getElementById('favicon').getAttribute('href')) - .then(url => Promise.all([urlToImage(url), urlToImage(faviconWithOverlayDataUrl)])) - .then(([actual, expected]) => { - expect(actual).toImageDiffEqual(expected, PIXEL_TOLERANCE); - done(); - }) - .catch(done.fail); - }); - }); - describe('isInViewport', () => { let el; diff --git a/spec/javascripts/matchers.js b/spec/javascripts/matchers.js index 5b7b7dc78b1..ae005e152ed 100644 --- a/spec/javascripts/matchers.js +++ b/spec/javascripts/matchers.js @@ -2,7 +2,7 @@ import pixelmatch from 'pixelmatch'; export default { toImageDiffEqual: () => { - const getImageData = img => { + const getImageData = (img) => { const canvas = document.createElement('canvas'); canvas.width = img.width; canvas.height = img.height; @@ -32,8 +32,9 @@ export default { return { pass: differentPixels < 20, - message: `${differentPixels} pixels differ more than ${threshold * - 100} percent between input and output.`, + message: `${differentPixels} pixels differ more than ${ + threshold * 100 + } percent between input and output.`, }; }, }; diff --git a/spec/javascripts/test_bundle.js b/spec/javascripts/test_bundle.js index b37a53515a6..59136de0b0d 100644 --- a/spec/javascripts/test_bundle.js +++ b/spec/javascripts/test_bundle.js @@ -30,7 +30,7 @@ Vue.config.warnHandler = (msg, vm, trace) => { const currentStack = new Error().stack; const isInVueTestUtils = currentStack .split('\n') - .some(line => line.startsWith(' at VueWrapper.setProps (')); + .some((line) => line.startsWith(' at VueWrapper.setProps (')); if (isInVueTestUtils) { return; } @@ -40,7 +40,7 @@ Vue.config.warnHandler = (msg, vm, trace) => { }; let hasVueErrors = false; -Vue.config.errorHandler = function(err) { +Vue.config.errorHandler = function (err) { hasVueErrors = true; fail(err); }; @@ -75,7 +75,7 @@ gon.relative_url_root = ''; let hasUnhandledPromiseRejections = false; -window.addEventListener('unhandledrejection', event => { +window.addEventListener('unhandledrejection', (event) => { hasUnhandledPromiseRejections = true; console.error('Unhandled promise rejection:'); console.error(event.reason.stack || event.reason); @@ -87,11 +87,11 @@ window.addEventListener('unhandledrejection', event => { // enough for the socket to continue to communicate. // The downside is that it creates a minor performance penalty in the time it takes // to run our unit tests. -beforeEach(done => done()); +beforeEach((done) => done()); let longRunningTestTimeoutHandle; -beforeEach(done => { +beforeEach((done) => { longRunningTestTimeoutHandle = setTimeout(() => { done.fail('Test is running too long!'); }, 4000); @@ -111,15 +111,15 @@ if (process.env.IS_EE) { testContexts.push(require.context('ee_spec', true, /_spec$/)); } -testContexts.forEach(context => { - context.keys().forEach(path => { +testContexts.forEach((context) => { + context.keys().forEach((path) => { try { context(path); } catch (err) { console.log(err); console.error('[GL SPEC RUNNER ERROR] Unable to load spec: ', path); - describe('Test bundle', function() { - it(`includes '${path}'`, function() { + describe('Test bundle', function () { + it(`includes '${path}'`, function () { expect(err).toBeNull(); }); }); @@ -128,7 +128,7 @@ testContexts.forEach(context => { }); describe('test errors', () => { - beforeAll(done => { + beforeAll((done) => { if (hasUnhandledPromiseRejections || hasVueWarnings || hasVueErrors) { setTimeout(done, 1000); } else { diff --git a/spec/javascripts/test_constants.js b/spec/javascripts/test_constants.js index 51c0716b99d..de7b3a0e80c 100644 --- a/spec/javascripts/test_constants.js +++ b/spec/javascripts/test_constants.js @@ -1 +1 @@ -export * from '../frontend/helpers/test_constants'; +export * from '../frontend/__helpers__/test_constants'; |