Skip to content
Snippets Groups Projects
Unverified Commit f666026d authored by Mike Greiling's avatar Mike Greiling
Browse files

Prettify all spec files

parent 5a6fffcf
No related branches found
No related tags found
1 merge request!10495Merge Requests - Assignee
Showing
with 323 additions and 324 deletions
Loading
Loading
@@ -10,8 +10,8 @@ describe('Ajax Loading Spinner', () => {
AjaxLoadingSpinner.init();
});
 
it('change current icon with spinner icon and disable link while waiting ajax response', (done) => {
spyOn($, 'ajax').and.callFake((req) => {
it('change current icon with spinner icon and disable link while waiting ajax response', done => {
spyOn($, 'ajax').and.callFake(req => {
const xhr = new XMLHttpRequest();
const ajaxLoadingSpinner = document.querySelector('.js-ajax-loading-spinner');
const icon = ajaxLoadingSpinner.querySelector('i');
Loading
Loading
@@ -33,8 +33,8 @@ describe('Ajax Loading Spinner', () => {
document.querySelector('.js-ajax-loading-spinner').click();
});
 
it('use original icon again and enabled the link after complete the ajax request', (done) => {
spyOn($, 'ajax').and.callFake((req) => {
it('use original icon again and enabled the link after complete the ajax request', done => {
spyOn($, 'ajax').and.callFake(req => {
const xhr = new XMLHttpRequest();
const ajaxLoadingSpinner = document.querySelector('.js-ajax-loading-spinner');
 
Loading
Loading
Loading
Loading
@@ -21,7 +21,7 @@ describe('avatar_helper', () => {
 
it(`wraps around if id is bigger than ${IDENTICON_BG_COUNT}`, () => {
expect(getIdenticonBackgroundClass(IDENTICON_BG_COUNT + 4)).toEqual('bg5');
expect(getIdenticonBackgroundClass((IDENTICON_BG_COUNT * 5) + 6)).toEqual('bg7');
expect(getIdenticonBackgroundClass(IDENTICON_BG_COUNT * 5 + 6)).toEqual('bg7');
});
});
 
Loading
Loading
import BindInOut from '~/behaviors/bind_in_out';
import ClassSpecHelper from '../helpers/class_spec_helper';
 
describe('BindInOut', function () {
describe('constructor', function () {
beforeEach(function () {
describe('BindInOut', function() {
describe('constructor', function() {
beforeEach(function() {
this.in = {};
this.out = {};
 
this.bindInOut = new BindInOut(this.in, this.out);
});
 
it('should set .in', function () {
it('should set .in', function() {
expect(this.bindInOut.in).toBe(this.in);
});
 
it('should set .out', function () {
it('should set .out', function() {
expect(this.bindInOut.out).toBe(this.out);
});
 
it('should set .eventWrapper', function () {
it('should set .eventWrapper', function() {
expect(this.bindInOut.eventWrapper).toEqual({});
});
 
describe('if .in is an input', function () {
beforeEach(function () {
describe('if .in is an input', function() {
beforeEach(function() {
this.bindInOut = new BindInOut({ tagName: 'INPUT' });
});
 
it('should set .eventType to keyup ', function () {
it('should set .eventType to keyup ', function() {
expect(this.bindInOut.eventType).toEqual('keyup');
});
});
 
describe('if .in is a textarea', function () {
beforeEach(function () {
describe('if .in is a textarea', function() {
beforeEach(function() {
this.bindInOut = new BindInOut({ tagName: 'TEXTAREA' });
});
 
it('should set .eventType to keyup ', function () {
it('should set .eventType to keyup ', function() {
expect(this.bindInOut.eventType).toEqual('keyup');
});
});
 
describe('if .in is not an input or textarea', function () {
beforeEach(function () {
describe('if .in is not an input or textarea', function() {
beforeEach(function() {
this.bindInOut = new BindInOut({ tagName: 'SELECT' });
});
 
it('should set .eventType to change ', function () {
it('should set .eventType to change ', function() {
expect(this.bindInOut.eventType).toEqual('change');
});
});
});
 
describe('addEvents', function () {
beforeEach(function () {
describe('addEvents', function() {
beforeEach(function() {
this.in = jasmine.createSpyObj('in', ['addEventListener']);
 
this.bindInOut = new BindInOut(this.in);
Loading
Loading
@@ -62,25 +62,24 @@ describe('BindInOut', function () {
this.addEvents = this.bindInOut.addEvents();
});
 
it('should set .eventWrapper.updateOut', function () {
it('should set .eventWrapper.updateOut', function() {
expect(this.bindInOut.eventWrapper.updateOut).toEqual(jasmine.any(Function));
});
 
it('should call .addEventListener', function () {
expect(this.in.addEventListener)
.toHaveBeenCalledWith(
this.bindInOut.eventType,
this.bindInOut.eventWrapper.updateOut,
);
it('should call .addEventListener', function() {
expect(this.in.addEventListener).toHaveBeenCalledWith(
this.bindInOut.eventType,
this.bindInOut.eventWrapper.updateOut,
);
});
 
it('should return the instance', function () {
it('should return the instance', function() {
expect(this.addEvents).toBe(this.bindInOut);
});
});
 
describe('updateOut', function () {
beforeEach(function () {
describe('updateOut', function() {
beforeEach(function() {
this.in = { value: 'the-value' };
this.out = { textContent: 'not-the-value' };
 
Loading
Loading
@@ -89,17 +88,17 @@ describe('BindInOut', function () {
this.updateOut = this.bindInOut.updateOut();
});
 
it('should set .out.textContent to .in.value', function () {
it('should set .out.textContent to .in.value', function() {
expect(this.out.textContent).toBe(this.in.value);
});
 
it('should return the instance', function () {
it('should return the instance', function() {
expect(this.updateOut).toBe(this.bindInOut);
});
});
 
describe('removeEvents', function () {
beforeEach(function () {
describe('removeEvents', function() {
beforeEach(function() {
this.in = jasmine.createSpyObj('in', ['removeEventListener']);
this.updateOut = () => {};
 
Loading
Loading
@@ -109,21 +108,20 @@ describe('BindInOut', function () {
this.removeEvents = this.bindInOut.removeEvents();
});
 
it('should call .removeEventListener', function () {
expect(this.in.removeEventListener)
.toHaveBeenCalledWith(
this.bindInOut.eventType,
this.updateOut,
);
it('should call .removeEventListener', function() {
expect(this.in.removeEventListener).toHaveBeenCalledWith(
this.bindInOut.eventType,
this.updateOut,
);
});
 
it('should return the instance', function () {
it('should return the instance', function() {
expect(this.removeEvents).toBe(this.bindInOut);
});
});
 
describe('initAll', function () {
beforeEach(function () {
describe('initAll', function() {
beforeEach(function() {
this.ins = [0, 1, 2];
this.instances = [];
 
Loading
Loading
@@ -136,43 +134,47 @@ describe('BindInOut', function () {
 
ClassSpecHelper.itShouldBeAStaticMethod(BindInOut, 'initAll');
 
it('should call .querySelectorAll', function () {
it('should call .querySelectorAll', function() {
expect(document.querySelectorAll).toHaveBeenCalledWith('*[data-bind-in]');
});
 
it('should call .map', function () {
it('should call .map', function() {
expect(Array.prototype.map).toHaveBeenCalledWith(jasmine.any(Function));
});
 
it('should call .init for each element', function () {
it('should call .init for each element', function() {
expect(BindInOut.init.calls.count()).toEqual(3);
});
 
it('should return an array of instances', function () {
it('should return an array of instances', function() {
expect(this.initAll).toEqual(jasmine.any(Array));
});
});
 
describe('init', function () {
beforeEach(function () {
spyOn(BindInOut.prototype, 'addEvents').and.callFake(function () { return this; });
spyOn(BindInOut.prototype, 'updateOut').and.callFake(function () { return this; });
describe('init', function() {
beforeEach(function() {
spyOn(BindInOut.prototype, 'addEvents').and.callFake(function() {
return this;
});
spyOn(BindInOut.prototype, 'updateOut').and.callFake(function() {
return this;
});
 
this.init = BindInOut.init({}, {});
});
 
ClassSpecHelper.itShouldBeAStaticMethod(BindInOut, 'init');
 
it('should call .addEvents', function () {
it('should call .addEvents', function() {
expect(BindInOut.prototype.addEvents).toHaveBeenCalled();
});
 
it('should call .updateOut', function () {
it('should call .updateOut', function() {
expect(BindInOut.prototype.updateOut).toHaveBeenCalled();
});
 
describe('if no anOut is provided', function () {
beforeEach(function () {
describe('if no anOut is provided', function() {
beforeEach(function() {
this.anIn = { dataset: { bindIn: 'the-data-bind-in' } };
 
spyOn(document, 'querySelector');
Loading
Loading
@@ -180,9 +182,10 @@ describe('BindInOut', function () {
BindInOut.init(this.anIn);
});
 
it('should call .querySelector', function () {
expect(document.querySelector)
.toHaveBeenCalledWith(`*[data-bind-out="${this.anIn.dataset.bindIn}"]`);
it('should call .querySelector', function() {
expect(document.querySelector).toHaveBeenCalledWith(
`*[data-bind-out="${this.anIn.dataset.bindIn}"]`,
);
});
});
});
Loading
Loading
Loading
Loading
@@ -56,7 +56,7 @@ describe('CopyAsGFM', () => {
const fragment = document.createDocumentFragment();
const node = document.createElement('div');
node.innerHTML = html;
Array.from(node.childNodes).forEach((item) => fragment.appendChild(item));
Array.from(node.childNodes).forEach(item => fragment.appendChild(item));
return fragment;
},
}),
Loading
Loading
Loading
Loading
@@ -13,7 +13,7 @@ describe('Unicode Support Map', () => {
spyOn(JSON, 'stringify').and.returnValue(stringSupportMap);
});
 
describe('if isLocalStorageAvailable is `true`', function () {
describe('if isLocalStorageAvailable is `true`', function() {
beforeEach(() => {
AccessorUtilities.isLocalStorageAccessSafe.and.returnValue(true);
 
Loading
Loading
@@ -36,7 +36,7 @@ describe('Unicode Support Map', () => {
});
});
 
describe('if isLocalStorageAvailable is `false`', function () {
describe('if isLocalStorageAvailable is `false`', function() {
beforeEach(() => {
AccessorUtilities.isLocalStorageAccessSafe.and.returnValue(false);
 
Loading
Loading
import $ from 'jquery';
import '~/behaviors/quick_submit';
 
describe('Quick Submit behavior', function () {
describe('Quick Submit behavior', function() {
const keydownEvent = (options = { keyCode: 13, metaKey: true }) => $.Event('keydown', options);
 
preloadFixtures('snippets/show.html.raw');
Loading
Loading
Loading
Loading
@@ -32,18 +32,30 @@ describe('requiresInput', () => {
 
it('enables submit when all required fields receive input', () => {
$('.js-requires-input').requiresInput();
$('#required1').val('input1').change();
$('#required1')
.val('input1')
.change();
 
expect(submitButton).toBeDisabled();
 
$('#optional1').val('input1').change();
$('#optional1')
.val('input1')
.change();
 
expect(submitButton).toBeDisabled();
 
$('#required2').val('input2').change();
$('#required3').val('input3').change();
$('#required4').val('input4').change();
$('#required5').val('1').change();
$('#required2')
.val('input2')
.change();
$('#required3')
.val('input3')
.change();
$('#required4')
.val('input4')
.change();
$('#required5')
.val('1')
.change();
 
expect($('.submit')).not.toBeDisabled();
});
Loading
Loading
Loading
Loading
@@ -36,12 +36,7 @@ function setupSecretFixture(
placeholderClass = 'js-secret-value-placeholder',
) {
const wrapper = document.createElement('div');
wrapper.innerHTML = generateFixtureMarkup(
secrets,
isRevealed,
valueClass,
placeholderClass,
);
wrapper.innerHTML = generateFixtureMarkup(secrets, isRevealed, valueClass, placeholderClass);
 
const secretValues = new SecretValues({
container: wrapper.querySelector('.js-secret-container'),
Loading
Loading
@@ -127,12 +122,12 @@ describe('setupSecretValues', () => {
const placeholders = wrapper.querySelectorAll('.js-secret-value-placeholder');
 
expect(values.length).toEqual(3);
values.forEach((value) => {
values.forEach(value => {
expect(value.classList.contains('hide')).toEqual(true);
});
 
expect(placeholders.length).toEqual(3);
placeholders.forEach((placeholder) => {
placeholders.forEach(placeholder => {
expect(placeholder.classList.contains('hide')).toEqual(false);
});
});
Loading
Loading
@@ -146,24 +141,24 @@ describe('setupSecretValues', () => {
revealButton.click();
 
expect(values.length).toEqual(3);
values.forEach((value) => {
values.forEach(value => {
expect(value.classList.contains('hide')).toEqual(false);
});
 
expect(placeholders.length).toEqual(3);
placeholders.forEach((placeholder) => {
placeholders.forEach(placeholder => {
expect(placeholder.classList.contains('hide')).toEqual(true);
});
 
revealButton.click();
 
expect(values.length).toEqual(3);
values.forEach((value) => {
values.forEach(value => {
expect(value.classList.contains('hide')).toEqual(true);
});
 
expect(placeholders.length).toEqual(3);
placeholders.forEach((placeholder) => {
placeholders.forEach(placeholder => {
expect(placeholder.classList.contains('hide')).toEqual(false);
});
});
Loading
Loading
@@ -175,7 +170,9 @@ describe('setupSecretValues', () => {
it('should toggle values and placeholders', () => {
const wrapper = setupSecretFixture(secrets, false);
// Insert the new dynamic row
wrapper.querySelector('.js-secret-container').insertAdjacentHTML('afterbegin', generateValueMarkup('foobarbazdynamic'));
wrapper
.querySelector('.js-secret-container')
.insertAdjacentHTML('afterbegin', generateValueMarkup('foobarbazdynamic'));
 
const revealButton = wrapper.querySelector('.js-secret-value-reveal-button');
const values = wrapper.querySelectorAll('.js-secret-value');
Loading
Loading
@@ -184,24 +181,24 @@ describe('setupSecretValues', () => {
revealButton.click();
 
expect(values.length).toEqual(4);
values.forEach((value) => {
values.forEach(value => {
expect(value.classList.contains('hide')).toEqual(false);
});
 
expect(placeholders.length).toEqual(4);
placeholders.forEach((placeholder) => {
placeholders.forEach(placeholder => {
expect(placeholder.classList.contains('hide')).toEqual(true);
});
 
revealButton.click();
 
expect(values.length).toEqual(4);
values.forEach((value) => {
values.forEach(value => {
expect(value.classList.contains('hide')).toEqual(true);
});
 
expect(placeholders.length).toEqual(4);
placeholders.forEach((placeholder) => {
placeholders.forEach(placeholder => {
expect(placeholder.classList.contains('hide')).toEqual(false);
});
});
Loading
Loading
import {
BoxGeometry,
} from 'three/build/three.module';
import { BoxGeometry } from 'three/build/three.module';
import MeshObject from '~/blob/3d_viewer/mesh_object';
 
describe('Mesh object', () => {
it('defaults to non-wireframe material', () => {
const object = new MeshObject(
new BoxGeometry(10, 10, 10),
);
const object = new MeshObject(new BoxGeometry(10, 10, 10));
 
expect(object.material.wireframe).toBeFalsy();
});
 
it('changes to wirefame material', () => {
const object = new MeshObject(
new BoxGeometry(10, 10, 10),
);
const object = new MeshObject(new BoxGeometry(10, 10, 10));
 
object.changeMaterial('wireframe');
 
Loading
Loading
@@ -23,18 +17,14 @@ describe('Mesh object', () => {
});
 
it('scales object down', () => {
const object = new MeshObject(
new BoxGeometry(10, 10, 10),
);
const object = new MeshObject(new BoxGeometry(10, 10, 10));
const { radius } = object.geometry.boundingSphere;
 
expect(radius).not.toBeGreaterThan(4);
});
 
it('does not scale object down', () => {
const object = new MeshObject(
new BoxGeometry(1, 1, 1),
);
const object = new MeshObject(new BoxGeometry(1, 1, 1));
const { radius } = object.geometry.boundingSphere;
 
expect(radius).toBeLessThan(1);
Loading
Loading
Loading
Loading
@@ -16,10 +16,13 @@ describe('Balsamiq integration spec', () => {
});
 
describe('successful response', () => {
beforeEach((done) => {
beforeEach(done => {
endpoint = bmprPath;
 
balsamiqViewer.loadFile(endpoint).then(done).catch(done.fail);
balsamiqViewer
.loadFile(endpoint)
.then(done)
.catch(done.fail);
});
 
it('does not show loading icon', () => {
Loading
Loading
@@ -32,10 +35,13 @@ describe('Balsamiq integration spec', () => {
});
 
describe('error getting file', () => {
beforeEach((done) => {
beforeEach(done => {
endpoint = 'invalid/path/to/file.bmpr';
 
balsamiqViewer.loadFile(endpoint).then(done.fail, null).catch(done);
balsamiqViewer
.loadFile(endpoint)
.then(done.fail, null)
.catch(done);
});
 
it('does not show loading icon', () => {
Loading
Loading
Loading
Loading
@@ -18,9 +18,7 @@ describe('BalsamiqViewer', () => {
});
});
 
describe('fileLoaded', () => {
});
describe('fileLoaded', () => {});
 
describe('loadFile', () => {
let xhr;
Loading
Loading
@@ -64,12 +62,16 @@ describe('BalsamiqViewer', () => {
viewer = jasmine.createSpyObj('viewer', ['appendChild']);
previews = [document.createElement('ul'), document.createElement('ul')];
 
balsamiqViewer = jasmine.createSpyObj('balsamiqViewer', ['initDatabase', 'getPreviews', 'renderPreview']);
balsamiqViewer = jasmine.createSpyObj('balsamiqViewer', [
'initDatabase',
'getPreviews',
'renderPreview',
]);
balsamiqViewer.viewer = viewer;
 
balsamiqViewer.getPreviews.and.returnValue(previews);
balsamiqViewer.renderPreview.and.callFake(preview => preview);
viewer.appendChild.and.callFake((containerElement) => {
viewer.appendChild.and.callFake(containerElement => {
container = containerElement;
});
 
Loading
Loading
@@ -198,7 +200,9 @@ describe('BalsamiqViewer', () => {
});
 
it('should call database.exec', () => {
expect(database.exec).toHaveBeenCalledWith(`SELECT * FROM resources WHERE id = '${resourceID}'`);
expect(database.exec).toHaveBeenCalledWith(
`SELECT * FROM resources WHERE id = '${resourceID}'`,
);
});
 
it('should return the selected resource', () => {
Loading
Loading
@@ -281,7 +285,7 @@ describe('BalsamiqViewer', () => {
expect(BalsamiqViewer.parseTitle).toHaveBeenCalledWith(resource);
});
 
it('should return the template string', function () {
it('should return the template string', function() {
expect(renderTemplate.replace(/\s/g, '')).toEqual(template.replace(/\s/g, ''));
});
});
Loading
Loading
import $ from 'jquery';
import BlobFileDropzone from '~/blob/blob_file_dropzone';
 
describe('BlobFileDropzone', function () {
describe('BlobFileDropzone', function() {
preloadFixtures('blob/show.html.raw');
 
beforeEach(() => {
Loading
Loading
Loading
Loading
@@ -16,8 +16,7 @@ describe('BlobForkSuggestion', () => {
cancelButtons: cancelButton,
suggestionSections: suggestionSection,
actionTextPieces: actionTextPiece,
})
.init();
}).init();
});
 
afterEach(() => {
Loading
Loading
Loading
Loading
@@ -12,29 +12,27 @@ describe('iPython notebook renderer', () => {
it('shows loading icon', () => {
renderNotebook();
 
expect(
document.querySelector('.loading'),
).not.toBeNull();
expect(document.querySelector('.loading')).not.toBeNull();
});
 
describe('successful response', () => {
let mock;
 
beforeEach((done) => {
beforeEach(done => {
mock = new MockAdapter(axios);
mock.onGet('/test').reply(200, {
cells: [{
cell_type: 'markdown',
source: ['# test'],
}, {
cell_type: 'code',
execution_count: 1,
source: [
'def test(str)',
' return str',
],
outputs: [],
}],
cells: [
{
cell_type: 'markdown',
source: ['# test'],
},
{
cell_type: 'code',
execution_count: 1,
source: ['def test(str)', ' return str'],
outputs: [],
},
],
});
 
renderNotebook();
Loading
Loading
@@ -49,35 +47,23 @@ describe('iPython notebook renderer', () => {
});
 
it('does not show loading icon', () => {
expect(
document.querySelector('.loading'),
).toBeNull();
expect(document.querySelector('.loading')).toBeNull();
});
 
it('renders the notebook', () => {
expect(
document.querySelector('.md'),
).not.toBeNull();
expect(document.querySelector('.md')).not.toBeNull();
});
 
it('renders the markdown cell', () => {
expect(
document.querySelector('h1'),
).not.toBeNull();
expect(document.querySelector('h1')).not.toBeNull();
 
expect(
document.querySelector('h1').textContent.trim(),
).toBe('test');
expect(document.querySelector('h1').textContent.trim()).toBe('test');
});
 
it('highlights code', () => {
expect(
document.querySelector('.token'),
).not.toBeNull();
expect(document.querySelector('.token')).not.toBeNull();
 
expect(
document.querySelector('.language-python'),
).not.toBeNull();
expect(document.querySelector('.language-python')).not.toBeNull();
});
});
 
Loading
Loading
@@ -86,12 +72,10 @@ describe('iPython notebook renderer', () => {
 
beforeEach(done => {
mock = new MockAdapter(axios);
mock
.onGet('/test')
.reply(() =>
// eslint-disable-next-line prefer-promise-reject-errors
Promise.reject({ status: 200, data: '{ "cells": [{"cell_type": "markdown"} }' }),
);
mock.onGet('/test').reply(() =>
// eslint-disable-next-line prefer-promise-reject-errors
Promise.reject({ status: 200, data: '{ "cells": [{"cell_type": "markdown"} }' }),
);
 
renderNotebook();
 
Loading
Loading
@@ -105,22 +89,20 @@ describe('iPython notebook renderer', () => {
});
 
it('does not show loading icon', () => {
expect(
document.querySelector('.loading'),
).toBeNull();
expect(document.querySelector('.loading')).toBeNull();
});
 
it('shows error message', () => {
expect(
document.querySelector('.md').textContent.trim(),
).toBe('An error occurred whilst parsing the file.');
expect(document.querySelector('.md').textContent.trim()).toBe(
'An error occurred whilst parsing the file.',
);
});
});
 
describe('error getting file', () => {
let mock;
 
beforeEach((done) => {
beforeEach(done => {
mock = new MockAdapter(axios);
mock.onGet('/test').reply(500, '');
 
Loading
Loading
@@ -136,15 +118,13 @@ describe('iPython notebook renderer', () => {
});
 
it('does not show loading icon', () => {
expect(
document.querySelector('.loading'),
).toBeNull();
expect(document.querySelector('.loading')).toBeNull();
});
 
it('shows error message', () => {
expect(
document.querySelector('.md').textContent.trim(),
).toBe('An error occurred whilst loading the file. Please try again later.');
expect(document.querySelector('.md').textContent.trim()).toBe(
'An error occurred whilst loading the file. Please try again later.',
);
});
});
});
Loading
Loading
@@ -5,7 +5,7 @@ describe('PDF renderer', () => {
let viewer;
let app;
 
const checkLoaded = (done) => {
const checkLoaded = done => {
if (app.loading) {
setTimeout(() => {
checkLoaded(done);
Loading
Loading
@@ -26,39 +26,31 @@ describe('PDF renderer', () => {
it('shows loading icon', () => {
renderPDF();
 
expect(
document.querySelector('.loading'),
).not.toBeNull();
expect(document.querySelector('.loading')).not.toBeNull();
});
 
describe('successful response', () => {
beforeEach((done) => {
beforeEach(done => {
app = renderPDF();
 
checkLoaded(done);
});
 
it('does not show loading icon', () => {
expect(
document.querySelector('.loading'),
).toBeNull();
expect(document.querySelector('.loading')).toBeNull();
});
 
it('renders the PDF', () => {
expect(
document.querySelector('.pdf-viewer'),
).not.toBeNull();
expect(document.querySelector('.pdf-viewer')).not.toBeNull();
});
 
it('renders the PDF page', () => {
expect(
document.querySelector('.pdf-page'),
).not.toBeNull();
expect(document.querySelector('.pdf-page')).not.toBeNull();
});
});
 
describe('error getting file', () => {
beforeEach((done) => {
beforeEach(done => {
viewer.dataset.endpoint = 'invalid/path/to/file.pdf';
app = renderPDF();
 
Loading
Loading
@@ -66,15 +58,13 @@ describe('PDF renderer', () => {
});
 
it('does not show loading icon', () => {
expect(
document.querySelector('.loading'),
).toBeNull();
expect(document.querySelector('.loading')).toBeNull();
});
 
it('shows error message', () => {
expect(
document.querySelector('.md').textContent.trim(),
).toBe('An error occurred whilst loading the file. Please try again later.');
expect(document.querySelector('.md').textContent.trim()).toBe(
'An error occurred whilst loading the file. Please try again later.',
);
});
});
});
Loading
Loading
@@ -4,15 +4,13 @@ import SketchLoader from '~/blob/sketch';
 
describe('Sketch viewer', () => {
const generateZipFileArrayBuffer = (zipFile, resolve, done) => {
zipFile
.generateAsync({ type: 'arrayBuffer' })
.then((content) => {
resolve(content);
setTimeout(() => {
done();
}, 100);
});
zipFile.generateAsync({ type: 'arrayBuffer' }).then(content => {
resolve(content);
setTimeout(() => {
done();
}, 100);
});
};
 
preloadFixtures('static/sketch_viewer.html.raw');
Loading
Loading
@@ -22,60 +20,63 @@ describe('Sketch viewer', () => {
});
 
describe('with error message', () => {
beforeEach((done) => {
spyOn(SketchLoader.prototype, 'getZipFile').and.callFake(() => new Promise((resolve, reject) => {
reject();
setTimeout(() => {
done();
});
}));
beforeEach(done => {
spyOn(SketchLoader.prototype, 'getZipFile').and.callFake(
() =>
new Promise((resolve, reject) => {
reject();
setTimeout(() => {
done();
});
}),
);
 
new SketchLoader(document.getElementById('js-sketch-viewer'));
});
 
it('renders error message', () => {
expect(
document.querySelector('#js-sketch-viewer p'),
).not.toBeNull();
expect(document.querySelector('#js-sketch-viewer p')).not.toBeNull();
 
expect(
document.querySelector('#js-sketch-viewer p').textContent.trim(),
).toContain('Cannot show preview.');
expect(document.querySelector('#js-sketch-viewer p').textContent.trim()).toContain(
'Cannot show preview.',
);
});
 
it('removes render the loading icon', () => {
expect(
document.querySelector('.js-loading-icon'),
).toBeNull();
expect(document.querySelector('.js-loading-icon')).toBeNull();
});
});
 
describe('success', () => {
beforeEach((done) => {
spyOn(SketchLoader.prototype, 'getZipFile').and.callFake(() => new Promise((resolve) => {
const zipFile = new JSZip();
zipFile.folder('previews')
.file('preview.png', 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAMAAAAoyzS7AAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAA1JREFUeNoBAgD9/wAAAAIAAVMrnDAAAAAASUVORK5CYII=', {
base64: true,
});
generateZipFileArrayBuffer(zipFile, resolve, done);
}));
beforeEach(done => {
spyOn(SketchLoader.prototype, 'getZipFile').and.callFake(
() =>
new Promise(resolve => {
const zipFile = new JSZip();
zipFile
.folder('previews')
.file(
'preview.png',
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAMAAAAoyzS7AAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAA1JREFUeNoBAgD9/wAAAAIAAVMrnDAAAAAASUVORK5CYII=',
{
base64: true,
},
);
generateZipFileArrayBuffer(zipFile, resolve, done);
}),
);
 
new SketchLoader(document.getElementById('js-sketch-viewer'));
});
 
it('does not render error message', () => {
expect(
document.querySelector('#js-sketch-viewer p'),
).toBeNull();
expect(document.querySelector('#js-sketch-viewer p')).toBeNull();
});
 
it('removes render the loading icon', () => {
expect(
document.querySelector('.js-loading-icon'),
).toBeNull();
expect(document.querySelector('.js-loading-icon')).toBeNull();
});
 
it('renders preview img', () => {
Loading
Loading
@@ -95,24 +96,25 @@ describe('Sketch viewer', () => {
});
 
describe('incorrect file', () => {
beforeEach((done) => {
spyOn(SketchLoader.prototype, 'getZipFile').and.callFake(() => new Promise((resolve) => {
const zipFile = new JSZip();
beforeEach(done => {
spyOn(SketchLoader.prototype, 'getZipFile').and.callFake(
() =>
new Promise(resolve => {
const zipFile = new JSZip();
 
generateZipFileArrayBuffer(zipFile, resolve, done);
}));
generateZipFileArrayBuffer(zipFile, resolve, done);
}),
);
 
new SketchLoader(document.getElementById('js-sketch-viewer'));
});
 
it('renders error message', () => {
expect(
document.querySelector('#js-sketch-viewer p'),
).not.toBeNull();
expect(document.querySelector('#js-sketch-viewer p')).not.toBeNull();
 
expect(
document.querySelector('#js-sketch-viewer p').textContent.trim(),
).toContain('Cannot show preview.');
expect(document.querySelector('#js-sketch-viewer p').textContent.trim()).toContain(
'Cannot show preview.',
);
});
});
});
Loading
Loading
@@ -35,12 +35,13 @@ describe('Blob viewer', () => {
window.location.hash = '';
});
 
it('loads source file after switching views', (done) => {
it('loads source file after switching views', done => {
document.querySelector('.js-blob-viewer-switch-btn[data-viewer="simple"]').click();
 
setTimeout(() => {
expect(
document.querySelector('.js-blob-viewer-switch-btn[data-viewer="simple"]')
document
.querySelector('.js-blob-viewer-switch-btn[data-viewer="simple"]')
.classList.contains('hidden'),
).toBeFalsy();
 
Loading
Loading
@@ -48,14 +49,15 @@ describe('Blob viewer', () => {
});
});
 
it('loads source file when line number is in hash', (done) => {
it('loads source file when line number is in hash', done => {
window.location.hash = '#L1';
 
new BlobViewer();
 
setTimeout(() => {
expect(
document.querySelector('.js-blob-viewer-switch-btn[data-viewer="simple"]')
document
.querySelector('.js-blob-viewer-switch-btn[data-viewer="simple"]')
.classList.contains('hidden'),
).toBeFalsy();
 
Loading
Loading
@@ -63,12 +65,13 @@ describe('Blob viewer', () => {
});
});
 
it('doesnt reload file if already loaded', (done) => {
const asyncClick = () => new Promise((resolve) => {
document.querySelector('.js-blob-viewer-switch-btn[data-viewer="simple"]').click();
it('doesnt reload file if already loaded', done => {
const asyncClick = () =>
new Promise(resolve => {
document.querySelector('.js-blob-viewer-switch-btn[data-viewer="simple"]').click();
 
setTimeout(resolve);
});
setTimeout(resolve);
});
 
asyncClick()
.then(() => asyncClick())
Loading
Loading
@@ -93,15 +96,13 @@ describe('Blob viewer', () => {
});
 
it('disabled on load', () => {
expect(
copyButton.classList.contains('disabled'),
).toBeTruthy();
expect(copyButton.classList.contains('disabled')).toBeTruthy();
});
 
it('has tooltip when disabled', () => {
expect(
copyButton.getAttribute('data-original-title'),
).toBe('Switch to the source to copy it to the clipboard');
expect(copyButton.getAttribute('data-original-title')).toBe(
'Switch to the source to copy it to the clipboard',
);
});
 
it('is blurred when clicked and disabled', () => {
Loading
Loading
@@ -121,25 +122,21 @@ describe('Blob viewer', () => {
expect(copyButton.blur).not.toHaveBeenCalled();
});
 
it('enables after switching to simple view', (done) => {
it('enables after switching to simple view', done => {
document.querySelector('.js-blob-viewer-switch-btn[data-viewer="simple"]').click();
 
setTimeout(() => {
expect(
copyButton.classList.contains('disabled'),
).toBeFalsy();
expect(copyButton.classList.contains('disabled')).toBeFalsy();
 
done();
});
});
 
it('updates tooltip after switching to simple view', (done) => {
it('updates tooltip after switching to simple view', done => {
document.querySelector('.js-blob-viewer-switch-btn[data-viewer="simple"]').click();
 
setTimeout(() => {
expect(
copyButton.getAttribute('data-original-title'),
).toBe('Copy source to clipboard');
expect(copyButton.getAttribute('data-original-title')).toBe('Copy source to clipboard');
 
done();
});
Loading
Loading
@@ -162,9 +159,7 @@ describe('Blob viewer', () => {
 
blob.switchToViewer('simple');
 
expect(
simpleBtn.classList.contains('active'),
).toBeTruthy();
expect(simpleBtn.classList.contains('active')).toBeTruthy();
 
expect(simpleBtn.blur).toHaveBeenCalled();
});
Loading
Loading
Loading
Loading
@@ -7,29 +7,35 @@ describe('Boards blank state', () => {
let vm;
let fail = false;
 
beforeEach((done) => {
beforeEach(done => {
const Comp = Vue.extend(BoardBlankState);
 
boardsStore.create();
gl.boardService = mockBoardService();
 
spyOn(gl.boardService, 'generateDefaultLists').and.callFake(() => new Promise((resolve, reject) => {
if (fail) {
reject();
} else {
resolve({
data: [{
id: 1,
title: 'To Do',
label: { id: 1 },
}, {
id: 2,
title: 'Doing',
label: { id: 2 },
}],
});
}
}));
spyOn(gl.boardService, 'generateDefaultLists').and.callFake(
() =>
new Promise((resolve, reject) => {
if (fail) {
reject();
} else {
resolve({
data: [
{
id: 1,
title: 'To Do',
label: { id: 1 },
},
{
id: 2,
title: 'Doing',
label: { id: 2 },
},
],
});
}
}),
);
 
vm = new Comp();
 
Loading
Loading
@@ -40,20 +46,18 @@ describe('Boards blank state', () => {
});
 
it('renders pre-defined labels', () => {
expect(
vm.$el.querySelectorAll('.board-blank-state-list li').length,
).toBe(2);
expect(vm.$el.querySelectorAll('.board-blank-state-list li').length).toBe(2);
 
expect(
vm.$el.querySelectorAll('.board-blank-state-list li')[0].textContent.trim(),
).toEqual('To Do');
expect(vm.$el.querySelectorAll('.board-blank-state-list li')[0].textContent.trim()).toEqual(
'To Do',
);
 
expect(
vm.$el.querySelectorAll('.board-blank-state-list li')[1].textContent.trim(),
).toEqual('Doing');
expect(vm.$el.querySelectorAll('.board-blank-state-list li')[1].textContent.trim()).toEqual(
'Doing',
);
});
 
it('clears blank state', (done) => {
it('clears blank state', done => {
vm.$el.querySelector('.btn-default').click();
 
setTimeout(() => {
Loading
Loading
@@ -63,7 +67,7 @@ describe('Boards blank state', () => {
});
});
 
it('creates pre-defined labels', (done) => {
it('creates pre-defined labels', done => {
vm.$el.querySelector('.btn-success').click();
 
setTimeout(() => {
Loading
Loading
@@ -75,7 +79,7 @@ describe('Boards blank state', () => {
});
});
 
it('resets the store if request fails', (done) => {
it('resets the store if request fails', done => {
fail = true;
 
vm.$el.querySelector('.btn-success').click();
Loading
Loading
Loading
Loading
@@ -18,7 +18,7 @@ describe('Board card', () => {
let vm;
let mock;
 
beforeEach((done) => {
beforeEach(done => {
mock = new MockAdapter(axios);
mock.onAny().reply(boardsMockInterceptor);
 
Loading
Loading
@@ -71,7 +71,7 @@ describe('Board card', () => {
expect(vm.$el.classList.contains('user-can-drag')).toBe(true);
});
 
it('does not add user-can-drag class disabled', (done) => {
it('does not add user-can-drag class disabled', done => {
vm.disabled = true;
 
setTimeout(() => {
Loading
Loading
@@ -84,7 +84,7 @@ describe('Board card', () => {
expect(vm.$el.classList.contains('is-disabled')).toBe(false);
});
 
it('adds disabled class is disabled is true', (done) => {
it('adds disabled class is disabled is true', done => {
vm.disabled = true;
 
setTimeout(() => {
Loading
Loading
@@ -96,8 +96,23 @@ describe('Board card', () => {
describe('mouse events', () => {
const triggerEvent = (eventName, el = vm.$el) => {
const event = document.createEvent('MouseEvents');
event.initMouseEvent(eventName, true, true, window, 1, 0, 0, 0, 0, false, false,
false, false, 0, null);
event.initMouseEvent(
eventName,
true,
true,
window,
1,
0,
0,
0,
0,
false,
false,
false,
false,
0,
null,
);
 
el.dispatchEvent(event);
};
Loading
Loading
@@ -134,13 +149,15 @@ describe('Board card', () => {
expect(boardsStore.detail.issue).toEqual({});
});
 
it('does not set detail issue if img is clicked', (done) => {
vm.issue.assignees = [new ListAssignee({
id: 1,
name: 'testing 123',
username: 'test',
avatar: 'test_image',
})];
it('does not set detail issue if img is clicked', done => {
vm.issue.assignees = [
new ListAssignee({
id: 1,
name: 'testing 123',
username: 'test',
avatar: 'test_image',
}),
];
 
Vue.nextTick(() => {
triggerEvent('mouseup', vm.$el.querySelector('img'));
Loading
Loading
@@ -167,7 +184,7 @@ describe('Board card', () => {
expect(boardsStore.detail.list).toEqual(vm.list);
});
 
it('adds active class if detail issue is set', (done) => {
it('adds active class if detail issue is set', done => {
vm.detailIssue.issue = vm.issue;
 
Vue.nextTick()
Loading
Loading
Loading
Loading
@@ -28,7 +28,7 @@ describe('Issue boards new issue form', () => {
return vm.submit(dummySubmitEvent);
};
 
beforeEach((done) => {
beforeEach(done => {
setFixtures('<div class="test-container"></div>');
 
const BoardNewIssueComp = Vue.extend(boardNewIssue);
Loading
Loading
@@ -60,7 +60,7 @@ describe('Issue boards new issue form', () => {
mock.restore();
});
 
it('calls submit if submit button is clicked', (done) => {
it('calls submit if submit button is clicked', done => {
spyOn(vm, 'submit').and.callFake(e => e.preventDefault());
vm.title = 'Testing Title';
 
Loading
Loading
@@ -78,7 +78,7 @@ describe('Issue boards new issue form', () => {
expect(vm.$el.querySelector('.btn-success').disabled).toBe(true);
});
 
it('enables submit button if title is not empty', (done) => {
it('enables submit button if title is not empty', done => {
vm.title = 'Testing Title';
 
Vue.nextTick()
Loading
Loading
@@ -90,7 +90,7 @@ describe('Issue boards new issue form', () => {
.catch(done.fail);
});
 
it('clears title after clicking cancel', (done) => {
it('clears title after clicking cancel', done => {
vm.$el.querySelector('.btn-default').click();
 
Vue.nextTick()
Loading
Loading
@@ -101,7 +101,7 @@ describe('Issue boards new issue form', () => {
.catch(done.fail);
});
 
it('does not create new issue if title is empty', (done) => {
it('does not create new issue if title is empty', done => {
submitIssue()
.then(() => {
expect(list.newIssue).not.toHaveBeenCalled();
Loading
Loading
@@ -111,7 +111,7 @@ describe('Issue boards new issue form', () => {
});
 
describe('submit success', () => {
it('creates new issue', (done) => {
it('creates new issue', done => {
vm.title = 'submit title';
 
Vue.nextTick()
Loading
Loading
@@ -123,7 +123,7 @@ describe('Issue boards new issue form', () => {
.catch(done.fail);
});
 
it('enables button after submit', (done) => {
it('enables button after submit', done => {
vm.title = 'submit issue';
 
Vue.nextTick()
Loading
Loading
@@ -135,7 +135,7 @@ describe('Issue boards new issue form', () => {
.catch(done.fail);
});
 
it('clears title after submit', (done) => {
it('clears title after submit', done => {
vm.title = 'submit issue';
 
Vue.nextTick()
Loading
Loading
@@ -147,7 +147,7 @@ describe('Issue boards new issue form', () => {
.catch(done.fail);
});
 
it('sets detail issue after submit', (done) => {
it('sets detail issue after submit', done => {
expect(boardsStore.detail.issue.title).toBe(undefined);
vm.title = 'submit issue';
 
Loading
Loading
@@ -160,7 +160,7 @@ describe('Issue boards new issue form', () => {
.catch(done.fail);
});
 
it('sets detail list after submit', (done) => {
it('sets detail list after submit', done => {
vm.title = 'submit issue';
 
Vue.nextTick()
Loading
Loading
@@ -179,7 +179,7 @@ describe('Issue boards new issue form', () => {
vm.title = 'error';
});
 
it('removes issue', (done) => {
it('removes issue', done => {
Vue.nextTick()
.then(submitIssue)
.then(() => {
Loading
Loading
@@ -189,7 +189,7 @@ describe('Issue boards new issue form', () => {
.catch(done.fail);
});
 
it('shows error', (done) => {
it('shows error', done => {
Vue.nextTick()
.then(submitIssue)
.then(() => {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment