enable jasmine/new-line-before-expect

parent 28d412e5
...@@ -36,5 +36,4 @@ rules: ...@@ -36,5 +36,4 @@ rules:
- ignore: - ignore:
- 'fixtures/blob' - 'fixtures/blob'
# Temporarily disabled to facilitate an upgrade to eslint-plugin-jasmine # Temporarily disabled to facilitate an upgrade to eslint-plugin-jasmine
jasmine/new-line-before-expect: off
jasmine/prefer-toHaveBeenCalledWith: off jasmine/prefer-toHaveBeenCalledWith: off
...@@ -42,6 +42,7 @@ describe('Ajax Loading Spinner', () => { ...@@ -42,6 +42,7 @@ describe('Ajax Loading Spinner', () => {
req.complete({}); req.complete({});
const icon = ajaxLoadingSpinner.querySelector('i'); const icon = ajaxLoadingSpinner.querySelector('i');
expect(icon).toHaveClass('fa-trash-o'); expect(icon).toHaveClass('fa-trash-o');
expect(icon).not.toHaveClass('fa-spinner'); expect(icon).not.toHaveClass('fa-spinner');
expect(icon).not.toHaveClass('fa-spin'); expect(icon).not.toHaveClass('fa-spin');
......
...@@ -74,6 +74,7 @@ import '~/lib/utils/common_utils'; ...@@ -74,6 +74,7 @@ import '~/lib/utils/common_utils';
return lazyAssert(done, function() { return lazyAssert(done, function() {
var $emojiMenu; var $emojiMenu;
$emojiMenu = $('.emoji-menu'); $emojiMenu = $('.emoji-menu');
expect($emojiMenu.length).toBe(1); expect($emojiMenu.length).toBe(1);
expect($emojiMenu.hasClass('is-visible')).toBe(true); expect($emojiMenu.hasClass('is-visible')).toBe(true);
expect($emojiMenu.find('.js-emoji-menu-search').length).toBe(1); expect($emojiMenu.find('.js-emoji-menu-search').length).toBe(1);
...@@ -85,7 +86,8 @@ import '~/lib/utils/common_utils'; ...@@ -85,7 +86,8 @@ import '~/lib/utils/common_utils';
$('.js-add-award.note-action-button').click(); $('.js-add-award.note-action-button').click();
return lazyAssert(done, function() { return lazyAssert(done, function() {
var $emojiMenu = $('.emoji-menu'); var $emojiMenu = $('.emoji-menu');
return expect($emojiMenu.length).toBe(1);
expect($emojiMenu.length).toBe(1);
}); });
}); });
...@@ -97,6 +99,7 @@ import '~/lib/utils/common_utils'; ...@@ -97,6 +99,7 @@ import '~/lib/utils/common_utils';
var $emojiMenu; var $emojiMenu;
$emojiMenu = $('.emoji-menu'); $emojiMenu = $('.emoji-menu');
$('body').click(); $('body').click();
expect($emojiMenu.length).toBe(1); expect($emojiMenu.length).toBe(1);
expect($emojiMenu.hasClass('is-visible')).toBe(false); expect($emojiMenu.hasClass('is-visible')).toBe(false);
return expect($('.js-awards-block.current').length).toBe(0); return expect($('.js-awards-block.current').length).toBe(0);
...@@ -111,6 +114,7 @@ import '~/lib/utils/common_utils'; ...@@ -111,6 +114,7 @@ import '~/lib/utils/common_utils';
var $emojiMenu; var $emojiMenu;
$emojiMenu = $('.emoji-menu'); $emojiMenu = $('.emoji-menu');
$('.emoji-search').click(); $('.emoji-search').click();
expect($emojiMenu.length).toBe(1); expect($emojiMenu.length).toBe(1);
expect($emojiMenu.hasClass('is-visible')).toBe(true); expect($emojiMenu.hasClass('is-visible')).toBe(true);
return expect($('.js-awards-block.current').length).toBe(1); return expect($('.js-awards-block.current').length).toBe(1);
...@@ -124,6 +128,7 @@ import '~/lib/utils/common_utils'; ...@@ -124,6 +128,7 @@ import '~/lib/utils/common_utils';
$votesBlock = $('.js-awards-block').eq(0); $votesBlock = $('.js-awards-block').eq(0);
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false); awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
$emojiButton = $votesBlock.find('[data-name=heart]'); $emojiButton = $votesBlock.find('[data-name=heart]');
expect($emojiButton.length).toBe(1); expect($emojiButton.length).toBe(1);
expect($emojiButton.next('.js-counter').text()).toBe('1'); expect($emojiButton.next('.js-counter').text()).toBe('1');
return expect($votesBlock.hasClass('hidden')).toBe(false); return expect($votesBlock.hasClass('hidden')).toBe(false);
...@@ -135,7 +140,8 @@ import '~/lib/utils/common_utils'; ...@@ -135,7 +140,8 @@ import '~/lib/utils/common_utils';
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false); awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false); awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
$emojiButton = $votesBlock.find('[data-name=heart]'); $emojiButton = $votesBlock.find('[data-name=heart]');
return expect($emojiButton.length).toBe(0);
expect($emojiButton.length).toBe(0);
}); });
return it('should decrement the emoji counter', function() { return it('should decrement the emoji counter', function() {
var $emojiButton, $votesBlock; var $emojiButton, $votesBlock;
...@@ -144,6 +150,7 @@ import '~/lib/utils/common_utils'; ...@@ -144,6 +150,7 @@ import '~/lib/utils/common_utils';
$emojiButton = $votesBlock.find('[data-name=heart]'); $emojiButton = $votesBlock.find('[data-name=heart]');
$emojiButton.next('.js-counter').text(5); $emojiButton.next('.js-counter').text(5);
awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false); awardsHandler.addAwardToEmojiBar($votesBlock, 'heart', false);
expect($emojiButton.length).toBe(1); expect($emojiButton.length).toBe(1);
return expect($emojiButton.next('.js-counter').text()).toBe('4'); return expect($emojiButton.next('.js-counter').text()).toBe('4');
}); });
...@@ -156,7 +163,8 @@ import '~/lib/utils/common_utils'; ...@@ -156,7 +163,8 @@ import '~/lib/utils/common_utils';
$thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent(); $thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
$thumbsUpEmoji.attr('data-title', 'sam'); $thumbsUpEmoji.attr('data-title', 'sam');
awardsHandler.userAuthored($thumbsUpEmoji); awardsHandler.userAuthored($thumbsUpEmoji);
return expect($thumbsUpEmoji.data('originalTitle')).toBe(
expect($thumbsUpEmoji.data('originalTitle')).toBe(
'You cannot vote on your own issue, MR and note', 'You cannot vote on your own issue, MR and note',
); );
}); });
...@@ -170,13 +178,15 @@ import '~/lib/utils/common_utils'; ...@@ -170,13 +178,15 @@ import '~/lib/utils/common_utils';
awardsHandler.userAuthored($thumbsUpEmoji); awardsHandler.userAuthored($thumbsUpEmoji);
jasmine.clock().tick(2801); jasmine.clock().tick(2801);
jasmine.clock().uninstall(); jasmine.clock().uninstall();
return expect($thumbsUpEmoji.data('originalTitle')).toBe('sam');
expect($thumbsUpEmoji.data('originalTitle')).toBe('sam');
}); });
}); });
describe('::getAwardUrl', function() { describe('::getAwardUrl', function() {
return it('returns the url for request', function() { return it('returns the url for request', function() {
return expect(awardsHandler.getAwardUrl()).toBe(
expect(awardsHandler.getAwardUrl()).toBe(
'http://test.host/snippets/1/toggle_award_emoji', 'http://test.host/snippets/1/toggle_award_emoji',
); );
}); });
...@@ -190,11 +200,13 @@ import '~/lib/utils/common_utils'; ...@@ -190,11 +200,13 @@ import '~/lib/utils/common_utils';
$thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent(); $thumbsUpEmoji = $votesBlock.find('[data-name=thumbsup]').parent();
$thumbsDownEmoji = $votesBlock.find('[data-name=thumbsdown]').parent(); $thumbsDownEmoji = $votesBlock.find('[data-name=thumbsdown]').parent();
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false); awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
expect($thumbsUpEmoji.hasClass('active')).toBe(true); expect($thumbsUpEmoji.hasClass('active')).toBe(true);
expect($thumbsDownEmoji.hasClass('active')).toBe(false); expect($thumbsDownEmoji.hasClass('active')).toBe(false);
$thumbsUpEmoji.tooltip(); $thumbsUpEmoji.tooltip();
$thumbsDownEmoji.tooltip(); $thumbsDownEmoji.tooltip();
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsdown', true); awardsHandler.addAward($votesBlock, awardUrl, 'thumbsdown', true);
expect($thumbsUpEmoji.hasClass('active')).toBe(false); expect($thumbsUpEmoji.hasClass('active')).toBe(false);
return expect($thumbsDownEmoji.hasClass('active')).toBe(true); return expect($thumbsDownEmoji.hasClass('active')).toBe(true);
}); });
...@@ -206,9 +218,11 @@ import '~/lib/utils/common_utils'; ...@@ -206,9 +218,11 @@ import '~/lib/utils/common_utils';
awardUrl = awardsHandler.getAwardUrl(); awardUrl = awardsHandler.getAwardUrl();
$votesBlock = $('.js-awards-block').eq(0); $votesBlock = $('.js-awards-block').eq(0);
awardsHandler.addAward($votesBlock, awardUrl, 'fire', false); awardsHandler.addAward($votesBlock, awardUrl, 'fire', false);
expect($votesBlock.find('[data-name=fire]').length).toBe(1); expect($votesBlock.find('[data-name=fire]').length).toBe(1);
awardsHandler.removeEmoji($votesBlock.find('[data-name=fire]').closest('button')); awardsHandler.removeEmoji($votesBlock.find('[data-name=fire]').closest('button'));
return expect($votesBlock.find('[data-name=fire]').length).toBe(0);
expect($votesBlock.find('[data-name=fire]').length).toBe(0);
}); });
}); });
...@@ -221,7 +235,8 @@ import '~/lib/utils/common_utils'; ...@@ -221,7 +235,8 @@ import '~/lib/utils/common_utils';
$thumbsUpEmoji.attr('data-title', 'sam, jerry, max, and andy'); $thumbsUpEmoji.attr('data-title', 'sam, jerry, max, and andy');
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false); awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
$thumbsUpEmoji.tooltip(); $thumbsUpEmoji.tooltip();
return expect($thumbsUpEmoji.data('originalTitle')).toBe('You, sam, jerry, max, and andy');
expect($thumbsUpEmoji.data('originalTitle')).toBe('You, sam, jerry, max, and andy');
}); });
return it('handles the special case where "You" is not cleanly comma seperated', function() { return it('handles the special case where "You" is not cleanly comma seperated', function() {
var $thumbsUpEmoji, $votesBlock, awardUrl; var $thumbsUpEmoji, $votesBlock, awardUrl;
...@@ -231,7 +246,8 @@ import '~/lib/utils/common_utils'; ...@@ -231,7 +246,8 @@ import '~/lib/utils/common_utils';
$thumbsUpEmoji.attr('data-title', 'sam'); $thumbsUpEmoji.attr('data-title', 'sam');
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false); awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
$thumbsUpEmoji.tooltip(); $thumbsUpEmoji.tooltip();
return expect($thumbsUpEmoji.data('originalTitle')).toBe('You and sam');
expect($thumbsUpEmoji.data('originalTitle')).toBe('You and sam');
}); });
}); });
...@@ -245,7 +261,8 @@ import '~/lib/utils/common_utils'; ...@@ -245,7 +261,8 @@ import '~/lib/utils/common_utils';
$thumbsUpEmoji.addClass('active'); $thumbsUpEmoji.addClass('active');
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false); awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
$thumbsUpEmoji.tooltip(); $thumbsUpEmoji.tooltip();
return expect($thumbsUpEmoji.data('originalTitle')).toBe('sam, jerry, max, and andy');
expect($thumbsUpEmoji.data('originalTitle')).toBe('sam, jerry, max, and andy');
}); });
return it('handles the special case where "You" is not cleanly comma seperated', function() { return it('handles the special case where "You" is not cleanly comma seperated', function() {
var $thumbsUpEmoji, $votesBlock, awardUrl; var $thumbsUpEmoji, $votesBlock, awardUrl;
...@@ -256,7 +273,8 @@ import '~/lib/utils/common_utils'; ...@@ -256,7 +273,8 @@ import '~/lib/utils/common_utils';
$thumbsUpEmoji.addClass('active'); $thumbsUpEmoji.addClass('active');
awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false); awardsHandler.addAward($votesBlock, awardUrl, 'thumbsup', false);
$thumbsUpEmoji.tooltip(); $thumbsUpEmoji.tooltip();
return expect($thumbsUpEmoji.data('originalTitle')).toBe('sam');
expect($thumbsUpEmoji.data('originalTitle')).toBe('sam');
}); });
}); });
...@@ -267,6 +285,7 @@ import '~/lib/utils/common_utils'; ...@@ -267,6 +285,7 @@ import '~/lib/utils/common_utils';
expect($('[data-name=angel]').is(':visible')).toBe(true); expect($('[data-name=angel]').is(':visible')).toBe(true);
expect($('[data-name=anger]').is(':visible')).toBe(true); expect($('[data-name=anger]').is(':visible')).toBe(true);
awardsHandler.searchEmojis('ali'); awardsHandler.searchEmojis('ali');
expect($('[data-name=angel]').is(':visible')).toBe(false); expect($('[data-name=angel]').is(':visible')).toBe(false);
expect($('[data-name=anger]').is(':visible')).toBe(false); expect($('[data-name=anger]').is(':visible')).toBe(false);
expect($('[data-name=alien]').is(':visible')).toBe(true); expect($('[data-name=alien]').is(':visible')).toBe(true);
...@@ -282,10 +301,12 @@ import '~/lib/utils/common_utils'; ...@@ -282,10 +301,12 @@ import '~/lib/utils/common_utils';
return openAndWaitForEmojiMenu() return openAndWaitForEmojiMenu()
.then(() => { .then(() => {
awardsHandler.searchEmojis('ali'); awardsHandler.searchEmojis('ali');
expect($('[data-name=angel]').is(':visible')).toBe(false); expect($('[data-name=angel]').is(':visible')).toBe(false);
expect($('[data-name=anger]').is(':visible')).toBe(false); expect($('[data-name=anger]').is(':visible')).toBe(false);
expect($('[data-name=alien]').is(':visible')).toBe(true); expect($('[data-name=alien]').is(':visible')).toBe(true);
awardsHandler.searchEmojis(''); awardsHandler.searchEmojis('');
expect($('[data-name=angel]').is(':visible')).toBe(true); expect($('[data-name=angel]').is(':visible')).toBe(true);
expect($('[data-name=anger]').is(':visible')).toBe(true); expect($('[data-name=anger]').is(':visible')).toBe(true);
expect($('[data-name=alien]').is(':visible')).toBe(true); expect($('[data-name=alien]').is(':visible')).toBe(true);
...@@ -309,6 +330,7 @@ import '~/lib/utils/common_utils'; ...@@ -309,6 +330,7 @@ import '~/lib/utils/common_utils';
expect($emoji.length).toBe(1); expect($emoji.length).toBe(1);
expect($block.find(emojiSelector).length).toBe(0); expect($block.find(emojiSelector).length).toBe(0);
$emoji.click(); $emoji.click();
expect($menu.hasClass('.is-visible')).toBe(false); expect($menu.hasClass('.is-visible')).toBe(false);
expect($block.find(emojiSelector).length).toBe(1); expect($block.find(emojiSelector).length).toBe(1);
}); });
...@@ -332,6 +354,7 @@ import '~/lib/utils/common_utils'; ...@@ -332,6 +354,7 @@ import '~/lib/utils/common_utils';
`.emoji-menu-list:not(.frequent-emojis) ${emojiSelector}`, `.emoji-menu-list:not(.frequent-emojis) ${emojiSelector}`,
); );
$emoji.click(); $emoji.click();
expect($block.find(emojiSelector).length).toBe(0); expect($block.find(emojiSelector).length).toBe(0);
}) })
.then(done) .then(done)
......
...@@ -66,8 +66,10 @@ describe('BadgeForm component', () => { ...@@ -66,8 +66,10 @@ describe('BadgeForm component', () => {
}; };
const expectInvalidInput = inputElementSelector => { const expectInvalidInput = inputElementSelector => {
const inputElement = vm.$el.querySelector(inputElementSelector); const inputElement = vm.$el.querySelector(inputElementSelector);
expect(inputElement).toBeMatchedBy(':invalid'); expect(inputElement).toBeMatchedBy(':invalid');
const feedbackElement = vm.$el.querySelector(`${inputElementSelector} + .invalid-feedback`); const feedbackElement = vm.$el.querySelector(`${inputElementSelector} + .invalid-feedback`);
expect(feedbackElement).toBeVisible(); expect(feedbackElement).toBeVisible();
}; };
...@@ -90,6 +92,7 @@ describe('BadgeForm component', () => { ...@@ -90,6 +92,7 @@ describe('BadgeForm component', () => {
submitForm(); submitForm();
expectInvalidInput(imageUrlSelector); expectInvalidInput(imageUrlSelector);
expect(vm[submitAction]).not.toHaveBeenCalled(); expect(vm[submitAction]).not.toHaveBeenCalled();
}); });
...@@ -99,6 +102,7 @@ describe('BadgeForm component', () => { ...@@ -99,6 +102,7 @@ describe('BadgeForm component', () => {
submitForm(); submitForm();
expectInvalidInput(imageUrlSelector); expectInvalidInput(imageUrlSelector);
expect(vm[submitAction]).not.toHaveBeenCalled(); expect(vm[submitAction]).not.toHaveBeenCalled();
}); });
...@@ -108,6 +112,7 @@ describe('BadgeForm component', () => { ...@@ -108,6 +112,7 @@ describe('BadgeForm component', () => {
submitForm(); submitForm();
expectInvalidInput(linkUrlSelector); expectInvalidInput(linkUrlSelector);
expect(vm[submitAction]).not.toHaveBeenCalled(); expect(vm[submitAction]).not.toHaveBeenCalled();
}); });
...@@ -117,6 +122,7 @@ describe('BadgeForm component', () => { ...@@ -117,6 +122,7 @@ describe('BadgeForm component', () => {
submitForm(); submitForm();
expectInvalidInput(linkUrlSelector); expectInvalidInput(linkUrlSelector);
expect(vm[submitAction]).not.toHaveBeenCalled(); expect(vm[submitAction]).not.toHaveBeenCalled();
}); });
...@@ -143,8 +149,10 @@ describe('BadgeForm component', () => { ...@@ -143,8 +149,10 @@ describe('BadgeForm component', () => {
it('renders one button', () => { it('renders one button', () => {
expect(vm.$el.querySelector('.row-content-block')).toBeNull(); expect(vm.$el.querySelector('.row-content-block')).toBeNull();
const buttons = vm.$el.querySelectorAll('.form-group:last-of-type button'); const buttons = vm.$el.querySelectorAll('.form-group:last-of-type button');
expect(buttons.length).toBe(1); expect(buttons.length).toBe(1);
const buttonAddElement = buttons[0]; const buttonAddElement = buttons[0];
expect(buttonAddElement).toBeVisible(); expect(buttonAddElement).toBeVisible();
expect(buttonAddElement).toHaveText('Add badge'); expect(buttonAddElement).toHaveText('Add badge');
}); });
...@@ -165,11 +173,14 @@ describe('BadgeForm component', () => { ...@@ -165,11 +173,14 @@ describe('BadgeForm component', () => {
it('renders two buttons', () => { it('renders two buttons', () => {
const buttons = vm.$el.querySelectorAll('.row-content-block button'); const buttons = vm.$el.querySelectorAll('.row-content-block button');
expect(buttons.length).toBe(2); expect(buttons.length).toBe(2);
const buttonSaveElement = buttons[0]; const buttonSaveElement = buttons[0];
expect(buttonSaveElement).toBeVisible(); expect(buttonSaveElement).toBeVisible();
expect(buttonSaveElement).toHaveText('Save changes'); expect(buttonSaveElement).toHaveText('Save changes');
const buttonCancelElement = buttons[1]; const buttonCancelElement = buttons[1];
expect(buttonCancelElement).toBeVisible(); expect(buttonCancelElement).toBeVisible();
expect(buttonCancelElement).toHaveText('Cancel'); expect(buttonCancelElement).toHaveText('Cancel');
}); });
......
...@@ -34,6 +34,7 @@ describe('BadgeListRow component', () => { ...@@ -34,6 +34,7 @@ describe('BadgeListRow component', () => {
it('renders the badge', () => { it('renders the badge', () => {
const badgeElement = vm.$el.querySelector('.project-badge'); const badgeElement = vm.$el.querySelector('.project-badge');
expect(badgeElement).not.toBeNull(); expect(badgeElement).not.toBeNull();
expect(badgeElement.getAttribute('src')).toBe(badge.renderedImageUrl); expect(badgeElement.getAttribute('src')).toBe(badge.renderedImageUrl);
}); });
...@@ -48,11 +49,14 @@ describe('BadgeListRow component', () => { ...@@ -48,11 +49,14 @@ describe('BadgeListRow component', () => {
it('shows edit and delete buttons', () => { it('shows edit and delete buttons', () => {
const buttons = vm.$el.querySelectorAll('.table-button-footer button'); const buttons = vm.$el.querySelectorAll('.table-button-footer button');
expect(buttons).toHaveLength(2); expect(buttons).toHaveLength(2);
const buttonEditElement = buttons[0]; const buttonEditElement = buttons[0];
expect(buttonEditElement).toBeVisible(); expect(buttonEditElement).toBeVisible();
expect(buttonEditElement).toHaveSpriteIcon('pencil'); expect(buttonEditElement).toHaveSpriteIcon('pencil');
const buttonDeleteElement = buttons[1]; const buttonDeleteElement = buttons[1];
expect(buttonDeleteElement).toBeVisible(); expect(buttonDeleteElement).toBeVisible();
expect(buttonDeleteElement).toHaveSpriteIcon('remove'); expect(buttonDeleteElement).toHaveSpriteIcon('remove');
}); });
...@@ -91,6 +95,7 @@ describe('BadgeListRow component', () => { ...@@ -91,6 +95,7 @@ describe('BadgeListRow component', () => {
it('hides edit and delete buttons', () => { it('hides edit and delete buttons', () => {
const buttons = vm.$el.querySelectorAll('.table-button-footer button'); const buttons = vm.$el.querySelectorAll('.table-button-footer button');
expect(buttons).toHaveLength(0); expect(buttons).toHaveLength(0);
}); });
}); });
......
...@@ -34,11 +34,13 @@ describe('BadgeList component', () => { ...@@ -34,11 +34,13 @@ describe('BadgeList component', () => {
it('renders a header with the badge count', () => { it('renders a header with the badge count', () => {
const header = vm.$el.querySelector('.card-header'); const header = vm.$el.querySelector('.card-header');
expect(header).toHaveText(new RegExp(`Your badges\\s+${numberOfDummyBadges}`)); expect(header).toHaveText(new RegExp(`Your badges\\s+${numberOfDummyBadges}`));
}); });
it('renders a row for each badge', () => { it('renders a row for each badge', () => {
const rows = vm.$el.querySelectorAll('.gl-responsive-table-row'); const rows = vm.$el.querySelectorAll('.gl-responsive-table-row');
expect(rows).toHaveLength(numberOfDummyBadges); expect(rows).toHaveLength(numberOfDummyBadges);
}); });
...@@ -59,6 +61,7 @@ describe('BadgeList component', () => { ...@@ -59,6 +61,7 @@ describe('BadgeList component', () => {
Vue.nextTick() Vue.nextTick()
.then(() => { .then(() => {
const loadingIcon = vm.$el.querySelector('.fa-spinner'); const loadingIcon = vm.$el.querySelector('.fa-spinner');
expect(loadingIcon).toBeVisible(); expect(loadingIcon).toBeVisible();
}) })
.then(done) .then(done)
......
...@@ -38,6 +38,7 @@ describe('BadgeSettings component', () => { ...@@ -38,6 +38,7 @@ describe('BadgeSettings component', () => {
$(modal).on('shown.bs.modal', () => { $(modal).on('shown.bs.modal', () => {
expect(modal).toContainText('Delete badge?'); expect(modal).toContainText('Delete badge?');
const badgeElement = modal.querySelector('img.project-badge'); const badgeElement = modal.querySelector('img.project-badge');
expect(badgeElement).not.toBe(null); expect(badgeElement).not.toBe(null);
expect(badgeElement.getAttribute('src')).toBe(badge.renderedImageUrl); expect(badgeElement.getAttribute('src')).toBe(badge.renderedImageUrl);
...@@ -53,14 +54,17 @@ describe('BadgeSettings component', () => { ...@@ -53,14 +54,17 @@ describe('BadgeSettings component', () => {
it('displays a form to add a badge', () => { it('displays a form to add a badge', () => {
const form = vm.$el.querySelector('form:nth-of-type(2)'); const form = vm.$el.querySelector('form:nth-of-type(2)');
expect(form).not.toBe(null); expect(form).not.toBe(null);
const button = form.querySelector('.btn-success'); const button = form.querySelector('.btn-success');
expect(button).not.toBe(null); expect(button).not.toBe(null);
expect(button).toHaveText(/Add badge/); expect(button).toHaveText(/Add badge/);
}); });
it('displays badge list', () => { it('displays badge list', () => {
const badgeListElement = vm.$el.querySelector('.card'); const badgeListElement = vm.$el.querySelector('.card');
expect(badgeListElement).not.toBe(null); expect(badgeListElement).not.toBe(null);
expect(badgeListElement).toBeVisible(); expect(badgeListElement).toBeVisible();
expect(badgeListElement).toContainText('Your badges'); expect(badgeListElement).toContainText('Your badges');
...@@ -77,17 +81,21 @@ describe('BadgeSettings component', () => { ...@@ -77,17 +81,21 @@ describe('BadgeSettings component', () => {
it('displays a form to edit a badge', () => { it('displays a form to edit a badge', () => {
const form = vm.$el.querySelector('form:nth-of-type(1)'); const form = vm.$el.querySelector('form:nth-of-type(1)');
expect(form).not.toBe(null); expect(form).not.toBe(null);
const submitButton = form.querySelector('.btn-success'); const submitButton = form.querySelector('.btn-success');
expect(submitButton).not.toBe(null); expect(submitButton).not.toBe(null);
expect(submitButton).toHaveText(/Save changes/); expect(submitButton).toHaveText(/Save changes/);
const cancelButton = form.querySelector('.btn-cancel'); const cancelButton = form.querySelector('.btn-cancel');
expect(cancelButton).not.toBe(null); expect(cancelButton).not.toBe(null);
expect(cancelButton).toHaveText(/Cancel/); expect(cancelButton).toHaveText(/Cancel/);
}); });
it('displays no badge list', () => { it('displays no badge list', () => {
const badgeListElement = vm.$el.querySelector('.card'); const badgeListElement = vm.$el.querySelector('.card');
expect(badgeListElement).toBeHidden(); expect(badgeListElement).toBeHidden();
}); });
}); });
...@@ -102,6 +110,7 @@ describe('BadgeSettings component', () => { ...@@ -102,6 +110,7 @@ describe('BadgeSettings component', () => {
deleteButton.click(); deleteButton.click();
const badge = store.state.badgeInModal; const badge = store.state.badgeInModal;
expect(vm.deleteBadge).toHaveBeenCalledWith(badge); expect(vm.deleteBadge).toHaveBeenCalledWith(badge);
}); });
}); });
......
...@@ -107,6 +107,7 @@ describe('Badge component', () => { ...@@ -107,6 +107,7 @@ describe('Badge component', () => {
expect(vm.isLoading).toBe(false); expect(vm.isLoading).toBe(false);
expect(vm.hasError).toBe(false); expect(vm.hasError).toBe(false);
const { badgeImage, loadingIcon, reloadButton } = findElements(); const { badgeImage, loadingIcon, reloadButton } = findElements();
expect(badgeImage).toBeVisible(); expect(badgeImage).toBeVisible();
expect(loadingIcon).toBeHidden(); expect(loadingIcon).toBeHidden();
expect(reloadButton).toBeHidden(); expect(reloadButton).toBeHidden();
...@@ -119,6 +120,7 @@ describe('Badge component', () => { ...@@ -119,6 +120,7 @@ describe('Badge component', () => {
Vue.nextTick() Vue.nextTick()
.then(() => { .then(() => {
const { badgeImage, loadingIcon, reloadButton } = findElements(); const { badgeImage, loadingIcon, reloadButton } = findElements();
expect(badgeImage).toBeHidden(); expect(badgeImage).toBeHidden();
expect(loadingIcon).toBeVisible(); expect(loadingIcon).toBeVisible();
expect(reloadButton).toBeHidden(); expect(reloadButton).toBeHidden();
...@@ -134,6 +136,7 @@ describe('Badge component', () => { ...@@ -134,6 +136,7 @@ describe('Badge component', () => {
Vue.nextTick() Vue.nextTick()
.then(() => { .then(() => {
const { badgeImage, loadingIcon, reloadButton } = findElements(); const { badgeImage, loadingIcon, reloadButton } = findElements();
expect(badgeImage).toBeHidden(); expect(badgeImage).toBeHidden();
expect(loadingIcon).toBeHidden(); expect(loadingIcon).toBeHidden();
expect(reloadButton).toBeVisible(); expect(reloadButton).toBeVisible();
......
...@@ -94,6 +94,7 @@ describe('Badges store actions', () => { ...@@ -94,6 +94,7 @@ describe('Badges store actions', () => {
link_url: badgeInAddForm.linkUrl, link_url: badgeInAddForm.linkUrl,
}), }),
); );
expect(dispatch.calls.allArgs()).toEqual([['requestNewBadge']]); expect(dispatch.calls.allArgs()).toEqual([['requestNewBadge']]);
dispatch.calls.reset(); dispatch.calls.reset();
return [200, dummyResponse]; return [200, dummyResponse];
...@@ -117,6 +118,7 @@ describe('Badges store actions', () => { ...@@ -117,6 +118,7 @@ describe('Badges store actions', () => {
link_url: badgeInAddForm.linkUrl, link_url: badgeInAddForm.linkUrl,
}), }),
); );
expect(dispatch.calls.allArgs()).toEqual([['requestNewBadge']]); expect(dispatch.calls.allArgs()).toEqual([['requestNewBadge']]);
dispatch.calls.reset(); dispatch.calls.reset();
return [500, '']; return [500, ''];
...@@ -296,6 +298,7 @@ describe('Badges store actions', () => { ...@@ -296,6 +298,7 @@ describe('Badges store actions', () => {
.loadBadges({ state, dispatch }, dummyData) .loadBadges({ state, dispatch }, dummyData)
.then(() => { .then(() => {
const badges = dummyReponse.map(transformBackendBadge); const badges = dummyReponse.map(transformBackendBadge);
expect(dispatch.calls.allArgs()).toEqual([['receiveLoadBadges', badges]]); expect(dispatch.calls.allArgs()).toEqual([['receiveLoadBadges', badges]]);
}) })
.then(done) .then(done)
...@@ -416,6 +419,7 @@ describe('Badges store actions', () => { ...@@ -416,6 +419,7 @@ describe('Badges store actions', () => {
.then(() => { .then(() => {
expect(axios.get.calls.count()).toBe(1); expect(axios.get.calls.count()).toBe(1);
const url = axios.get.calls.argsFor(0)[0]; const url = axios.get.calls.argsFor(0)[0];
expect(url).toMatch(`^${dummyEndpointUrl}/render?`); expect(url).toMatch(`^${dummyEndpointUrl}/render?`);
expect(url).toMatch('\\?link_url=%3Cscript%3EI%20am%20dangerous!%3C%2Fscript%3E&'); expect(url).toMatch('\\?link_url=%3Cscript%3EI%20am%20dangerous!%3C%2Fscript%3E&');
expect(url).toMatch('&image_url=%26make-sandwhich%3Dtrue$'); expect(url).toMatch('&image_url=%26make-sandwhich%3Dtrue$');
...@@ -436,6 +440,7 @@ describe('Badges store actions', () => { ...@@ -436,6 +440,7 @@ describe('Badges store actions', () => {
.renderBadge({ state, dispatch }) .renderBadge({ state, dispatch })
.then(() => { .then(() => {
const renderedBadge = transformBackendBadge(dummyReponse); const renderedBadge = transformBackendBadge(dummyReponse);
expect(dispatch.calls.allArgs()).toEqual([['receiveRenderedBadge', renderedBadge]]); expect(dispatch.calls.allArgs()).toEqual([['receiveRenderedBadge', renderedBadge]]);
}) })
.then(done) .then(done)
...@@ -525,6 +530,7 @@ describe('Badges store actions', () => { ...@@ -525,6 +530,7 @@ describe('Badges store actions', () => {
link_url: badgeInEditForm.linkUrl, link_url: badgeInEditForm.linkUrl,
}), }),
); );
expect(dispatch.calls.allArgs()).toEqual([['requestUpdatedBadge']]); expect(dispatch.calls.allArgs()).toEqual([['requestUpdatedBadge']]);
dispatch.calls.reset(); dispatch.calls.reset();
return [200, dummyResponse]; return [200, dummyResponse];
...@@ -548,6 +554,7 @@ describe('Badges store actions', () => { ...@@ -548,6 +554,7 @@ describe('Badges store actions', () => {
link_url: badgeInEditForm.linkUrl, link_url: badgeInEditForm.linkUrl,
}), }),
); );
expect(dispatch.calls.allArgs()).toEqual([['requestUpdatedBadge']]); expect(dispatch.calls.allArgs()).toEqual([['requestUpdatedBadge']]);
dispatch.calls.reset(); dispatch.calls.reset();
return [500, '']; return [500, ''];
......
...@@ -12,6 +12,7 @@ describe('Autosize behavior', () => { ...@@ -12,6 +12,7 @@ describe('Autosize behavior', () => {
it('does not overwrite the resize property', () => { it('does not overwrite the resize property', () => {
load(); load();
expect($('textarea')).toHaveCss({ expect($('textarea')).toHaveCss({
resize: 'vertical', resize: 'vertical',
}); });
......
...@@ -29,6 +29,7 @@ describe('CopyAsGFM', () => { ...@@ -29,6 +29,7 @@ describe('CopyAsGFM', () => {
it('wraps pasted code when not already in code tags', () => { it('wraps pasted code when not already in code tags', () => {
spyOn(window.gl.utils, 'insertText').and.callFake((el, textFunc) => { spyOn(window.gl.utils, 'insertText').and.callFake((el, textFunc) => {
const insertedText = textFunc('This is code: ', ''); const insertedText = textFunc('This is code: ', '');
expect(insertedText).toEqual('`code`'); expect(insertedText).toEqual('`code`');
}); });
...@@ -38,6 +39,7 @@ describe('CopyAsGFM', () => { ...@@ -38,6 +39,7 @@ describe('CopyAsGFM', () => {
it('does not wrap pasted code when already in code tags', () => { it('does not wrap pasted code when already in code tags', () => {
spyOn(window.gl.utils, 'insertText').and.callFake((el, textFunc) => { spyOn(window.gl.utils, 'insertText').and.callFake((el, textFunc) => {
const insertedText = textFunc('This is code: `', '`'); const insertedText = textFunc('This is code: `', '`');
expect(insertedText).toEqual('code'); expect(insertedText).toEqual('code');
}); });
...@@ -86,6 +88,7 @@ describe('CopyAsGFM', () => { ...@@ -86,6 +88,7 @@ describe('CopyAsGFM', () => {
simulateCopy(); simulateCopy();
const expectedGFM = '- List Item1\n- List Item2'; const expectedGFM = '- List Item1\n- List Item2';
expect(clipboardData.setData).toHaveBeenCalledWith('text/x-gfm', expectedGFM); expect(clipboardData.setData).toHaveBeenCalledWith('text/x-gfm', expectedGFM);
}); });
...@@ -95,6 +98,7 @@ describe('CopyAsGFM', () => { ...@@ -95,6 +98,7 @@ describe('CopyAsGFM', () => {
simulateCopy(); simulateCopy();
const expectedGFM = '1. List Item1\n1. List Item2'; const expectedGFM = '1. List Item1\n1. List Item2';
expect(clipboardData.setData).toHaveBeenCalledWith('text/x-gfm', expectedGFM); expect(clipboardData.setData).toHaveBeenCalledWith('text/x-gfm', expectedGFM);
}); });
}); });
......
...@@ -30,6 +30,7 @@ describe('Quick Submit behavior', function () { ...@@ -30,6 +30,7 @@ describe('Quick Submit behavior', function () {
keyCode: 32, keyCode: 32,
}), }),
); );
expect(this.spies.submit).not.toHaveBeenTriggered(); expect(this.spies.submit).not.toHaveBeenTriggered();
}); });
...@@ -40,6 +41,7 @@ describe('Quick Submit behavior', function () { ...@@ -40,6 +41,7 @@ describe('Quick Submit behavior', function () {
metaKey: false, metaKey: false,
}), }),
); );
expect(this.spies.submit).not.toHaveBeenTriggered(); expect(this.spies.submit).not.toHaveBeenTriggered();
}); });
...@@ -49,6 +51,7 @@ describe('Quick Submit behavior', function () { ...@@ -49,6 +51,7 @@ describe('Quick Submit behavior', function () {
repeat: true, repeat: true,
}), }),
); );
expect(this.spies.submit).not.toHaveBeenTriggered(); expect(this.spies.submit).not.toHaveBeenTriggered();
}); });
...@@ -86,7 +89,8 @@ describe('Quick Submit behavior', function () { ...@@ -86,7 +89,8 @@ describe('Quick Submit behavior', function () {
describe('In Macintosh', () => { describe('In Macintosh', () => {
it('responds to Meta+Enter', () => { it('responds to Meta+Enter', () => {
this.textarea.trigger(keydownEvent()); this.textarea.trigger(keydownEvent());
return expect(this.spies.submit).toHaveBeenTriggered();
expect(this.spies.submit).toHaveBeenTriggered();
}); });
it('excludes other modifier keys', () => { it('excludes other modifier keys', () => {
...@@ -105,13 +109,15 @@ describe('Quick Submit behavior', function () { ...@@ -105,13 +109,15 @@ describe('Quick Submit behavior', function () {
shiftKey: true, shiftKey: true,
}), }),
); );
return expect(this.spies.submit).not.toHaveBeenTriggered();
expect(this.spies.submit).not.toHaveBeenTriggered();
}); });
}); });
} else { } else {
it('responds to Ctrl+Enter', () => { it('responds to Ctrl+Enter', () => {
this.textarea.trigger(keydownEvent()); this.textarea.trigger(keydownEvent());
return expect(this.spies.submit).toHaveBeenTriggered();
expect(this.spies.submit).toHaveBeenTriggered();
}); });
it('excludes other modifier keys', () => { it('excludes other modifier keys', () => {
...@@ -130,7 +136,8 @@ describe('Quick Submit behavior', function () { ...@@ -130,7 +136,8 @@ describe('Quick Submit behavior', function () {
shiftKey: true, shiftKey: true,
}), }),
); );
return expect(this.spies.submit).not.toHaveBeenTriggered();
expect(this.spies.submit).not.toHaveBeenTriggered();
}); });
} }
}); });
...@@ -12,33 +12,39 @@ describe('requiresInput', () => { ...@@ -12,33 +12,39 @@ describe('requiresInput', () => {
it('disables submit when any field is required', () => { it('disables submit when any field is required', () => {
$('.js-requires-input').requiresInput(); $('.js-requires-input').requiresInput();
expect(submitButton).toBeDisabled(); expect(submitButton).toBeDisabled();
}); });
it('enables submit when no field is required', () => { it('enables submit when no field is required', () => {
$('*[required=required]').prop('required', false); $('*[required=required]').prop('required', false);
$('.js-requires-input').requiresInput(); $('.js-requires-input').requiresInput();
expect(submitButton).not.toBeDisabled(); expect(submitButton).not.toBeDisabled();
}); });
it('enables submit when all required fields are pre-filled', () => { it('enables submit when all required fields are pre-filled', () => {
$('*[required=required]').remove(); $('*[required=required]').remove();
$('.js-requires-input').requiresInput(); $('.js-requires-input').requiresInput();
expect($('.submit')).not.toBeDisabled(); expect($('.submit')).not.toBeDisabled();
}); });
it('enables submit when all required fields receive input', () => { it('enables submit when all required fields receive input', () => {
$('.js-requires-input').requiresInput(); $('.js-requires-input').requiresInput();
$('#required1').val('input1').change(); $('#required1').val('input1').change();
expect(submitButton).toBeDisabled(); expect(submitButton).toBeDisabled();
$('#optional1').val('input1').change(); $('#optional1').val('input1').change();
expect(submitButton).toBeDisabled(); expect(submitButton).toBeDisabled();
$('#required2').val('input2').change(); $('#required2').val('input2').change();
$('#required3').val('input3').change(); $('#required3').val('input3').change();
$('#required4').val('input4').change(); $('#required4').val('input4').change();
$('#required5').val('1').change(); $('#required5').val('1').change();
expect($('.submit')).not.toBeDisabled(); expect($('.submit')).not.toBeDisabled();
}); });
}); });
...@@ -130,6 +130,7 @@ describe('setupSecretValues', () => { ...@@ -130,6 +130,7 @@ describe('setupSecretValues', () => {
values.forEach((value) => { values.forEach((value) => {
expect(value.classList.contains('hide')).toEqual(true); expect(value.classList.contains('hide')).toEqual(true);
}); });
expect(placeholders.length).toEqual(3); expect(placeholders.length).toEqual(3);
placeholders.forEach((placeholder) => { placeholders.forEach((placeholder) => {
expect(placeholder.classList.contains('hide')).toEqual(false); expect(placeholder.classList.contains('hide')).toEqual(false);
...@@ -148,6 +149,7 @@ describe('setupSecretValues', () => { ...@@ -148,6 +149,7 @@ describe('setupSecretValues', () => {
values.forEach((value) => { values.forEach((value) => {
expect(value.classList.contains('hide')).toEqual(false); expect(value.classList.contains('hide')).toEqual(false);
}); });
expect(placeholders.length).toEqual(3); expect(placeholders.length).toEqual(3);
placeholders.forEach((placeholder) => { placeholders.forEach((placeholder) => {
expect(placeholder.classList.contains('hide')).toEqual(true); expect(placeholder.classList.contains('hide')).toEqual(true);
...@@ -159,6 +161,7 @@ describe('setupSecretValues', () => { ...@@ -159,6 +161,7 @@ describe('setupSecretValues', () => {
values.forEach((value) => { values.forEach((value) => {
expect(value.classList.contains('hide')).toEqual(true); expect(value.classList.contains('hide')).toEqual(true);
}); });
expect(placeholders.length).toEqual(3); expect(placeholders.length).toEqual(3);
placeholders.forEach((placeholder) => { placeholders.forEach((placeholder) => {
expect(placeholder.classList.contains('hide')).toEqual(false); expect(placeholder.classList.contains('hide')).toEqual(false);
...@@ -184,6 +187,7 @@ describe('setupSecretValues', () => { ...@@ -184,6 +187,7 @@ describe('setupSecretValues', () => {
values.forEach((value) => { values.forEach((value) => {
expect(value.classList.contains('hide')).toEqual(false); expect(value.classList.contains('hide')).toEqual(false);
}); });
expect(placeholders.length).toEqual(4); expect(placeholders.length).toEqual(4);
placeholders.forEach((placeholder) => { placeholders.forEach((placeholder) => {
expect(placeholder.classList.contains('hide')).toEqual(true); expect(placeholder.classList.contains('hide')).toEqual(true);
...@@ -195,6 +199,7 @@ describe('setupSecretValues', () => { ...@@ -195,6 +199,7 @@ describe('setupSecretValues', () => {
values.forEach((value) => { values.forEach((value) => {
expect(value.classList.contains('hide')).toEqual(true); expect(value.classList.contains('hide')).toEqual(true);
}); });
expect(placeholders.length).toEqual(4); expect(placeholders.length).toEqual(4);
placeholders.forEach((placeholder) => { placeholders.forEach((placeholder) => {
expect(placeholder.classList.contains('hide')).toEqual(false); expect(placeholder.classList.contains('hide')).toEqual(false);
......
...@@ -57,9 +57,11 @@ describe('ShortcutsIssuable', function() { ...@@ -57,9 +57,11 @@ describe('ShortcutsIssuable', function() {
it('leaves existing input intact', () => { it('leaves existing input intact', () => {
$(FORM_SELECTOR).val('This text was already here.'); $(FORM_SELECTOR).val('This text was already here.');
expect($(FORM_SELECTOR).val()).toBe('This text was already here.'); expect($(FORM_SELECTOR).val()).toBe('This text was already here.');
ShortcutsIssuable.replyWithSelectedText(true); ShortcutsIssuable.replyWithSelectedText(true);
expect($(FORM_SELECTOR).val()).toBe('This text was already here.\n\n> Selected text.\n\n'); expect($(FORM_SELECTOR).val()).toBe('This text was already here.\n\n> Selected text.\n\n');
}); });
...@@ -70,6 +72,7 @@ describe('ShortcutsIssuable', function() { ...@@ -70,6 +72,7 @@ describe('ShortcutsIssuable', function() {
}); });
ShortcutsIssuable.replyWithSelectedText(true); ShortcutsIssuable.replyWithSelectedText(true);
expect(triggered).toBe(true); expect(triggered).toBe(true);
}); });
......
...@@ -26,6 +26,7 @@ describe('BlobForkSuggestion', () => { ...@@ -26,6 +26,7 @@ describe('BlobForkSuggestion', () => {
it('showSuggestionSection', () => { it('showSuggestionSection', () => {
blobForkSuggestion.showSuggestionSection('/foo', 'foo'); blobForkSuggestion.showSuggestionSection('/foo', 'foo');
expect(suggestionSection.classList.contains('hidden')).toEqual(false); expect(suggestionSection.classList.contains('hidden')).toEqual(false);
expect(forkButton.getAttribute('href')).toEqual('/foo'); expect(forkButton.getAttribute('href')).toEqual('/foo');
expect(actionTextPiece.textContent).toEqual('foo'); expect(actionTextPiece.textContent).toEqual('foo');
...@@ -33,6 +34,7 @@ describe('BlobForkSuggestion', () => { ...@@ -33,6 +34,7 @@ describe('BlobForkSuggestion', () => {
it('hideSuggestionSection', () => { it('hideSuggestionSection', () => {
blobForkSuggestion.hideSuggestionSection(); blobForkSuggestion.hideSuggestionSection();
expect(suggestionSection.classList.contains('hidden')).toEqual(true); expect(suggestionSection.classList.contains('hidden')).toEqual(true);
}); });
}); });
...@@ -165,6 +165,7 @@ describe('Blob viewer', () => { ...@@ -165,6 +165,7 @@ describe('Blob viewer', () => {
expect( expect(
simpleBtn.classList.contains('active'), simpleBtn.classList.contains('active'),
).toBeTruthy(); ).toBeTruthy();
expect(simpleBtn.blur).toHaveBeenCalled(); expect(simpleBtn.blur).toHaveBeenCalled();
}); });
......
...@@ -86,10 +86,12 @@ describe('Store', () => { ...@@ -86,10 +86,12 @@ describe('Store', () => {
description: 'testing;' description: 'testing;'
} }
}); });
expect(boardsStore.state.lists.length).toBe(1); expect(boardsStore.state.lists.length).toBe(1);
setTimeout(() => { setTimeout(() => {
const list = boardsStore.findList('id', listObj.id); const list = boardsStore.findList('id', listObj.id);
expect(list).toBeDefined(); expect(list).toBeDefined();
expect(list.id).toBe(listObj.id); expect(list.id).toBe(listObj.id);
expect(list.position).toBe(0); expect(list.position).toBe(0);
...@@ -103,6 +105,7 @@ describe('Store', () => { ...@@ -103,6 +105,7 @@ describe('Store', () => {
it('check for blank state not adding', () => { it('check for blank state not adding', () => {
boardsStore.addList(listObj); boardsStore.addList(listObj);
expect(boardsStore.shouldAddBlankState()).toBe(false); expect(boardsStore.shouldAddBlankState()).toBe(false);
}); });
...@@ -118,6 +121,7 @@ describe('Store', () => { ...@@ -118,6 +121,7 @@ describe('Store', () => {
boardsStore.addBlankState(); boardsStore.addBlankState();
const list = boardsStore.findList('type', 'blank', 'blank'); const list = boardsStore.findList('type', 'blank', 'blank');
expect(list).toBeDefined(); expect(list).toBeDefined();
}); });
......
...@@ -47,6 +47,7 @@ describe('Issue model', () => { ...@@ -47,6 +47,7 @@ describe('Issue model', () => {
color: 'blue', color: 'blue',
description: 'bugs!' description: 'bugs!'
}); });
expect(issue.labels.length).toBe(2); expect(issue.labels.length).toBe(2);
}); });
...@@ -63,12 +64,14 @@ describe('Issue model', () => { ...@@ -63,12 +64,14 @@ describe('Issue model', () => {
it('finds label', () => { it('finds label', () => {
const label = issue.findLabel(issue.labels[0]); const label = issue.findLabel(issue.labels[0]);
expect(label).toBeDefined(); expect(label).toBeDefined();
}); });
it('removes label', () => { it('removes label', () => {
const label = issue.findLabel(issue.labels[0]); const label = issue.findLabel(issue.labels[0]);
issue.removeLabel(label); issue.removeLabel(label);
expect(issue.labels.length).toBe(0); expect(issue.labels.length).toBe(0);
}); });
...@@ -79,9 +82,11 @@ describe('Issue model', () => { ...@@ -79,9 +82,11 @@ describe('Issue model', () => {
color: 'blue', color: 'blue',
description: 'bugs!' description: 'bugs!'
}); });
expect(issue.labels.length).toBe(2); expect(issue.labels.length).toBe(2);
issue.removeLabels([issue.labels[0], issue.labels[1]]); issue.removeLabels([issue.labels[0], issue.labels[1]]);
expect(issue.labels.length).toBe(0); expect(issue.labels.length).toBe(0);
}); });
...@@ -98,17 +103,20 @@ describe('Issue model', () => { ...@@ -98,17 +103,20 @@ describe('Issue model', () => {
it('finds assignee', () => { it('finds assignee', () => {
const assignee = issue.findAssignee(issue.assignees[0]); const assignee = issue.findAssignee(issue.assignees[0]);
expect(assignee).toBeDefined(); expect(assignee).toBeDefined();
}); });
it('removes assignee', () => { it('removes assignee', () => {
const assignee = issue.findAssignee(issue.assignees[0]); const assignee = issue.findAssignee(issue.assignees[0]);
issue.removeAssignee(assignee); issue.removeAssignee(assignee);
expect(issue.assignees.length).toBe(0); expect(issue.assignees.length).toBe(0);
}); });
it('removes all assignees', () => { it('removes all assignees', () => {
issue.removeAllAssignees(); issue.removeAllAssignees();
expect(issue.assignees.length).toBe(0); expect(issue.assignees.length).toBe(0);
}); });
...@@ -131,6 +139,7 @@ describe('Issue model', () => { ...@@ -131,6 +139,7 @@ describe('Issue model', () => {
it('updates data', () => { it('updates data', () => {
issue.updateData({ subscribed: true }); issue.updateData({ subscribed: true });
expect(issue.subscribed).toBe(true); expect(issue.subscribed).toBe(true);
}); });
......
...@@ -60,6 +60,7 @@ describe('List model', () => { ...@@ -60,6 +60,7 @@ describe('List model', () => {
it('destroys the list', (done) => { it('destroys the list', (done) => {
boardsStore.addList(listObj); boardsStore.addList(listObj);
list = boardsStore.findList('id', listObj.id); list = boardsStore.findList('id', listObj.id);
expect(boardsStore.state.lists.length).toBe(1); expect(boardsStore.state.lists.length).toBe(1);
list.destroy(); list.destroy();
...@@ -72,6 +73,7 @@ describe('List model', () => { ...@@ -72,6 +73,7 @@ describe('List model', () => {
it('gets issue from list', (done) => { it('gets issue from list', (done) => {
setTimeout(() => { setTimeout(() => {
const issue = list.findIssue(1); const issue = list.findIssue(1);
expect(issue).toBeDefined(); expect(issue).toBeDefined();
done(); done();
}, 0); }, 0);
...@@ -80,8 +82,10 @@ describe('List model', () => { ...@@ -80,8 +82,10 @@ describe('List model', () => {
it('removes issue', (done) => { it('removes issue', (done) => {
setTimeout(() => { setTimeout(() => {
const issue = list.findIssue(1); const issue = list.findIssue(1);
expect(list.issues.length).toBe(1); expect(list.issues.length).toBe(1);
list.removeIssue(issue); list.removeIssue(issue);
expect(list.issues.length).toBe(0); expect(list.issues.length).toBe(0);
done(); done();
}, 0); }, 0);
......
...@@ -14,13 +14,15 @@ import '~/commons/bootstrap'; ...@@ -14,13 +14,15 @@ import '~/commons/bootstrap';
var $input; var $input;
$input = $('input').first(); $input = $('input').first();
$input.disable(); $input.disable();
return expect($input).toHaveAttr('disabled', 'disabled');
expect($input).toHaveAttr('disabled', 'disabled');
}); });
return it('adds the disabled class', function() { return it('adds the disabled class', function() {
var $input; var $input;
$input = $('input').first(); $input = $('input').first();
$input.disable(); $input.disable();
return expect($input).toHaveClass('disabled');
expect($input).toHaveClass('disabled');
}); });
}); });
return describe('enable', function() { return describe('enable', function() {
...@@ -32,13 +34,15 @@ import '~/commons/bootstrap'; ...@@ -32,13 +34,15 @@ import '~/commons/bootstrap';
var $input; var $input;
$input = $('input').first(); $input = $('input').first();
$input.enable(); $input.enable();
return expect($input).not.toHaveAttr('disabled');
expect($input).not.toHaveAttr('disabled');
}); });
return it('removes the disabled class', function() { return it('removes the disabled class', function() {
var $input; var $input;
$input = $('input').first(); $input = $('input').first();
$input.enable(); $input.enable();
return expect($input).not.toHaveClass('disabled');
expect($input).not.toHaveClass('disabled');
}); });
}); });
}); });
......
...@@ -41,6 +41,7 @@ describe('VariableList', () => { ...@@ -41,6 +41,7 @@ describe('VariableList', () => {
// Check for the correct default in the new row // Check for the correct default in the new row
const $keyInput = $wrapper.find('.js-row:last-child').find('.js-ci-variable-input-key'); const $keyInput = $wrapper.find('.js-row:last-child').find('.js-ci-variable-input-key');
expect($keyInput.val()).toBe(''); expect($keyInput.val()).toBe('');
}); });
...@@ -54,6 +55,7 @@ describe('VariableList', () => { ...@@ -54,6 +55,7 @@ describe('VariableList', () => {
// Check for the correct default in the new row // Check for the correct default in the new row
const $valueInput = $wrapper.find('.js-row:last-child').find('.js-ci-variable-input-key'); const $valueInput = $wrapper.find('.js-row:last-child').find('.js-ci-variable-input-key');
expect($valueInput.val()).toBe(''); expect($valueInput.val()).toBe('');
}); });
...@@ -129,6 +131,7 @@ describe('VariableList', () => { ...@@ -129,6 +131,7 @@ describe('VariableList', () => {
// Check for the correct default in the new row // Check for the correct default in the new row
const $protectedInput = $wrapper.find('.js-row:last-child').find('.js-ci-variable-input-protected'); const $protectedInput = $wrapper.find('.js-row:last-child').find('.js-ci-variable-input-protected');
expect($protectedInput.val()).toBe('false'); expect($protectedInput.val()).toBe('false');
}) })
.then(done) .then(done)
...@@ -166,6 +169,7 @@ describe('VariableList', () => { ...@@ -166,6 +169,7 @@ describe('VariableList', () => {
it('should enable all remove buttons', () => { it('should enable all remove buttons', () => {
variableList.toggleEnableRow(false); variableList.toggleEnableRow(false);
expect($wrapper.find('.js-row-remove-button[disabled]').length).toBe(3); expect($wrapper.find('.js-row-remove-button[disabled]').length).toBe(3);
variableList.toggleEnableRow(true); variableList.toggleEnableRow(true);
...@@ -175,6 +179,7 @@ describe('VariableList', () => { ...@@ -175,6 +179,7 @@ describe('VariableList', () => {
it('should enable all key inputs', () => { it('should enable all key inputs', () => {
variableList.toggleEnableRow(false); variableList.toggleEnableRow(false);
expect($wrapper.find('.js-ci-variable-input-key[disabled]').length).toBe(3); expect($wrapper.find('.js-ci-variable-input-key[disabled]').length).toBe(3);
variableList.toggleEnableRow(true); variableList.toggleEnableRow(true);
......
...@@ -19,6 +19,7 @@ describe('NativeFormVariableList', () => { ...@@ -19,6 +19,7 @@ describe('NativeFormVariableList', () => {
describe('onFormSubmit', () => { describe('onFormSubmit', () => {
it('should clear out the `name` attribute on the inputs for the last empty row on form submission (avoid BE validation)', () => { it('should clear out the `name` attribute on the inputs for the last empty row on form submission (avoid BE validation)', () => {
const $row = $wrapper.find('.js-row'); const $row = $wrapper.find('.js-row');
expect($row.find('.js-ci-variable-input-key').attr('name')).toBe('schedule[variables_attributes][][key]'); expect($row.find('.js-ci-variable-input-key').attr('name')).toBe('schedule[variables_attributes][][key]');
expect($row.find('.js-ci-variable-input-value').attr('name')).toBe('schedule[variables_attributes][][secret_value]'); expect($row.find('.js-ci-variable-input-value').attr('name')).toBe('schedule[variables_attributes][][secret_value]');
......
...@@ -86,6 +86,7 @@ describe('Clusters', () => { ...@@ -86,6 +86,7 @@ describe('Clusters', () => {
}); });
const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text'); const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text');
expect(flashMessage).toBeNull(); expect(flashMessage).toBeNull();
}); });
...@@ -99,6 +100,7 @@ describe('Clusters', () => { ...@@ -99,6 +100,7 @@ describe('Clusters', () => {
}); });
const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text'); const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text');
expect(flashMessage).not.toBeNull(); expect(flashMessage).not.toBeNull();
expect(flashMessage.textContent.trim()).toEqual('Helm Tiller was successfully installed on your Kubernetes cluster'); expect(flashMessage.textContent.trim()).toEqual('Helm Tiller was successfully installed on your Kubernetes cluster');
}); });
...@@ -115,6 +117,7 @@ describe('Clusters', () => { ...@@ -115,6 +117,7 @@ describe('Clusters', () => {
}); });
const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text'); const flashMessage = document.querySelector('.js-cluster-application-notice .flash-text');
expect(flashMessage).not.toBeNull(); expect(flashMessage).not.toBeNull();
expect(flashMessage.textContent.trim()).toEqual('Helm Tiller, Ingress was successfully installed on your Kubernetes cluster'); expect(flashMessage.textContent.trim()).toEqual('Helm Tiller, Ingress was successfully installed on your Kubernetes cluster');
}); });
...@@ -128,9 +131,11 @@ describe('Clusters', () => { ...@@ -128,9 +131,11 @@ describe('Clusters', () => {
expect( expect(
cluster.creatingContainer.classList.contains('hidden'), cluster.creatingContainer.classList.contains('hidden'),
).toBeFalsy(); ).toBeFalsy();
expect( expect(
cluster.successContainer.classList.contains('hidden'), cluster.successContainer.classList.contains('hidden'),
).toBeTruthy(); ).toBeTruthy();
expect( expect(
cluster.errorContainer.classList.contains('hidden'), cluster.errorContainer.classList.contains('hidden'),
).toBeTruthy(); ).toBeTruthy();
...@@ -142,9 +147,11 @@ describe('Clusters', () => { ...@@ -142,9 +147,11 @@ describe('Clusters', () => {
expect( expect(
cluster.creatingContainer.classList.contains('hidden'), cluster.creatingContainer.classList.contains('hidden'),
).toBeFalsy(); ).toBeFalsy();
expect( expect(
cluster.successContainer.classList.contains('hidden'), cluster.successContainer.classList.contains('hidden'),
).toBeTruthy(); ).toBeTruthy();
expect( expect(
cluster.errorContainer.classList.contains('hidden'), cluster.errorContainer.classList.contains('hidden'),
).toBeTruthy(); ).toBeTruthy();
...@@ -158,9 +165,11 @@ describe('Clusters', () => { ...@@ -158,9 +165,11 @@ describe('Clusters', () => {
expect( expect(
cluster.creatingContainer.classList.contains('hidden'), cluster.creatingContainer.classList.contains('hidden'),
).toBeTruthy(); ).toBeTruthy();
expect( expect(
cluster.successContainer.classList.contains('hidden'), cluster.successContainer.classList.contains('hidden'),
).toBeFalsy(); ).toBeFalsy();
expect( expect(
cluster.errorContainer.classList.contains('hidden'), cluster.errorContainer.classList.contains('hidden'),
).toBeTruthy(); ).toBeTruthy();
...@@ -172,9 +181,11 @@ describe('Clusters', () => { ...@@ -172,9 +181,11 @@ describe('Clusters', () => {
expect( expect(
cluster.creatingContainer.classList.contains('hidden'), cluster.creatingContainer.classList.contains('hidden'),
).toBeTruthy(); ).toBeTruthy();
expect( expect(
cluster.successContainer.classList.contains('hidden'), cluster.successContainer.classList.contains('hidden'),
).toBeTruthy(); ).toBeTruthy();
expect( expect(
cluster.errorContainer.classList.contains('hidden'), cluster.errorContainer.classList.contains('hidden'),
).toBeTruthy(); ).toBeTruthy();
...@@ -188,9 +199,11 @@ describe('Clusters', () => { ...@@ -188,9 +199,11 @@ describe('Clusters', () => {
expect( expect(
cluster.creatingContainer.classList.contains('hidden'), cluster.creatingContainer.classList.contains('hidden'),
).toBeTruthy(); ).toBeTruthy();
expect( expect(
cluster.successContainer.classList.contains('hidden'), cluster.successContainer.classList.contains('hidden'),
).toBeTruthy(); ).toBeTruthy();
expect( expect(
cluster.errorContainer.classList.contains('hidden'), cluster.errorContainer.classList.contains('hidden'),
).toBeFalsy(); ).toBeFalsy();
...@@ -206,9 +219,11 @@ describe('Clusters', () => { ...@@ -206,9 +219,11 @@ describe('Clusters', () => {
expect( expect(
cluster.creatingContainer.classList.contains('hidden'), cluster.creatingContainer.classList.contains('hidden'),
).toBeTruthy(); ).toBeTruthy();
expect( expect(
cluster.successContainer.classList.contains('hidden'), cluster.successContainer.classList.contains('hidden'),
).toBeTruthy(); ).toBeTruthy();
expect( expect(
cluster.errorContainer.classList.contains('hidden'), cluster.errorContainer.classList.contains('hidden'),
).toBeFalsy(); ).toBeFalsy();
...@@ -219,6 +234,7 @@ describe('Clusters', () => { ...@@ -219,6 +234,7 @@ describe('Clusters', () => {
describe('installApplication', () => { describe('installApplication', () => {
it('tries to install helm', (done) => { it('tries to install helm', (done) => {
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve()); spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
expect(cluster.store.state.applications.helm.requestStatus).toEqual(null); expect(cluster.store.state.applications.helm.requestStatus).toEqual(null);
cluster.installApplication({ id: 'helm' }); cluster.installApplication({ id: 'helm' });
...@@ -238,6 +254,7 @@ describe('Clusters', () => { ...@@ -238,6 +254,7 @@ describe('Clusters', () => {
it('tries to install ingress', (done) => { it('tries to install ingress', (done) => {
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve()); spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
expect(cluster.store.state.applications.ingress.requestStatus).toEqual(null); expect(cluster.store.state.applications.ingress.requestStatus).toEqual(null);
cluster.installApplication({ id: 'ingress' }); cluster.installApplication({ id: 'ingress' });
...@@ -257,6 +274,7 @@ describe('Clusters', () => { ...@@ -257,6 +274,7 @@ describe('Clusters', () => {
it('tries to install runner', (done) => { it('tries to install runner', (done) => {
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve()); spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
expect(cluster.store.state.applications.runner.requestStatus).toEqual(null); expect(cluster.store.state.applications.runner.requestStatus).toEqual(null);
cluster.installApplication({ id: 'runner' }); cluster.installApplication({ id: 'runner' });
...@@ -276,6 +294,7 @@ describe('Clusters', () => { ...@@ -276,6 +294,7 @@ describe('Clusters', () => {
it('tries to install jupyter', (done) => { it('tries to install jupyter', (done) => {
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve()); spyOn(cluster.service, 'installApplication').and.returnValue(Promise.resolve());
expect(cluster.store.state.applications.jupyter.requestStatus).toEqual(null); expect(cluster.store.state.applications.jupyter.requestStatus).toEqual(null);
cluster.installApplication({ id: 'jupyter', params: { hostname: cluster.store.state.applications.jupyter.hostname } }); cluster.installApplication({ id: 'jupyter', params: { hostname: cluster.store.state.applications.jupyter.hostname } });
...@@ -294,6 +313,7 @@ describe('Clusters', () => { ...@@ -294,6 +313,7 @@ describe('Clusters', () => {
it('sets error request status when the request fails', (done) => { it('sets error request status when the request fails', (done) => {
spyOn(cluster.service, 'installApplication').and.returnValue(Promise.reject(new Error('STUBBED ERROR'))); spyOn(cluster.service, 'installApplication').and.returnValue(Promise.reject(new Error('STUBBED ERROR')));
expect(cluster.store.state.applications.helm.requestStatus).toEqual(null); expect(cluster.store.state.applications.helm.requestStatus).toEqual(null);
cluster.installApplication({ id: 'helm' }); cluster.installApplication({ id: 'helm' });
......
...@@ -4,10 +4,12 @@ describe('CommitMergeRequests', () => { ...@@ -4,10 +4,12 @@ describe('CommitMergeRequests', () => {
describe('createContent', () => { describe('createContent', () => {
it('should return created content', () => { it('should return created content', () => {
const content1 = CommitMergeRequests.createContent([{ iid: 1, path: '/path1', title: 'foo' }, { iid: 2, path: '/path2', title: 'baz' }])[0]; const content1 = CommitMergeRequests.createContent([{ iid: 1, path: '/path1', title: 'foo' }, { iid: 2, path: '/path2', title: 'baz' }])[0];
expect(content1.tagName).toEqual('SPAN'); expect(content1.tagName).toEqual('SPAN');
expect(content1.childElementCount).toEqual(4); expect(content1.childElementCount).toEqual(4);
const content2 = CommitMergeRequests.createContent([])[0]; const content2 = CommitMergeRequests.createContent([])[0];
expect(content2.tagName).toEqual('SPAN'); expect(content2.tagName).toEqual('SPAN');
expect(content2.childElementCount).toEqual(0); expect(content2.childElementCount).toEqual(0);
expect(content2.innerText).toEqual('No related merge requests found'); expect(content2.innerText).toEqual('No related merge requests found');
...@@ -26,6 +28,7 @@ describe('CommitMergeRequests', () => { ...@@ -26,6 +28,7 @@ describe('CommitMergeRequests', () => {
describe('createHeader', () => { describe('createHeader', () => {
it('should return created header', () => { it('should return created header', () => {
const header = CommitMergeRequests.createHeader(0, 1)[0]; const header = CommitMergeRequests.createHeader(0, 1)[0];
expect(header.tagName).toEqual('SPAN'); expect(header.tagName).toEqual('SPAN');
expect(header.innerText).toEqual('1 merge request'); expect(header.innerText).toEqual('1 merge request');
}); });
...@@ -34,6 +37,7 @@ describe('CommitMergeRequests', () => { ...@@ -34,6 +37,7 @@ describe('CommitMergeRequests', () => {
describe('createItem', () => { describe('createItem', () => {
it('should return created item', () => { it('should return created item', () => {
const item = CommitMergeRequests.createItem({ iid: 1, path: '/path', title: 'foo' })[0]; const item = CommitMergeRequests.createItem({ iid: 1, path: '/path', title: 'foo' })[0];
expect(item.tagName).toEqual('SPAN'); expect(item.tagName).toEqual('SPAN');
expect(item.childElementCount).toEqual(2); expect(item.childElementCount).toEqual(2);
expect(item.children[0].tagName).toEqual('A'); expect(item.children[0].tagName).toEqual('A');
...@@ -44,6 +48,7 @@ describe('CommitMergeRequests', () => { ...@@ -44,6 +48,7 @@ describe('CommitMergeRequests', () => {
describe('createLink', () => { describe('createLink', () => {
it('should return created link', () => { it('should return created link', () => {
const link = CommitMergeRequests.createLink({ iid: 1, path: '/path', title: 'foo' })[0]; const link = CommitMergeRequests.createLink({ iid: 1, path: '/path', title: 'foo' })[0];
expect(link.tagName).toEqual('A'); expect(link.tagName).toEqual('A');
expect(link.href).toMatch(/\/path$/); expect(link.href).toMatch(/\/path$/);
expect(link.innerText).toEqual('!1'); expect(link.innerText).toEqual('!1');
...@@ -53,6 +58,7 @@ describe('CommitMergeRequests', () => { ...@@ -53,6 +58,7 @@ describe('CommitMergeRequests', () => {
describe('createTitle', () => { describe('createTitle', () => {
it('should return created title', () => { it('should return created title', () => {
const title = CommitMergeRequests.createTitle({ iid: 1, path: '/path', title: 'foo' })[0]; const title = CommitMergeRequests.createTitle({ iid: 1, path: '/path', title: 'foo' })[0];
expect(title.tagName).toEqual('SPAN'); expect(title.tagName).toEqual('SPAN');
expect(title.innerText).toEqual('foo'); expect(title.innerText).toEqual('foo');
}); });
......
...@@ -63,6 +63,7 @@ describe('CreateItemDropdown', () => { ...@@ -63,6 +63,7 @@ describe('CreateItemDropdown', () => {
$('.js-dropdown-menu-toggle').click(); $('.js-dropdown-menu-toggle').click();
const $itemEls = $wrapperEl.find('.js-dropdown-content a'); const $itemEls = $wrapperEl.find('.js-dropdown-content a');
expect($itemEls.length).toEqual(DROPDOWN_ITEM_DATA.length); expect($itemEls.length).toEqual(DROPDOWN_ITEM_DATA.length);
}); });
}); });
...@@ -106,6 +107,7 @@ describe('CreateItemDropdown', () => { ...@@ -106,6 +107,7 @@ describe('CreateItemDropdown', () => {
createItemAndClearInput(NEW_ITEM_TEXT); createItemAndClearInput(NEW_ITEM_TEXT);
const $itemEls = $wrapperEl.find('.js-dropdown-content a'); const $itemEls = $wrapperEl.find('.js-dropdown-content a');
expect($itemEls.length).toEqual(1 + DROPDOWN_ITEM_DATA.length); expect($itemEls.length).toEqual(1 + DROPDOWN_ITEM_DATA.length);
expect($($itemEls.get(DROPDOWN_ITEM_DATA.length)).text()).toEqual(NEW_ITEM_TEXT); expect($($itemEls.get(DROPDOWN_ITEM_DATA.length)).text()).toEqual(NEW_ITEM_TEXT);
}); });
...@@ -114,6 +116,7 @@ describe('CreateItemDropdown', () => { ...@@ -114,6 +116,7 @@ describe('CreateItemDropdown', () => {
createItemAndClearInput(DROPDOWN_ITEM_DATA[0].text); createItemAndClearInput(DROPDOWN_ITEM_DATA[0].text);
const $itemEls = $wrapperEl.find('.js-dropdown-content a'); const $itemEls = $wrapperEl.find('.js-dropdown-content a');
expect($itemEls.length).toEqual(DROPDOWN_ITEM_DATA.length); expect($itemEls.length).toEqual(DROPDOWN_ITEM_DATA.length);
}); });
}); });
...@@ -142,11 +145,13 @@ describe('CreateItemDropdown', () => { ...@@ -142,11 +145,13 @@ describe('CreateItemDropdown', () => {
.trigger('input'); .trigger('input');
const $itemElsAfterFilter = $wrapperEl.find('.js-dropdown-content a'); const $itemElsAfterFilter = $wrapperEl.find('.js-dropdown-content a');
expect($itemElsAfterFilter.length).toEqual(1); expect($itemElsAfterFilter.length).toEqual(1);
createItemDropdown.clearDropdown(); createItemDropdown.clearDropdown();
const $itemElsAfterClear = $wrapperEl.find('.js-dropdown-content a'); const $itemElsAfterClear = $wrapperEl.find('.js-dropdown-content a');
expect($itemElsAfterClear.length).toEqual(0); expect($itemElsAfterClear.length).toEqual(0);
expect(filterInput.val()).toEqual(''); expect(filterInput.val()).toEqual('');
}); });
...@@ -176,6 +181,7 @@ describe('CreateItemDropdown', () => { ...@@ -176,6 +181,7 @@ describe('CreateItemDropdown', () => {
createItemAndClearInput('new-item'); createItemAndClearInput('new-item');
const $itemEls = $wrapperEl.find('.js-dropdown-content a'); const $itemEls = $wrapperEl.find('.js-dropdown-content a');
expect($itemEls.length).toEqual(1 + DROPDOWN_ITEM_DATA.length); expect($itemEls.length).toEqual(1 + DROPDOWN_ITEM_DATA.length);
expect($($itemEls[3]).text()).toEqual('new-item-text'); expect($($itemEls[3]).text()).toEqual('new-item-text');
expect($wrapperEl.find('.dropdown-toggle-text').text()).toEqual('new-item-title'); expect($wrapperEl.find('.dropdown-toggle-text').text()).toEqual('new-item-title');
......
...@@ -59,6 +59,7 @@ describe('CreateMergeRequestDropdown', () => { ...@@ -59,6 +59,7 @@ describe('CreateMergeRequestDropdown', () => {
expect(dropdown.createBranchPath).toBe( expect(dropdown.createBranchPath).toBe(
`${TEST_HOST}/branches?branch_name=contains%23hash&issue=42`, `${TEST_HOST}/branches?branch_name=contains%23hash&issue=42`,
); );
expect(dropdown.createMrPath).toBe( expect(dropdown.createMrPath).toBe(
`${TEST_HOST}/create_merge_request?branch_name=contains%23hash&ref=master`, `${TEST_HOST}/create_merge_request?branch_name=contains%23hash&ref=master`,
); );
......
...@@ -24,9 +24,11 @@ describe('Cycle analytics banner', () => { ...@@ -24,9 +24,11 @@ describe('Cycle analytics banner', () => {
expect( expect(
vm.$el.querySelector('p').textContent.trim().replace(/[\r\n]+/g, ' '), vm.$el.querySelector('p').textContent.trim().replace(/[\r\n]+/g, ' '),
).toContain('Cycle Analytics gives an overview of how much time it takes to go from idea to production in your project.'); ).toContain('Cycle Analytics gives an overview of how much time it takes to go from idea to production in your project.');
expect( expect(
vm.$el.querySelector('a').textContent.trim(), vm.$el.querySelector('a').textContent.trim(),
).toEqual('Read more'); ).toEqual('Read more');
expect( expect(
vm.$el.querySelector('a').getAttribute('href'), vm.$el.querySelector('a').getAttribute('href'),
).toEqual('path'); ).toEqual('path');
......
...@@ -24,36 +24,43 @@ describe('Date time utils', () => { ...@@ -24,36 +24,43 @@ describe('Date time utils', () => {
describe('get day name', () => { describe('get day name', () => {
it('should return Sunday', () => { it('should return Sunday', () => {
const day = datetimeUtility.getDayName(new Date('07/17/2016')); const day = datetimeUtility.getDayName(new Date('07/17/2016'));
expect(day).toBe('Sunday'); expect(day).toBe('Sunday');
}); });
it('should return Monday', () => { it('should return Monday', () => {
const day = datetimeUtility.getDayName(new Date('07/18/2016')); const day = datetimeUtility.getDayName(new Date('07/18/2016'));
expect(day).toBe('Monday'); expect(day).toBe('Monday');
}); });
it('should return Tuesday', () => { it('should return Tuesday', () => {
const day = datetimeUtility.getDayName(new Date('07/19/2016')); const day = datetimeUtility.getDayName(new Date('07/19/2016'));
expect(day).toBe('Tuesday'); expect(day).toBe('Tuesday');
}); });
it('should return Wednesday', () => { it('should return Wednesday', () => {
const day = datetimeUtility.getDayName(new Date('07/20/2016')); const day = datetimeUtility.getDayName(new Date('07/20/2016'));
expect(day).toBe('Wednesday'); expect(day).toBe('Wednesday');
}); });
it('should return Thursday', () => { it('should return Thursday', () => {
const day = datetimeUtility.getDayName(new Date('07/21/2016')); const day = datetimeUtility.getDayName(new Date('07/21/2016'));
expect(day).toBe('Thursday'); expect(day).toBe('Thursday');
}); });
it('should return Friday', () => { it('should return Friday', () => {
const day = datetimeUtility.getDayName(new Date('07/22/2016')); const day = datetimeUtility.getDayName(new Date('07/22/2016'));
expect(day).toBe('Friday'); expect(day).toBe('Friday');
}); });
it('should return Saturday', () => { it('should return Saturday', () => {
const day = datetimeUtility.getDayName(new Date('07/23/2016')); const day = datetimeUtility.getDayName(new Date('07/23/2016'));
expect(day).toBe('Saturday'); expect(day).toBe('Saturday');
}); });
}); });
...@@ -63,6 +70,7 @@ describe('Date time utils', () => { ...@@ -63,6 +70,7 @@ describe('Date time utils', () => {
const firstDay = new Date('07/01/2016'); const firstDay = new Date('07/01/2016');
const secondDay = new Date('07/08/2016'); const secondDay = new Date('07/08/2016');
const difference = datetimeUtility.getDayDifference(firstDay, secondDay); const difference = datetimeUtility.getDayDifference(firstDay, secondDay);
expect(difference).toBe(7); expect(difference).toBe(7);
}); });
...@@ -70,6 +78,7 @@ describe('Date time utils', () => { ...@@ -70,6 +78,7 @@ describe('Date time utils', () => {
const firstDay = new Date('07/01/2016'); const firstDay = new Date('07/01/2016');
const secondDay = new Date('08/01/2016'); const secondDay = new Date('08/01/2016');
const difference = datetimeUtility.getDayDifference(firstDay, secondDay); const difference = datetimeUtility.getDayDifference(firstDay, secondDay);
expect(difference).toBe(31); expect(difference).toBe(31);
}); });
...@@ -77,6 +86,7 @@ describe('Date time utils', () => { ...@@ -77,6 +86,7 @@ describe('Date time utils', () => {
const firstDay = new Date('07/02/2015'); const firstDay = new Date('07/02/2015');
const secondDay = new Date('07/01/2016'); const secondDay = new Date('07/01/2016');
const difference = datetimeUtility.getDayDifference(firstDay, secondDay); const difference = datetimeUtility.getDayDifference(firstDay, secondDay);
expect(difference).toBe(365); expect(difference).toBe(365);
}); });
}); });
...@@ -156,6 +166,7 @@ describe('getTimeframeWindowFrom', () => { ...@@ -156,6 +166,7 @@ describe('getTimeframeWindowFrom', () => {
new Date(2018, 4, 31), new Date(2018, 4, 31),
]; ];
const timeframe = datetimeUtility.getTimeframeWindowFrom(startDate, 5); const timeframe = datetimeUtility.getTimeframeWindowFrom(startDate, 5);
expect(timeframe.length).toBe(5); expect(timeframe.length).toBe(5);
timeframe.forEach((timeframeItem, index) => { timeframe.forEach((timeframeItem, index) => {
expect(timeframeItem.getFullYear()).toBe(mockTimeframe[index].getFullYear()); expect(timeframeItem.getFullYear()).toBe(mockTimeframe[index].getFullYear());
......
...@@ -60,6 +60,7 @@ describe('Deploy keys app component', () => { ...@@ -60,6 +60,7 @@ describe('Deploy keys app component', () => {
expect(textContent('.js-deployKeys-tab-available_project_keys')).toContain( expect(textContent('.js-deployKeys-tab-available_project_keys')).toContain(
'Privately accessible deploy keys', 'Privately accessible deploy keys',
); );
expect(textContent('.js-deployKeys-tab-public_keys')).toContain( expect(textContent('.js-deployKeys-tab-public_keys')).toContain(
'Publicly accessible deploy keys', 'Publicly accessible deploy keys',
); );
...@@ -67,9 +68,11 @@ describe('Deploy keys app component', () => { ...@@ -67,9 +68,11 @@ describe('Deploy keys app component', () => {
expect(textContent('.js-deployKeys-tab-enabled_keys .badge')).toBe( expect(textContent('.js-deployKeys-tab-enabled_keys .badge')).toBe(
`${vm.store.keys.enabled_keys.length}`, `${vm.store.keys.enabled_keys.length}`,
); );
expect(textContent('.js-deployKeys-tab-available_project_keys .badge')).toBe( expect(textContent('.js-deployKeys-tab-available_project_keys .badge')).toBe(
`${vm.store.keys.available_project_keys.length}`, `${vm.store.keys.available_project_keys.length}`,
); );
expect(textContent('.js-deployKeys-tab-public_keys .badge')).toBe( expect(textContent('.js-deployKeys-tab-public_keys .badge')).toBe(
`${vm.store.keys.public_keys.length}`, `${vm.store.keys.public_keys.length}`,
); );
......
...@@ -82,6 +82,7 @@ describe('Deploy keys key', () => { ...@@ -82,6 +82,7 @@ describe('Deploy keys key', () => {
it('shows expandable button if more than two projects', () => { it('shows expandable button if more than two projects', () => {
const labels = vm.$el.querySelectorAll('.deploy-project-label'); const labels = vm.$el.querySelectorAll('.deploy-project-label');
expect(labels.length).toBe(2); expect(labels.length).toBe(2);
expect(labels[1].textContent).toContain('others'); expect(labels[1].textContent).toContain('others');
expect(labels[1].getAttribute('data-original-title')).toContain('Expand'); expect(labels[1].getAttribute('data-original-title')).toContain('Expand');
...@@ -93,6 +94,7 @@ describe('Deploy keys key', () => { ...@@ -93,6 +94,7 @@ describe('Deploy keys key', () => {
Vue.nextTick(() => { Vue.nextTick(() => {
const labels = vm.$el.querySelectorAll('.deploy-project-label'); const labels = vm.$el.querySelectorAll('.deploy-project-label');
expect(labels.length).toBe(length); expect(labels.length).toBe(length);
expect(labels[1].textContent).not.toContain(`+${length} others`); expect(labels[1].textContent).not.toContain(`+${length} others`);
expect(labels[1].getAttribute('data-original-title')).not.toContain('Expand'); expect(labels[1].getAttribute('data-original-title')).not.toContain('Expand');
...@@ -105,6 +107,7 @@ describe('Deploy keys key', () => { ...@@ -105,6 +107,7 @@ describe('Deploy keys key', () => {
Vue.nextTick(() => { Vue.nextTick(() => {
const labels = vm.$el.querySelectorAll('.deploy-project-label'); const labels = vm.$el.querySelectorAll('.deploy-project-label');
expect(labels.length).toBe(2); expect(labels.length).toBe(2);
expect(labels[1].textContent).toContain( expect(labels[1].textContent).toContain(
vm.deployKey.deploy_keys_projects[1].project.full_name, vm.deployKey.deploy_keys_projects[1].project.full_name,
......
...@@ -26,6 +26,7 @@ describe('New discussion', () => { ...@@ -26,6 +26,7 @@ describe('New discussion', () => {
it('creates new discussion', () => { it('creates new discussion', () => {
expect(Object.keys(CommentsStore.state).length).toBe(0); expect(Object.keys(CommentsStore.state).length).toBe(0);
createDiscussion(); createDiscussion();
expect(Object.keys(CommentsStore.state).length).toBe(1); expect(Object.keys(CommentsStore.state).length).toBe(1);
}); });
...@@ -34,6 +35,7 @@ describe('New discussion', () => { ...@@ -34,6 +35,7 @@ describe('New discussion', () => {
createDiscussion(2); createDiscussion(2);
const discussion = CommentsStore.state['a']; const discussion = CommentsStore.state['a'];
expect(Object.keys(discussion.notes).length).toBe(2); expect(Object.keys(discussion.notes).length).toBe(2);
}); });
}); });
...@@ -46,6 +48,7 @@ describe('Get note', () => { ...@@ -46,6 +48,7 @@ describe('Get note', () => {
it('gets note by ID', () => { it('gets note by ID', () => {
const note = CommentsStore.get('a', 1); const note = CommentsStore.get('a', 1);
expect(note).toBeDefined(); expect(note).toBeDefined();
expect(note.id).toBe(1); expect(note.id).toBe(1);
}); });
...@@ -59,17 +62,20 @@ describe('Delete discussion', () => { ...@@ -59,17 +62,20 @@ describe('Delete discussion', () => {
it('deletes discussion by ID', () => { it('deletes discussion by ID', () => {
CommentsStore.delete('a', 1); CommentsStore.delete('a', 1);
expect(Object.keys(CommentsStore.state).length).toBe(0); expect(Object.keys(CommentsStore.state).length).toBe(0);
}); });
it('deletes discussion when no more notes', () => { it('deletes discussion when no more notes', () => {
createDiscussion(); createDiscussion();
createDiscussion(2); createDiscussion(2);
expect(Object.keys(CommentsStore.state).length).toBe(1); expect(Object.keys(CommentsStore.state).length).toBe(1);
expect(Object.keys(CommentsStore.state['a'].notes).length).toBe(2); expect(Object.keys(CommentsStore.state['a'].notes).length).toBe(2);
CommentsStore.delete('a', 1); CommentsStore.delete('a', 1);
CommentsStore.delete('a', 2); CommentsStore.delete('a', 2);
expect(Object.keys(CommentsStore.state).length).toBe(0); expect(Object.keys(CommentsStore.state).length).toBe(0);
}); });
}); });
...@@ -84,6 +90,7 @@ describe('Update note', () => { ...@@ -84,6 +90,7 @@ describe('Update note', () => {
CommentsStore.update('a', 1, false, 'test'); CommentsStore.update('a', 1, false, 'test');
const note = CommentsStore.get('a', 1); const note = CommentsStore.get('a', 1);
expect(note.resolved).toBe(false); expect(note.resolved).toBe(false);
}); });
}); });
...@@ -96,6 +103,7 @@ describe('Discussion resolved', () => { ...@@ -96,6 +103,7 @@ describe('Discussion resolved', () => {
it('is resolved with single note', () => { it('is resolved with single note', () => {
const discussion = CommentsStore.state['a']; const discussion = CommentsStore.state['a'];
expect(discussion.isResolved()).toBe(true); expect(discussion.isResolved()).toBe(true);
}); });
...@@ -118,6 +126,7 @@ describe('Discussion resolved', () => { ...@@ -118,6 +126,7 @@ describe('Discussion resolved', () => {
createDiscussion(2, false); createDiscussion(2, false);
discussion.resolveAllNotes(); discussion.resolveAllNotes();
expect(discussion.isResolved()).toBe(true); expect(discussion.isResolved()).toBe(true);
}); });
...@@ -126,6 +135,7 @@ describe('Discussion resolved', () => { ...@@ -126,6 +135,7 @@ describe('Discussion resolved', () => {
createDiscussion(2); createDiscussion(2);
discussion.unResolveAllNotes(); discussion.unResolveAllNotes();
expect(discussion.isResolved()).toBe(false); expect(discussion.isResolved()).toBe(false);
}); });
}); });
...@@ -98,6 +98,7 @@ describe('diff_file_header', () => { ...@@ -98,6 +98,7 @@ describe('diff_file_header', () => {
props.discussionPath = 'link://to/discussion'; props.discussionPath = 'link://to/discussion';
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
const href = vm.$el.querySelector('.js-title-wrapper').getAttribute('href'); const href = vm.$el.querySelector('.js-title-wrapper').getAttribute('href');
expect(href).toBe(vm.discussionPath); expect(href).toBe(vm.discussionPath);
}); });
}); });
...@@ -270,6 +271,7 @@ describe('diff_file_header', () => { ...@@ -270,6 +271,7 @@ describe('diff_file_header', () => {
it('displays an file icon in the title', () => { it('displays an file icon in the title', () => {
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
expect(vm.$el.querySelector('svg.js-file-icon use').getAttribute('xlink:href')).toContain( expect(vm.$el.querySelector('svg.js-file-icon use').getAttribute('xlink:href')).toContain(
'ruby', 'ruby',
); );
...@@ -312,6 +314,7 @@ describe('diff_file_header', () => { ...@@ -312,6 +314,7 @@ describe('diff_file_header', () => {
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
const button = vm.$el.querySelector('.btn-clipboard'); const button = vm.$el.querySelector('.btn-clipboard');
expect(button).not.toBe(null); expect(button).not.toBe(null);
expect(button.dataset.clipboardText).toBe('{"text":"files/ruby/popen.rb","gfm":"`files/ruby/popen.rb`"}'); expect(button.dataset.clipboardText).toBe('{"text":"files/ruby/popen.rb","gfm":"`files/ruby/popen.rb`"}');
}); });
...@@ -323,6 +326,7 @@ describe('diff_file_header', () => { ...@@ -323,6 +326,7 @@ describe('diff_file_header', () => {
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
const { fileMode } = vm.$refs; const { fileMode } = vm.$refs;
expect(fileMode).not.toBe(undefined); expect(fileMode).not.toBe(undefined);
expect(fileMode).toContainText(props.diffFile.aMode); expect(fileMode).toContainText(props.diffFile.aMode);
expect(fileMode).toContainText(props.diffFile.bMode); expect(fileMode).toContainText(props.diffFile.bMode);
...@@ -334,6 +338,7 @@ describe('diff_file_header', () => { ...@@ -334,6 +338,7 @@ describe('diff_file_header', () => {
vm = mountComponentWithStore(Component, { props, store }); vm = mountComponentWithStore(Component, { props, store });
const { fileMode } = vm.$refs; const { fileMode } = vm.$refs;
expect(fileMode).toBe(undefined); expect(fileMode).toBe(undefined);
}); });
}); });
......
...@@ -97,6 +97,7 @@ describe('DiffFile', () => { ...@@ -97,6 +97,7 @@ describe('DiffFile', () => {
expect(vm.$el.innerText).toContain( expect(vm.$el.innerText).toContain(
'This source diff could not be displayed because it is too large', 'This source diff could not be displayed because it is too large',
); );
expect(vm.$el.querySelector('.js-too-large-diff')).toBeDefined(); expect(vm.$el.querySelector('.js-too-large-diff')).toBeDefined();
expect(vm.$el.querySelector('.js-too-large-diff a').href.indexOf(BLOB_LINK)).toBeGreaterThan(-1); expect(vm.$el.querySelector('.js-too-large-diff a').href.indexOf(BLOB_LINK)).toBeGreaterThan(-1);
......
...@@ -23,6 +23,7 @@ describe('DiffGutterAvatars', () => { ...@@ -23,6 +23,7 @@ describe('DiffGutterAvatars', () => {
it('should return false when all discussions are not expanded', () => { it('should return false when all discussions are not expanded', () => {
component.discussions[0].expanded = false; component.discussions[0].expanded = false;
expect(component.discussionsExpanded).toEqual(false); expect(component.discussionsExpanded).toEqual(false);
}); });
}); });
...@@ -56,6 +57,7 @@ describe('DiffGutterAvatars', () => { ...@@ -56,6 +57,7 @@ describe('DiffGutterAvatars', () => {
it('should return empty string if there is no discussion', () => { it('should return empty string if there is no discussion', () => {
component.discussions = []; component.discussions = [];
expect(component.moreText).toEqual(''); expect(component.moreText).toEqual('');
}); });
}); });
......
...@@ -31,12 +31,14 @@ describe('DiffLineGutterContent', () => { ...@@ -31,12 +31,14 @@ describe('DiffLineGutterContent', () => {
it('should prepend # to lineCode', () => { it('should prepend # to lineCode', () => {
const lineCode = 'LC_42'; const lineCode = 'LC_42';
const component = createComponent(); const component = createComponent();
expect(component.lineHref).toEqual(`#${lineCode}`); expect(component.lineHref).toEqual(`#${lineCode}`);
}); });
it('should return # if there is no lineCode', () => { it('should return # if there is no lineCode', () => {
const component = createComponent(); const component = createComponent();
component.line.lineCode = ''; component.line.lineCode = '';
expect(component.lineHref).toEqual('#'); expect(component.lineHref).toEqual('#');
}); });
}); });
...@@ -44,6 +46,7 @@ describe('DiffLineGutterContent', () => { ...@@ -44,6 +46,7 @@ describe('DiffLineGutterContent', () => {
describe('discussions, hasDiscussions, shouldShowAvatarsOnGutter', () => { describe('discussions, hasDiscussions, shouldShowAvatarsOnGutter', () => {
it('should return empty array when there is no discussion', () => { it('should return empty array when there is no discussion', () => {
const component = createComponent(); const component = createComponent();
expect(component.hasDiscussions).toEqual(false); expect(component.hasDiscussions).toEqual(false);
expect(component.shouldShowAvatarsOnGutter).toEqual(false); expect(component.shouldShowAvatarsOnGutter).toEqual(false);
}); });
......
...@@ -36,6 +36,7 @@ describe('DiffLineNoteForm', () => { ...@@ -36,6 +36,7 @@ describe('DiffLineNoteForm', () => {
spyOn(window, 'confirm').and.returnValue(false); spyOn(window, 'confirm').and.returnValue(false);
component.handleCancelCommentForm(true, true); component.handleCancelCommentForm(true, true);
expect(window.confirm).toHaveBeenCalled(); expect(window.confirm).toHaveBeenCalled();
}); });
...@@ -43,9 +44,11 @@ describe('DiffLineNoteForm', () => { ...@@ -43,9 +44,11 @@ describe('DiffLineNoteForm', () => {
spyOn(window, 'confirm').and.returnValue(false); spyOn(window, 'confirm').and.returnValue(false);
component.handleCancelCommentForm(true, false); component.handleCancelCommentForm(true, false);
expect(window.confirm).not.toHaveBeenCalled(); expect(window.confirm).not.toHaveBeenCalled();
component.handleCancelCommentForm(false, true); component.handleCancelCommentForm(false, true);
expect(window.confirm).not.toHaveBeenCalled(); expect(window.confirm).not.toHaveBeenCalled();
}); });
...@@ -60,6 +63,7 @@ describe('DiffLineNoteForm', () => { ...@@ -60,6 +63,7 @@ describe('DiffLineNoteForm', () => {
expect(component.cancelCommentForm).toHaveBeenCalledWith({ expect(component.cancelCommentForm).toHaveBeenCalledWith({
lineCode: diffLines[0].lineCode, lineCode: diffLines[0].lineCode,
}); });
expect(component.resetAutoSave).toHaveBeenCalled(); expect(component.resetAutoSave).toHaveBeenCalled();
done(); done();
......
...@@ -52,11 +52,13 @@ describe('Diffs Module Getters', () => { ...@@ -52,11 +52,13 @@ describe('Diffs Module Getters', () => {
describe('areAllFilesCollapsed', () => { describe('areAllFilesCollapsed', () => {
it('returns true when all files are collapsed', () => { it('returns true when all files are collapsed', () => {
localState.diffFiles = [{ collapsed: true }, { collapsed: true }]; localState.diffFiles = [{ collapsed: true }, { collapsed: true }];
expect(getters.areAllFilesCollapsed(localState)).toEqual(true); expect(getters.areAllFilesCollapsed(localState)).toEqual(true);
}); });
it('returns false when at least one file is not collapsed', () => { it('returns false when at least one file is not collapsed', () => {
localState.diffFiles = [{ collapsed: false }, { collapsed: true }]; localState.diffFiles = [{ collapsed: false }, { collapsed: true }];
expect(getters.areAllFilesCollapsed(localState)).toEqual(false); expect(getters.areAllFilesCollapsed(localState)).toEqual(false);
}); });
}); });
...@@ -244,6 +246,7 @@ describe('Diffs Module Getters', () => { ...@@ -244,6 +246,7 @@ describe('Diffs Module Getters', () => {
it('returns false when no line discussions were found', () => { it('returns false when no line discussions were found', () => {
line.discussions = []; line.discussions = [];
expect(getters.shouldRenderInlineCommentRow(localState)(line)).toEqual(false); expect(getters.shouldRenderInlineCommentRow(localState)(line)).toEqual(false);
}); });
...@@ -288,6 +291,7 @@ describe('Diffs Module Getters', () => { ...@@ -288,6 +291,7 @@ describe('Diffs Module Getters', () => {
it('returns null if no matching file is found', () => { it('returns null if no matching file is found', () => {
localState.diffFiles = []; localState.diffFiles = [];
expect(getters.getDiffFileByHash(localState)('123')).toBeUndefined(); expect(getters.getDiffFileByHash(localState)('123')).toBeUndefined();
}); });
}); });
......
...@@ -12,6 +12,7 @@ describe('DiffsStoreMutations', () => { ...@@ -12,6 +12,7 @@ describe('DiffsStoreMutations', () => {
const projectPath = '/root/project'; const projectPath = '/root/project';
mutations[types.SET_BASE_CONFIG](state, { endpoint, projectPath }); mutations[types.SET_BASE_CONFIG](state, { endpoint, projectPath });
expect(state.endpoint).toEqual(endpoint); expect(state.endpoint).toEqual(endpoint);
expect(state.projectPath).toEqual(projectPath); expect(state.projectPath).toEqual(projectPath);
}); });
...@@ -22,6 +23,7 @@ describe('DiffsStoreMutations', () => { ...@@ -22,6 +23,7 @@ describe('DiffsStoreMutations', () => {
const state = {}; const state = {};
mutations[types.SET_LOADING](state, false); mutations[types.SET_LOADING](state, false);
expect(state.isLoading).toEqual(false); expect(state.isLoading).toEqual(false);
}); });
}); });
...@@ -48,6 +50,7 @@ describe('DiffsStoreMutations', () => { ...@@ -48,6 +50,7 @@ describe('DiffsStoreMutations', () => {
const state = {}; const state = {};
mutations[types.SET_DIFF_VIEW_TYPE](state, INLINE_DIFF_VIEW_TYPE); mutations[types.SET_DIFF_VIEW_TYPE](state, INLINE_DIFF_VIEW_TYPE);
expect(state.diffViewType).toEqual(INLINE_DIFF_VIEW_TYPE); expect(state.diffViewType).toEqual(INLINE_DIFF_VIEW_TYPE);
}); });
}); });
...@@ -58,6 +61,7 @@ describe('DiffsStoreMutations', () => { ...@@ -58,6 +61,7 @@ describe('DiffsStoreMutations', () => {
const lineCode = 'FDE'; const lineCode = 'FDE';
mutations[types.ADD_COMMENT_FORM_LINE](state, { lineCode }); mutations[types.ADD_COMMENT_FORM_LINE](state, { lineCode });
expect(state.diffLineCommentForms[lineCode]).toBeTruthy(); expect(state.diffLineCommentForms[lineCode]).toBeTruthy();
}); });
}); });
...@@ -68,9 +72,11 @@ describe('DiffsStoreMutations', () => { ...@@ -68,9 +72,11 @@ describe('DiffsStoreMutations', () => {
const lineCode = 'FDE'; const lineCode = 'FDE';
mutations[types.ADD_COMMENT_FORM_LINE](state, { lineCode }); mutations[types.ADD_COMMENT_FORM_LINE](state, { lineCode });
expect(state.diffLineCommentForms[lineCode]).toBeTruthy(); expect(state.diffLineCommentForms[lineCode]).toBeTruthy();
mutations[types.REMOVE_COMMENT_FORM_LINE](state, { lineCode }); mutations[types.REMOVE_COMMENT_FORM_LINE](state, { lineCode });
expect(state.diffLineCommentForms[lineCode]).toBeUndefined(); expect(state.diffLineCommentForms[lineCode]).toBeUndefined();
}); });
}); });
...@@ -83,6 +89,7 @@ describe('DiffsStoreMutations', () => { ...@@ -83,6 +89,7 @@ describe('DiffsStoreMutations', () => {
const state = { expandAllFiles: true, diffFiles: [diffFile] }; const state = { expandAllFiles: true, diffFiles: [diffFile] };
mutations[types.EXPAND_ALL_FILES](state); mutations[types.EXPAND_ALL_FILES](state);
expect(state.diffFiles[0].collapsed).toEqual(false); expect(state.diffFiles[0].collapsed).toEqual(false);
}); });
}); });
...@@ -118,11 +125,13 @@ describe('DiffsStoreMutations', () => { ...@@ -118,11 +125,13 @@ describe('DiffsStoreMutations', () => {
options.lineNumbers, options.lineNumbers,
options.params.bottom, options.params.bottom,
); );
expect(lineRefSpy).toHaveBeenCalledWith( expect(lineRefSpy).toHaveBeenCalledWith(
options.contextLines, options.contextLines,
options.lineNumbers, options.lineNumbers,
options.params.bottom, options.params.bottom,
); );
expect(addContextLinesSpy).toHaveBeenCalledWith({ expect(addContextLinesSpy).toHaveBeenCalledWith({
inlineLines: diffFile.highlightedDiffLines, inlineLines: diffFile.highlightedDiffLines,
parallelLines: diffFile.parallelDiffLines, parallelLines: diffFile.parallelDiffLines,
...@@ -142,6 +151,7 @@ describe('DiffsStoreMutations', () => { ...@@ -142,6 +151,7 @@ describe('DiffsStoreMutations', () => {
const data = { diff_files: [{ file_hash: fileHash, extra_field: 1, existingField: 1 }] }; const data = { diff_files: [{ file_hash: fileHash, extra_field: 1, existingField: 1 }] };
mutations[types.ADD_COLLAPSED_DIFFS](state, { file: state.diffFiles[1], data }); mutations[types.ADD_COLLAPSED_DIFFS](state, { file: state.diffFiles[1], data });
expect(spy).toHaveBeenCalledWith(data, { deep: true }); expect(spy).toHaveBeenCalledWith(data, { deep: true });
expect(state.diffFiles[1].fileHash).toEqual(fileHash); expect(state.diffFiles[1].fileHash).toEqual(fileHash);
...@@ -345,6 +355,7 @@ describe('DiffsStoreMutations', () => { ...@@ -345,6 +355,7 @@ describe('DiffsStoreMutations', () => {
fileHash: 'ABC', fileHash: 'ABC',
lineCode: 'ABC_1', lineCode: 'ABC_1',
}); });
expect(state.diffFiles[0].parallelDiffLines[0].left.discussions.length).toEqual(0); expect(state.diffFiles[0].parallelDiffLines[0].left.discussions.length).toEqual(0);
expect(state.diffFiles[0].highlightedDiffLines[0].discussions.length).toEqual(0); expect(state.diffFiles[0].highlightedDiffLines[0].discussions.length).toEqual(0);
}); });
......
...@@ -62,10 +62,12 @@ describe('DiffsStoreUtils', () => { ...@@ -62,10 +62,12 @@ describe('DiffsStoreUtils', () => {
const atParallelIndex = diffFile.parallelDiffLines[parallelIndex]; const atParallelIndex = diffFile.parallelDiffLines[parallelIndex];
utils.removeMatchLine(diffFile, lineNumbers, false); utils.removeMatchLine(diffFile, lineNumbers, false);
expect(diffFile.highlightedDiffLines[inlineIndex]).not.toEqual(atInlineIndex); expect(diffFile.highlightedDiffLines[inlineIndex]).not.toEqual(atInlineIndex);
expect(diffFile.parallelDiffLines[parallelIndex]).not.toEqual(atParallelIndex); expect(diffFile.parallelDiffLines[parallelIndex]).not.toEqual(atParallelIndex);
utils.removeMatchLine(diffFile, lineNumbers, true); utils.removeMatchLine(diffFile, lineNumbers, true);
expect(diffFile.highlightedDiffLines[inlineIndex + 1]).not.toEqual(atInlineIndex); expect(diffFile.highlightedDiffLines[inlineIndex + 1]).not.toEqual(atInlineIndex);
expect(diffFile.parallelDiffLines[parallelIndex + 1]).not.toEqual(atParallelIndex); expect(diffFile.parallelDiffLines[parallelIndex + 1]).not.toEqual(atParallelIndex);
}); });
...@@ -87,11 +89,13 @@ describe('DiffsStoreUtils', () => { ...@@ -87,11 +89,13 @@ describe('DiffsStoreUtils', () => {
}; };
utils.addContextLines(options); utils.addContextLines(options);
expect(inlineLines[inlineLines.length - 1]).toEqual(contextLines[0]); expect(inlineLines[inlineLines.length - 1]).toEqual(contextLines[0]);
expect(parallelLines[parallelLines.length - 1]).toEqual(normalizedParallelLine); expect(parallelLines[parallelLines.length - 1]).toEqual(normalizedParallelLine);
delete options.bottom; delete options.bottom;
utils.addContextLines(options); utils.addContextLines(options);
expect(inlineLines[inlineIndex]).toEqual(contextLines[0]); expect(inlineLines[inlineIndex]).toEqual(contextLines[0]);
expect(parallelLines[parallelIndex]).toEqual(normalizedParallelLine); expect(parallelLines[parallelIndex]).toEqual(normalizedParallelLine);
}); });
...@@ -274,6 +278,7 @@ describe('DiffsStoreUtils', () => { ...@@ -274,6 +278,7 @@ describe('DiffsStoreUtils', () => {
}; };
utils.trimFirstCharOfLineContent(lineObj); utils.trimFirstCharOfLineContent(lineObj);
expect(lineObj).toEqual({ discussions: [], richText: ' diff' }); expect(lineObj).toEqual({ discussions: [], richText: ' diff' });
}); });
...@@ -288,19 +293,23 @@ describe('DiffsStoreUtils', () => { ...@@ -288,19 +293,23 @@ describe('DiffsStoreUtils', () => {
utils.prepareDiffData(preparedDiff); utils.prepareDiffData(preparedDiff);
const firstParallelDiffLine = preparedDiff.diffFiles[0].parallelDiffLines[2]; const firstParallelDiffLine = preparedDiff.diffFiles[0].parallelDiffLines[2];
expect(firstParallelDiffLine.left.discussions.length).toBe(0); expect(firstParallelDiffLine.left.discussions.length).toBe(0);
expect(firstParallelDiffLine.left).not.toHaveAttr('text'); expect(firstParallelDiffLine.left).not.toHaveAttr('text');
expect(firstParallelDiffLine.right.discussions.length).toBe(0); expect(firstParallelDiffLine.right.discussions.length).toBe(0);
expect(firstParallelDiffLine.right).not.toHaveAttr('text'); expect(firstParallelDiffLine.right).not.toHaveAttr('text');
const firstParallelChar = firstParallelDiffLine.right.richText.charAt(0); const firstParallelChar = firstParallelDiffLine.right.richText.charAt(0);
expect(firstParallelChar).not.toBe(' '); expect(firstParallelChar).not.toBe(' ');
expect(firstParallelChar).not.toBe('+'); expect(firstParallelChar).not.toBe('+');
expect(firstParallelChar).not.toBe('-'); expect(firstParallelChar).not.toBe('-');
const checkLine = preparedDiff.diffFiles[0].highlightedDiffLines[0]; const checkLine = preparedDiff.diffFiles[0].highlightedDiffLines[0];
expect(checkLine.discussions.length).toBe(0); expect(checkLine.discussions.length).toBe(0);
expect(checkLine).not.toHaveAttr('text'); expect(checkLine).not.toHaveAttr('text');
const firstChar = checkLine.richText.charAt(0); const firstChar = checkLine.richText.charAt(0);
expect(firstChar).not.toBe(' '); expect(firstChar).not.toBe(' ');
expect(firstChar).not.toBe('+'); expect(firstChar).not.toBe('+');
expect(firstChar).not.toBe('-'); expect(firstChar).not.toBe('-');
......
...@@ -15,9 +15,13 @@ describe('DirtySubmitCollection', () => { ...@@ -15,9 +15,13 @@ describe('DirtySubmitCollection', () => {
expect(submit.disabled).toBe(true); expect(submit.disabled).toBe(true);
return setInput(input, `${originalValue} changes`) return setInput(input, `${originalValue} changes`)
.then(() => expect(submit.disabled).toBe(false)) .then(() => {
expect(submit.disabled).toBe(false);
})
.then(() => setInput(input, originalValue)) .then(() => setInput(input, originalValue))
.then(() => expect(submit.disabled).toBe(true)) .then(() => {
expect(submit.disabled).toBe(true);
})
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
}); });
......
...@@ -12,9 +12,13 @@ describe('DirtySubmitForm', () => { ...@@ -12,9 +12,13 @@ describe('DirtySubmitForm', () => {
expect(submit.disabled).toBe(true); expect(submit.disabled).toBe(true);
return setInput(input, `${originalValue} changes`) return setInput(input, `${originalValue} changes`)
.then(() => expect(submit.disabled).toBe(false)) .then(() => {
expect(submit.disabled).toBe(false);
})
.then(() => setInput(input, originalValue)) .then(() => setInput(input, originalValue))
.then(() => expect(submit.disabled).toBe(true)) .then(() => {
expect(submit.disabled).toBe(true);
})
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
}); });
......
...@@ -8,6 +8,7 @@ describe('Ajax', () => { ...@@ -8,6 +8,7 @@ describe('Ajax', () => {
describe('is not configured', () => { describe('is not configured', () => {
it('passes the data through', () => { it('passes the data through', () => {
const data = ['data']; const data = ['data'];
expect(Ajax.preprocessing(config, data)).toEqual(data); expect(Ajax.preprocessing(config, data)).toEqual(data);
}); });
}); });
...@@ -22,13 +23,17 @@ describe('Ajax', () => { ...@@ -22,13 +23,17 @@ describe('Ajax', () => {
it('calls preprocessing', () => { it('calls preprocessing', () => {
Ajax.preprocessing(config, []); Ajax.preprocessing(config, []);
expect(config.preprocessing.calls.count()).toBe(1); expect(config.preprocessing.calls.count()).toBe(1);
}); });
it('overrides AjaxCache', () => { it('overrides AjaxCache', () => {
spyOn(AjaxCache, 'override').and.callFake((endpoint, results) => expect(results).toEqual(processedArray)); spyOn(AjaxCache, 'override').and.callFake((endpoint, results) => {
expect(results).toEqual(processedArray);
});
Ajax.preprocessing(config, []); Ajax.preprocessing(config, []);
expect(AjaxCache.override.calls.count()).toBe(1); expect(AjaxCache.override.calls.count()).toBe(1);
}); });
}); });
......
...@@ -375,6 +375,7 @@ describe('gl_emoji', () => { ...@@ -375,6 +375,7 @@ describe('gl_emoji', () => {
'', '',
'1.0', '1.0',
); );
expect(isSupported).toBeTruthy(); expect(isSupported).toBeTruthy();
}); });
...@@ -384,6 +385,7 @@ describe('gl_emoji', () => { ...@@ -384,6 +385,7 @@ describe('gl_emoji', () => {
'', '',
'1.0', '1.0',
); );
expect(isSupported).toBeFalsy(); expect(isSupported).toBeFalsy();
}); });
...@@ -397,6 +399,7 @@ describe('gl_emoji', () => { ...@@ -397,6 +399,7 @@ describe('gl_emoji', () => {
emojiFixtureMap[emojiKey].moji, emojiFixtureMap[emojiKey].moji,
emojiFixtureMap[emojiKey].unicodeVersion, emojiFixtureMap[emojiKey].unicodeVersion,
); );
expect(isSupported).toBeTruthy(); expect(isSupported).toBeTruthy();
}); });
...@@ -408,6 +411,7 @@ describe('gl_emoji', () => { ...@@ -408,6 +411,7 @@ describe('gl_emoji', () => {
emojiFixtureMap[emojiKey].moji, emojiFixtureMap[emojiKey].moji,
emojiFixtureMap[emojiKey].unicodeVersion, emojiFixtureMap[emojiKey].unicodeVersion,
); );
expect(isSupported).toBeFalsy(); expect(isSupported).toBeFalsy();
}); });
...@@ -421,6 +425,7 @@ describe('gl_emoji', () => { ...@@ -421,6 +425,7 @@ describe('gl_emoji', () => {
emojiFixtureMap[emojiKey].moji, emojiFixtureMap[emojiKey].moji,
emojiFixtureMap[emojiKey].unicodeVersion, emojiFixtureMap[emojiKey].unicodeVersion,
); );
expect(isSupported).toBeFalsy(); expect(isSupported).toBeFalsy();
}); });
...@@ -446,6 +451,7 @@ describe('gl_emoji', () => { ...@@ -446,6 +451,7 @@ describe('gl_emoji', () => {
emojiFixtureMap[emojiKey].moji, emojiFixtureMap[emojiKey].moji,
emojiFixtureMap[emojiKey].unicodeVersion, emojiFixtureMap[emojiKey].unicodeVersion,
); );
expect(isSupported).toBeFalsy(); expect(isSupported).toBeFalsy();
}); });
...@@ -463,6 +469,7 @@ describe('gl_emoji', () => { ...@@ -463,6 +469,7 @@ describe('gl_emoji', () => {
emojiFixtureMap[emojiKey].moji, emojiFixtureMap[emojiKey].moji,
emojiFixtureMap[emojiKey].unicodeVersion, emojiFixtureMap[emojiKey].unicodeVersion,
); );
expect(isSupported).toBeTruthy(); expect(isSupported).toBeTruthy();
}); });
...@@ -480,6 +487,7 @@ describe('gl_emoji', () => { ...@@ -480,6 +487,7 @@ describe('gl_emoji', () => {
emojiFixtureMap[emojiKey].moji, emojiFixtureMap[emojiKey].moji,
emojiFixtureMap[emojiKey].unicodeVersion, emojiFixtureMap[emojiKey].unicodeVersion,
); );
expect(isSupported).toBeFalsy(); expect(isSupported).toBeFalsy();
}); });
}); });
......
...@@ -94,6 +94,7 @@ describe('Environment', () => { ...@@ -94,6 +94,7 @@ describe('Environment', () => {
spyOn(component, 'updateContent'); spyOn(component, 'updateContent');
setTimeout(() => { setTimeout(() => {
component.$el.querySelector('.gl-pagination li:nth-child(5) a').click(); component.$el.querySelector('.gl-pagination li:nth-child(5) a').click();
expect(component.updateContent).toHaveBeenCalledWith({ scope: 'available', page: '2' }); expect(component.updateContent).toHaveBeenCalledWith({ scope: 'available', page: '2' });
done(); done();
}, 0); }, 0);
......
...@@ -17,23 +17,27 @@ describe('Store', () => { ...@@ -17,23 +17,27 @@ describe('Store', () => {
it('should store environments', () => { it('should store environments', () => {
store.storeEnvironments(serverData); store.storeEnvironments(serverData);
expect(store.state.environments.length).toEqual(serverData.length); expect(store.state.environments.length).toEqual(serverData.length);
expect(store.state.environments[0]).toEqual(environmentsList[0]); expect(store.state.environments[0]).toEqual(environmentsList[0]);
}); });
it('should store available count', () => { it('should store available count', () => {
store.storeAvailableCount(2); store.storeAvailableCount(2);
expect(store.state.availableCounter).toEqual(2); expect(store.state.availableCounter).toEqual(2);
}); });
it('should store stopped count', () => { it('should store stopped count', () => {
store.storeStoppedCount(2); store.storeStoppedCount(2);
expect(store.state.stoppedCounter).toEqual(2); expect(store.state.stoppedCounter).toEqual(2);
}); });
describe('store environments', () => { describe('store environments', () => {
it('should store environments', () => { it('should store environments', () => {
store.storeEnvironments(serverData); store.storeEnvironments(serverData);
expect(store.state.environments.length).toEqual(serverData.length); expect(store.state.environments.length).toEqual(serverData.length);
}); });
...@@ -45,6 +49,7 @@ describe('Store', () => { ...@@ -45,6 +49,7 @@ describe('Store', () => {
}; };
store.storeEnvironments([environment]); store.storeEnvironments([environment]);
expect(store.state.environments[0].isFolder).toEqual(true); expect(store.state.environments[0].isFolder).toEqual(true);
expect(store.state.environments[0].folderName).toEqual('bar'); expect(store.state.environments[0].folderName).toEqual('bar');
}); });
...@@ -61,17 +66,20 @@ describe('Store', () => { ...@@ -61,17 +66,20 @@ describe('Store', () => {
}; };
store.storeEnvironments([environment]); store.storeEnvironments([environment]);
expect(store.state.environments[0].last_deployment).toEqual({}); expect(store.state.environments[0].last_deployment).toEqual({});
expect(store.state.environments[0].isStoppable).toEqual(true); expect(store.state.environments[0].isStoppable).toEqual(true);
}); });
it('should store latest.name when the environment is not a folder', () => { it('should store latest.name when the environment is not a folder', () => {
store.storeEnvironments(serverData); store.storeEnvironments(serverData);
expect(store.state.environments[0].name).toEqual(serverData[0].latest.name); expect(store.state.environments[0].name).toEqual(serverData[0].latest.name);
}); });
it('should store root level name when environment is a folder', () => { it('should store root level name when environment is a folder', () => {
store.storeEnvironments(serverData); store.storeEnvironments(serverData);
expect(store.state.environments[1].folderName).toEqual(serverData[1].name); expect(store.state.environments[1].folderName).toEqual(serverData[1].name);
}); });
}); });
...@@ -81,9 +89,11 @@ describe('Store', () => { ...@@ -81,9 +89,11 @@ describe('Store', () => {
store.storeEnvironments(serverData); store.storeEnvironments(serverData);
store.toggleFolder(store.state.environments[1]); store.toggleFolder(store.state.environments[1]);
expect(store.state.environments[1].isOpen).toEqual(true); expect(store.state.environments[1].isOpen).toEqual(true);
store.toggleFolder(store.state.environments[1]); store.toggleFolder(store.state.environments[1]);
expect(store.state.environments[1].isOpen).toEqual(false); expect(store.state.environments[1].isOpen).toEqual(false);
}); });
...@@ -91,9 +101,11 @@ describe('Store', () => { ...@@ -91,9 +101,11 @@ describe('Store', () => {
store.storeEnvironments(serverData); store.storeEnvironments(serverData);
store.toggleFolder(store.state.environments[1]); store.toggleFolder(store.state.environments[1]);
expect(store.state.environments[1].isOpen).toEqual(true); expect(store.state.environments[1].isOpen).toEqual(true);
store.storeEnvironments(serverData); store.storeEnvironments(serverData);
expect(store.state.environments[1].isOpen).toEqual(true); expect(store.state.environments[1].isOpen).toEqual(true);
}); });
}); });
...@@ -116,6 +128,7 @@ describe('Store', () => { ...@@ -116,6 +128,7 @@ describe('Store', () => {
expect(store.state.environments[1].children.length).toEqual(serverData.length); expect(store.state.environments[1].children.length).toEqual(serverData.length);
// poll // poll
store.storeEnvironments(serverData); store.storeEnvironments(serverData);
expect(store.state.environments[1].children.length).toEqual(serverData.length); expect(store.state.environments[1].children.length).toEqual(serverData.length);
}); });
}); });
...@@ -141,6 +154,7 @@ describe('Store', () => { ...@@ -141,6 +154,7 @@ describe('Store', () => {
}; };
store.setPagination(pagination); store.setPagination(pagination);
expect(store.state.paginationInformation).toEqual(expectedResult); expect(store.state.paginationInformation).toEqual(expectedResult);
}); });
}); });
...@@ -150,6 +164,7 @@ describe('Store', () => { ...@@ -150,6 +164,7 @@ describe('Store', () => {
store.storeEnvironments(serverData); store.storeEnvironments(serverData);
store.toggleFolder(store.state.environments[1]); store.toggleFolder(store.state.environments[1]);
expect(store.getOpenFolders()[0]).toEqual(store.state.environments[1]); expect(store.getOpenFolders()[0]).toEqual(store.state.environments[1]);
}); });
}); });
......
...@@ -14,6 +14,7 @@ describe('feature highlight helper', () => { ...@@ -14,6 +14,7 @@ describe('feature highlight helper', () => {
describe('getSelector', () => { describe('getSelector', () => {
it('returns js-feature-highlight selector', () => { it('returns js-feature-highlight selector', () => {
const highlightId = 'highlightId'; const highlightId = 'highlightId';
expect(getSelector(highlightId)).toEqual(`.js-feature-highlight[data-highlight=${highlightId}]`); expect(getSelector(highlightId)).toEqual(`.js-feature-highlight[data-highlight=${highlightId}]`);
}); });
}); });
......
...@@ -63,6 +63,7 @@ describe('feature highlight', () => { ...@@ -63,6 +63,7 @@ describe('feature highlight', () => {
it('setup show.bs.popover', () => { it('setup show.bs.popover', () => {
$(selector).trigger('show.bs.popover'); $(selector).trigger('show.bs.popover');
expect(window.addEventListener).toHaveBeenCalledWith('scroll', jasmine.any(Function), { once: true }); expect(window.addEventListener).toHaveBeenCalledWith('scroll', jasmine.any(Function), { once: true });
}); });
...@@ -73,6 +74,7 @@ describe('feature highlight', () => { ...@@ -73,6 +74,7 @@ describe('feature highlight', () => {
it('displays popover', () => { it('displays popover', () => {
expect(document.querySelector(selector).getAttribute('aria-describedby')).toBeFalsy(); expect(document.querySelector(selector).getAttribute('aria-describedby')).toBeFalsy();
$(selector).trigger('mouseenter'); $(selector).trigger('mouseenter');
expect(document.querySelector(selector).getAttribute('aria-describedby')).toBeTruthy(); expect(document.querySelector(selector).getAttribute('aria-describedby')).toBeTruthy();
}); });
......
...@@ -47,6 +47,7 @@ describe('RecentSearchesDropdownContent', () => { ...@@ -47,6 +47,7 @@ describe('RecentSearchesDropdownContent', () => {
expect(el.querySelector('.dropdown-info-note')).toBeDefined(); expect(el.querySelector('.dropdown-info-note')).toBeDefined();
const items = el.querySelectorAll('.filtered-search-history-dropdown-item'); const items = el.querySelectorAll('.filtered-search-history-dropdown-item');
expect(items.length).toEqual(propsDataWithoutItems.items.length); expect(items.length).toEqual(propsDataWithoutItems.items.length);
}); });
}); });
...@@ -65,11 +66,13 @@ describe('RecentSearchesDropdownContent', () => { ...@@ -65,11 +66,13 @@ describe('RecentSearchesDropdownContent', () => {
it('should render recent search items', () => { it('should render recent search items', () => {
const items = el.querySelectorAll('.filtered-search-history-dropdown-item'); const items = el.querySelectorAll('.filtered-search-history-dropdown-item');
expect(items.length).toEqual(propsDataWithItems.items.length); expect(items.length).toEqual(propsDataWithItems.items.length);
expect(trimMarkupWhitespace(items[0].querySelector('.filtered-search-history-dropdown-search-token').textContent)).toEqual('foo'); expect(trimMarkupWhitespace(items[0].querySelector('.filtered-search-history-dropdown-search-token').textContent)).toEqual('foo');
const item1Tokens = items[1].querySelectorAll('.filtered-search-history-dropdown-token'); const item1Tokens = items[1].querySelectorAll('.filtered-search-history-dropdown-token');
expect(item1Tokens.length).toEqual(2); expect(item1Tokens.length).toEqual(2);
expect(item1Tokens[0].querySelector('.name').textContent).toEqual('author:'); expect(item1Tokens[0].querySelector('.name').textContent).toEqual('author:');
expect(item1Tokens[0].querySelector('.value').textContent).toEqual('@root'); expect(item1Tokens[0].querySelector('.value').textContent).toEqual('@root');
...@@ -132,12 +135,14 @@ describe('RecentSearchesDropdownContent', () => { ...@@ -132,12 +135,14 @@ describe('RecentSearchesDropdownContent', () => {
it('with items', () => { it('with items', () => {
vm = createComponent(propsDataWithItems); vm = createComponent(propsDataWithItems);
const { hasItems } = vm; const { hasItems } = vm;
expect(hasItems).toEqual(true); expect(hasItems).toEqual(true);
}); });
it('with no items', () => { it('with no items', () => {
vm = createComponent(propsDataWithoutItems); vm = createComponent(propsDataWithoutItems);
const { hasItems } = vm; const { hasItems } = vm;
expect(hasItems).toEqual(false); expect(hasItems).toEqual(false);
}); });
}); });
...@@ -161,6 +166,7 @@ describe('RecentSearchesDropdownContent', () => { ...@@ -161,6 +166,7 @@ describe('RecentSearchesDropdownContent', () => {
it('emits event', () => { it('emits event', () => {
expect(onRecentSearchesItemSelectedSpy).not.toHaveBeenCalled(); expect(onRecentSearchesItemSelectedSpy).not.toHaveBeenCalled();
vm.onItemActivated('something'); vm.onItemActivated('something');
expect(onRecentSearchesItemSelectedSpy).toHaveBeenCalledWith('something'); expect(onRecentSearchesItemSelectedSpy).toHaveBeenCalledWith('something');
}); });
}); });
...@@ -182,6 +188,7 @@ describe('RecentSearchesDropdownContent', () => { ...@@ -182,6 +188,7 @@ describe('RecentSearchesDropdownContent', () => {
it('emits event', () => { it('emits event', () => {
expect(onRequestClearRecentSearchesSpy).not.toHaveBeenCalled(); expect(onRequestClearRecentSearchesSpy).not.toHaveBeenCalled();
vm.onRequestClearRecentSearches({ stopPropagation: () => {} }); vm.onRequestClearRecentSearches({ stopPropagation: () => {} });
expect(onRequestClearRecentSearchesSpy).toHaveBeenCalled(); expect(onRequestClearRecentSearchesSpy).toHaveBeenCalled();
}); });
}); });
......
...@@ -92,6 +92,7 @@ describe('Dropdown User', () => { ...@@ -92,6 +92,7 @@ describe('Dropdown User', () => {
it('hides the current user from dropdown', () => { it('hides the current user from dropdown', () => {
const currentUserElement = findCurrentUserElement(); const currentUserElement = findCurrentUserElement();
expect(currentUserElement).not.toBe(null); expect(currentUserElement).not.toBe(null);
dropdown.hideCurrentUser(); dropdown.hideCurrentUser();
...@@ -102,6 +103,7 @@ describe('Dropdown User', () => { ...@@ -102,6 +103,7 @@ describe('Dropdown User', () => {
it('does nothing if no user is logged in', () => { it('does nothing if no user is logged in', () => {
const currentUserElement = findCurrentUserElement(); const currentUserElement = findCurrentUserElement();
currentUserElement.parentNode.removeChild(currentUserElement); currentUserElement.parentNode.removeChild(currentUserElement);
expect(findCurrentUserElement()).toBe(null); expect(findCurrentUserElement()).toBe(null);
dropdown.hideCurrentUser(); dropdown.hideCurrentUser();
......
...@@ -10,24 +10,29 @@ describe('Dropdown Utils', () => { ...@@ -10,24 +10,29 @@ describe('Dropdown Utils', () => {
describe('getEscapedText', () => { describe('getEscapedText', () => {
it('should return same word when it has no space', () => { it('should return same word when it has no space', () => {
const escaped = DropdownUtils.getEscapedText('textWithoutSpace'); const escaped = DropdownUtils.getEscapedText('textWithoutSpace');
expect(escaped).toBe('textWithoutSpace'); expect(escaped).toBe('textWithoutSpace');
}); });
it('should escape with double quotes', () => { it('should escape with double quotes', () => {
let escaped = DropdownUtils.getEscapedText('text with space'); let escaped = DropdownUtils.getEscapedText('text with space');
expect(escaped).toBe('"text with space"'); expect(escaped).toBe('"text with space"');
escaped = DropdownUtils.getEscapedText('won\'t fix'); escaped = DropdownUtils.getEscapedText('won\'t fix');
expect(escaped).toBe('"won\'t fix"'); expect(escaped).toBe('"won\'t fix"');
}); });
it('should escape with single quotes', () => { it('should escape with single quotes', () => {
const escaped = DropdownUtils.getEscapedText('won"t fix'); const escaped = DropdownUtils.getEscapedText('won"t fix');
expect(escaped).toBe('\'won"t fix\''); expect(escaped).toBe('\'won"t fix\'');
}); });
it('should escape with single quotes by default', () => { it('should escape with single quotes by default', () => {
const escaped = DropdownUtils.getEscapedText('won"t\' fix'); const escaped = DropdownUtils.getEscapedText('won"t\' fix');
expect(escaped).toBe('\'won"t\' fix\''); expect(escaped).toBe('\'won"t\' fix\'');
}); });
}); });
...@@ -50,6 +55,7 @@ describe('Dropdown Utils', () => { ...@@ -50,6 +55,7 @@ describe('Dropdown Utils', () => {
input.value = 'roo'; input.value = 'roo';
const updatedItem = DropdownUtils.filterWithSymbol('@', input, item); const updatedItem = DropdownUtils.filterWithSymbol('@', input, item);
expect(updatedItem.droplab_hidden).toBe(false); expect(updatedItem.droplab_hidden).toBe(false);
}); });
...@@ -57,6 +63,7 @@ describe('Dropdown Utils', () => { ...@@ -57,6 +63,7 @@ describe('Dropdown Utils', () => {
input.value = '@roo'; input.value = '@roo';
const updatedItem = DropdownUtils.filterWithSymbol('@', input, item); const updatedItem = DropdownUtils.filterWithSymbol('@', input, item);
expect(updatedItem.droplab_hidden).toBe(false); expect(updatedItem.droplab_hidden).toBe(false);
}); });
...@@ -69,6 +76,7 @@ describe('Dropdown Utils', () => { ...@@ -69,6 +76,7 @@ describe('Dropdown Utils', () => {
input.value = '"'; input.value = '"';
const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem);
expect(updatedItem.droplab_hidden).toBe(false); expect(updatedItem.droplab_hidden).toBe(false);
}); });
...@@ -76,6 +84,7 @@ describe('Dropdown Utils', () => { ...@@ -76,6 +84,7 @@ describe('Dropdown Utils', () => {
input.value = '~"'; input.value = '~"';
const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem);
expect(updatedItem.droplab_hidden).toBe(false); expect(updatedItem.droplab_hidden).toBe(false);
}); });
...@@ -83,6 +92,7 @@ describe('Dropdown Utils', () => { ...@@ -83,6 +92,7 @@ describe('Dropdown Utils', () => {
input.value = '"community con'; input.value = '"community con';
const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem);
expect(updatedItem.droplab_hidden).toBe(false); expect(updatedItem.droplab_hidden).toBe(false);
}); });
...@@ -90,6 +100,7 @@ describe('Dropdown Utils', () => { ...@@ -90,6 +100,7 @@ describe('Dropdown Utils', () => {
input.value = '~"community con'; input.value = '~"community con';
const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem);
expect(updatedItem.droplab_hidden).toBe(false); expect(updatedItem.droplab_hidden).toBe(false);
}); });
...@@ -97,6 +108,7 @@ describe('Dropdown Utils', () => { ...@@ -97,6 +108,7 @@ describe('Dropdown Utils', () => {
input.value = '\''; input.value = '\'';
const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem);
expect(updatedItem.droplab_hidden).toBe(false); expect(updatedItem.droplab_hidden).toBe(false);
}); });
...@@ -104,6 +116,7 @@ describe('Dropdown Utils', () => { ...@@ -104,6 +116,7 @@ describe('Dropdown Utils', () => {
input.value = '~\''; input.value = '~\'';
const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem);
expect(updatedItem.droplab_hidden).toBe(false); expect(updatedItem.droplab_hidden).toBe(false);
}); });
...@@ -111,6 +124,7 @@ describe('Dropdown Utils', () => { ...@@ -111,6 +124,7 @@ describe('Dropdown Utils', () => {
input.value = '\'community con'; input.value = '\'community con';
const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem);
expect(updatedItem.droplab_hidden).toBe(false); expect(updatedItem.droplab_hidden).toBe(false);
}); });
...@@ -118,6 +132,7 @@ describe('Dropdown Utils', () => { ...@@ -118,6 +132,7 @@ describe('Dropdown Utils', () => {
input.value = '~\'community con'; input.value = '~\'community con';
const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem); const updatedItem = DropdownUtils.filterWithSymbol('~', input, multipleWordItem);
expect(updatedItem.droplab_hidden).toBe(false); expect(updatedItem.droplab_hidden).toBe(false);
}); });
}); });
...@@ -152,17 +167,20 @@ describe('Dropdown Utils', () => { ...@@ -152,17 +167,20 @@ describe('Dropdown Utils', () => {
let updatedItem = DropdownUtils.filterHint(config(), { let updatedItem = DropdownUtils.filterHint(config(), {
hint: 'label', hint: 'label',
}); });
expect(updatedItem.droplab_hidden).toBe(false); expect(updatedItem.droplab_hidden).toBe(false);
input.value = 'o'; input.value = 'o';
updatedItem = DropdownUtils.filterHint(config(), { updatedItem = DropdownUtils.filterHint(config(), {
hint: 'label', hint: 'label',
}); });
expect(updatedItem.droplab_hidden).toBe(true); expect(updatedItem.droplab_hidden).toBe(true);
}); });
it('should return droplab_hidden false when item has no hint', () => { it('should return droplab_hidden false when item has no hint', () => {
const updatedItem = DropdownUtils.filterHint(config(), {}, ''); const updatedItem = DropdownUtils.filterHint(config(), {}, '');
expect(updatedItem.droplab_hidden).toBe(false); expect(updatedItem.droplab_hidden).toBe(false);
}); });
...@@ -172,6 +190,7 @@ describe('Dropdown Utils', () => { ...@@ -172,6 +190,7 @@ describe('Dropdown Utils', () => {
hint: 'label', hint: 'label',
type: 'array', type: 'array',
}); });
expect(updatedItem.droplab_hidden).toBe(false); expect(updatedItem.droplab_hidden).toBe(false);
}); });
...@@ -180,12 +199,14 @@ describe('Dropdown Utils', () => { ...@@ -180,12 +199,14 @@ describe('Dropdown Utils', () => {
let updatedItem = DropdownUtils.filterHint(config(), { let updatedItem = DropdownUtils.filterHint(config(), {
hint: 'milestone', hint: 'milestone',
}); });
expect(updatedItem.droplab_hidden).toBe(true); expect(updatedItem.droplab_hidden).toBe(true);
updatedItem = DropdownUtils.filterHint(config(), { updatedItem = DropdownUtils.filterHint(config(), {
hint: 'milestone', hint: 'milestone',
type: 'string', type: 'string',
}); });
expect(updatedItem.droplab_hidden).toBe(true); expect(updatedItem.droplab_hidden).toBe(true);
}); });
}); });
...@@ -205,6 +226,7 @@ describe('Dropdown Utils', () => { ...@@ -205,6 +226,7 @@ describe('Dropdown Utils', () => {
}; };
const updated = DropdownUtils.mergeDuplicateLabels(dataMap, newLabel); const updated = DropdownUtils.mergeDuplicateLabels(dataMap, newLabel);
expect(updated[newLabel.title]).toEqual(newLabel); expect(updated[newLabel.title]).toEqual(newLabel);
}); });
...@@ -215,6 +237,7 @@ describe('Dropdown Utils', () => { ...@@ -215,6 +237,7 @@ describe('Dropdown Utils', () => {
}; };
const updated = DropdownUtils.mergeDuplicateLabels(dataMap, duplicate); const updated = DropdownUtils.mergeDuplicateLabels(dataMap, duplicate);
expect(updated.label.multipleColors).toEqual([dataMap.label.color, duplicate.color]); expect(updated.label.multipleColors).toEqual([dataMap.label.color, duplicate.color]);
}); });
}); });
...@@ -222,21 +245,25 @@ describe('Dropdown Utils', () => { ...@@ -222,21 +245,25 @@ describe('Dropdown Utils', () => {
describe('duplicateLabelColor', () => { describe('duplicateLabelColor', () => {
it('should linear-gradient 2 colors', () => { it('should linear-gradient 2 colors', () => {
const gradient = DropdownUtils.duplicateLabelColor(['#FFFFFF', '#000000']); const gradient = DropdownUtils.duplicateLabelColor(['#FFFFFF', '#000000']);
expect(gradient).toEqual('linear-gradient(#FFFFFF 0%, #FFFFFF 50%, #000000 50%, #000000 100%)'); expect(gradient).toEqual('linear-gradient(#FFFFFF 0%, #FFFFFF 50%, #000000 50%, #000000 100%)');
}); });
it('should linear-gradient 3 colors', () => { it('should linear-gradient 3 colors', () => {
const gradient = DropdownUtils.duplicateLabelColor(['#FFFFFF', '#000000', '#333333']); const gradient = DropdownUtils.duplicateLabelColor(['#FFFFFF', '#000000', '#333333']);
expect(gradient).toEqual('linear-gradient(#FFFFFF 0%, #FFFFFF 33%, #000000 33%, #000000 66%, #333333 66%, #333333 100%)'); expect(gradient).toEqual('linear-gradient(#FFFFFF 0%, #FFFFFF 33%, #000000 33%, #000000 66%, #333333 66%, #333333 100%)');
}); });
it('should linear-gradient 4 colors', () => { it('should linear-gradient 4 colors', () => {
const gradient = DropdownUtils.duplicateLabelColor(['#FFFFFF', '#000000', '#333333', '#DDDDDD']); const gradient = DropdownUtils.duplicateLabelColor(['#FFFFFF', '#000000', '#333333', '#DDDDDD']);
expect(gradient).toEqual('linear-gradient(#FFFFFF 0%, #FFFFFF 25%, #000000 25%, #000000 50%, #333333 50%, #333333 75%, #DDDDDD 75%, #DDDDDD 100%)'); expect(gradient).toEqual('linear-gradient(#FFFFFF 0%, #FFFFFF 25%, #000000 25%, #000000 50%, #333333 50%, #333333 75%, #DDDDDD 75%, #DDDDDD 100%)');
}); });
it('should not linear-gradient more than 4 colors', () => { it('should not linear-gradient more than 4 colors', () => {
const gradient = DropdownUtils.duplicateLabelColor(['#FFFFFF', '#000000', '#333333', '#DDDDDD', '#EEEEEE']); const gradient = DropdownUtils.duplicateLabelColor(['#FFFFFF', '#000000', '#333333', '#DDDDDD', '#EEEEEE']);
expect(gradient.indexOf('#EEEEEE')).toBe(-1); expect(gradient.indexOf('#EEEEEE')).toBe(-1);
}); });
}); });
...@@ -244,6 +271,7 @@ describe('Dropdown Utils', () => { ...@@ -244,6 +271,7 @@ describe('Dropdown Utils', () => {
describe('duplicateLabelPreprocessing', () => { describe('duplicateLabelPreprocessing', () => {
it('should set preprocessed to true', () => { it('should set preprocessed to true', () => {
const results = DropdownUtils.duplicateLabelPreprocessing([]); const results = DropdownUtils.duplicateLabelPreprocessing([]);
expect(results.preprocessed).toEqual(true); expect(results.preprocessed).toEqual(true);
}); });
...@@ -298,6 +326,7 @@ describe('Dropdown Utils', () => { ...@@ -298,6 +326,7 @@ describe('Dropdown Utils', () => {
}; };
DropdownUtils.setDataValueIfSelected(null, selected); DropdownUtils.setDataValueIfSelected(null, selected);
expect(FilteredSearchDropdownManager.addWordToInput.calls.count()).toEqual(1); expect(FilteredSearchDropdownManager.addWordToInput.calls.count()).toEqual(1);
}); });
...@@ -308,6 +337,7 @@ describe('Dropdown Utils', () => { ...@@ -308,6 +337,7 @@ describe('Dropdown Utils', () => {
}; };
const result = DropdownUtils.setDataValueIfSelected(null, selected); const result = DropdownUtils.setDataValueIfSelected(null, selected);
expect(result).toBe(true); expect(result).toBe(true);
}); });
...@@ -317,6 +347,7 @@ describe('Dropdown Utils', () => { ...@@ -317,6 +347,7 @@ describe('Dropdown Utils', () => {
}; };
const result = DropdownUtils.setDataValueIfSelected(null, selected); const result = DropdownUtils.setDataValueIfSelected(null, selected);
expect(result).toBe(false); expect(result).toBe(false);
}); });
}); });
......
...@@ -134,6 +134,7 @@ describe('Filtered Search Manager', function () { ...@@ -134,6 +134,7 @@ describe('Filtered Search Manager', function () {
}; };
manager.searchState(e); manager.searchState(e);
expect(FilteredSearchManager.prototype.search).not.toHaveBeenCalled(); expect(FilteredSearchManager.prototype.search).not.toHaveBeenCalled();
}); });
...@@ -149,6 +150,7 @@ describe('Filtered Search Manager', function () { ...@@ -149,6 +150,7 @@ describe('Filtered Search Manager', function () {
}; };
manager.searchState(e); manager.searchState(e);
expect(FilteredSearchManager.prototype.search).toHaveBeenCalledWith('opened'); expect(FilteredSearchManager.prototype.search).toHaveBeenCalledWith('opened');
}); });
}); });
...@@ -304,6 +306,7 @@ describe('Filtered Search Manager', function () { ...@@ -304,6 +306,7 @@ describe('Filtered Search Manager', function () {
); );
tokensContainer.querySelector('.js-visual-token .remove-token').click(); tokensContainer.querySelector('.js-visual-token .remove-token').click();
expect(tokensContainer.querySelector('.js-visual-token')).toEqual(null); expect(tokensContainer.querySelector('.js-visual-token')).toEqual(null);
}); });
...@@ -437,11 +440,13 @@ describe('Filtered Search Manager', function () { ...@@ -437,11 +440,13 @@ describe('Filtered Search Manager', function () {
it('toggles on focus', () => { it('toggles on focus', () => {
input.focus(); input.focus();
expect(document.querySelector('.filtered-search-box').classList.contains('focus')).toEqual(true); expect(document.querySelector('.filtered-search-box').classList.contains('focus')).toEqual(true);
}); });
it('toggles on blur', () => { it('toggles on blur', () => {
input.blur(); input.blur();
expect(document.querySelector('.filtered-search-box').classList.contains('focus')).toEqual(false); expect(document.querySelector('.filtered-search-box').classList.contains('focus')).toEqual(false);
}); });
}); });
......
...@@ -51,11 +51,13 @@ describe('Filtered Search Token Keys', () => { ...@@ -51,11 +51,13 @@ describe('Filtered Search Token Keys', () => {
describe('searchByKey', () => { describe('searchByKey', () => {
it('should return null when key not found', () => { it('should return null when key not found', () => {
const tokenKey = new FilteredSearchTokenKeys(tokenKeys).searchByKey('notakey'); const tokenKey = new FilteredSearchTokenKeys(tokenKeys).searchByKey('notakey');
expect(tokenKey).toBeNull(); expect(tokenKey).toBeNull();
}); });
it('should return tokenKey when found by key', () => { it('should return tokenKey when found by key', () => {
const result = new FilteredSearchTokenKeys(tokenKeys).searchByKey(tokenKeys[0].key); const result = new FilteredSearchTokenKeys(tokenKeys).searchByKey(tokenKeys[0].key);
expect(result).toEqual(tokenKeys[0]); expect(result).toEqual(tokenKeys[0]);
}); });
}); });
...@@ -63,11 +65,13 @@ describe('Filtered Search Token Keys', () => { ...@@ -63,11 +65,13 @@ describe('Filtered Search Token Keys', () => {
describe('searchBySymbol', () => { describe('searchBySymbol', () => {
it('should return null when symbol not found', () => { it('should return null when symbol not found', () => {
const tokenKey = new FilteredSearchTokenKeys(tokenKeys).searchBySymbol('notasymbol'); const tokenKey = new FilteredSearchTokenKeys(tokenKeys).searchBySymbol('notasymbol');
expect(tokenKey).toBeNull(); expect(tokenKey).toBeNull();
}); });
it('should return tokenKey when found by symbol', () => { it('should return tokenKey when found by symbol', () => {
const result = new FilteredSearchTokenKeys(tokenKeys).searchBySymbol(tokenKeys[0].symbol); const result = new FilteredSearchTokenKeys(tokenKeys).searchBySymbol(tokenKeys[0].symbol);
expect(result).toEqual(tokenKeys[0]); expect(result).toEqual(tokenKeys[0]);
}); });
}); });
...@@ -75,16 +79,19 @@ describe('Filtered Search Token Keys', () => { ...@@ -75,16 +79,19 @@ describe('Filtered Search Token Keys', () => {
describe('searchByKeyParam', () => { describe('searchByKeyParam', () => {
it('should return null when key param not found', () => { it('should return null when key param not found', () => {
const tokenKey = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam('notakeyparam'); const tokenKey = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam('notakeyparam');
expect(tokenKey).toBeNull(); expect(tokenKey).toBeNull();
}); });
it('should return tokenKey when found by key param', () => { it('should return tokenKey when found by key param', () => {
const result = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam(`${tokenKeys[0].key}_${tokenKeys[0].param}`); const result = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam(`${tokenKeys[0].key}_${tokenKeys[0].param}`);
expect(result).toEqual(tokenKeys[0]); expect(result).toEqual(tokenKeys[0]);
}); });
it('should return alternative tokenKey when found by key param', () => { it('should return alternative tokenKey when found by key param', () => {
const result = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam(`${tokenKeys[0].key}_${tokenKeys[0].param}`); const result = new FilteredSearchTokenKeys(tokenKeys).searchByKeyParam(`${tokenKeys[0].key}_${tokenKeys[0].param}`);
expect(result).toEqual(tokenKeys[0]); expect(result).toEqual(tokenKeys[0]);
}); });
}); });
...@@ -92,12 +99,14 @@ describe('Filtered Search Token Keys', () => { ...@@ -92,12 +99,14 @@ describe('Filtered Search Token Keys', () => {
describe('searchByConditionUrl', () => { describe('searchByConditionUrl', () => {
it('should return null when condition url not found', () => { it('should return null when condition url not found', () => {
const condition = new FilteredSearchTokenKeys([], [], conditions).searchByConditionUrl(null); const condition = new FilteredSearchTokenKeys([], [], conditions).searchByConditionUrl(null);
expect(condition).toBeNull(); expect(condition).toBeNull();
}); });
it('should return condition when found by url', () => { it('should return condition when found by url', () => {
const result = new FilteredSearchTokenKeys([], [], conditions) const result = new FilteredSearchTokenKeys([], [], conditions)
.searchByConditionUrl(conditions[0].url); .searchByConditionUrl(conditions[0].url);
expect(result).toBe(conditions[0]); expect(result).toBe(conditions[0]);
}); });
}); });
...@@ -106,12 +115,14 @@ describe('Filtered Search Token Keys', () => { ...@@ -106,12 +115,14 @@ describe('Filtered Search Token Keys', () => {
it('should return null when condition tokenKey and value not found', () => { it('should return null when condition tokenKey and value not found', () => {
const condition = new FilteredSearchTokenKeys([], [], conditions) const condition = new FilteredSearchTokenKeys([], [], conditions)
.searchByConditionKeyValue(null, null); .searchByConditionKeyValue(null, null);
expect(condition).toBeNull(); expect(condition).toBeNull();
}); });
it('should return condition when found by tokenKey and value', () => { it('should return condition when found by tokenKey and value', () => {
const result = new FilteredSearchTokenKeys([], [], conditions) const result = new FilteredSearchTokenKeys([], [], conditions)
.searchByConditionKeyValue(conditions[0].tokenKey, conditions[0].value); .searchByConditionKeyValue(conditions[0].tokenKey, conditions[0].value);
expect(result).toEqual(conditions[0]); expect(result).toEqual(conditions[0]);
}); });
}); });
......
...@@ -7,6 +7,7 @@ describe('Filtered Search Tokenizer', () => { ...@@ -7,6 +7,7 @@ describe('Filtered Search Tokenizer', () => {
describe('processTokens', () => { describe('processTokens', () => {
it('returns for input containing only search value', () => { it('returns for input containing only search value', () => {
const results = FilteredSearchTokenizer.processTokens('searchTerm', allowedKeys); const results = FilteredSearchTokenizer.processTokens('searchTerm', allowedKeys);
expect(results.searchToken).toBe('searchTerm'); expect(results.searchToken).toBe('searchTerm');
expect(results.tokens.length).toBe(0); expect(results.tokens.length).toBe(0);
expect(results.lastToken).toBe(results.searchToken); expect(results.lastToken).toBe(results.searchToken);
...@@ -15,6 +16,7 @@ describe('Filtered Search Tokenizer', () => { ...@@ -15,6 +16,7 @@ describe('Filtered Search Tokenizer', () => {
it('returns for input containing only tokens', () => { it('returns for input containing only tokens', () => {
const results = FilteredSearchTokenizer const results = FilteredSearchTokenizer
.processTokens('author:@root label:~"Very Important" milestone:%v1.0 assignee:none', allowedKeys); .processTokens('author:@root label:~"Very Important" milestone:%v1.0 assignee:none', allowedKeys);
expect(results.searchToken).toBe(''); expect(results.searchToken).toBe('');
expect(results.tokens.length).toBe(4); expect(results.tokens.length).toBe(4);
expect(results.tokens[3]).toBe(results.lastToken); expect(results.tokens[3]).toBe(results.lastToken);
...@@ -39,6 +41,7 @@ describe('Filtered Search Tokenizer', () => { ...@@ -39,6 +41,7 @@ describe('Filtered Search Tokenizer', () => {
it('returns for input starting with search value and ending with tokens', () => { it('returns for input starting with search value and ending with tokens', () => {
const results = FilteredSearchTokenizer const results = FilteredSearchTokenizer
.processTokens('searchTerm anotherSearchTerm milestone:none', allowedKeys); .processTokens('searchTerm anotherSearchTerm milestone:none', allowedKeys);
expect(results.searchToken).toBe('searchTerm anotherSearchTerm'); expect(results.searchToken).toBe('searchTerm anotherSearchTerm');
expect(results.tokens.length).toBe(1); expect(results.tokens.length).toBe(1);
expect(results.tokens[0]).toBe(results.lastToken); expect(results.tokens[0]).toBe(results.lastToken);
...@@ -83,6 +86,7 @@ describe('Filtered Search Tokenizer', () => { ...@@ -83,6 +86,7 @@ describe('Filtered Search Tokenizer', () => {
it('returns for input containing search value in between tokens', () => { it('returns for input containing search value in between tokens', () => {
const results = FilteredSearchTokenizer const results = FilteredSearchTokenizer
.processTokens('author:@root searchTerm assignee:none anotherSearchTerm label:~Doing', allowedKeys); .processTokens('author:@root searchTerm assignee:none anotherSearchTerm label:~Doing', allowedKeys);
expect(results.searchToken).toBe('searchTerm anotherSearchTerm'); expect(results.searchToken).toBe('searchTerm anotherSearchTerm');
expect(results.tokens.length).toBe(3); expect(results.tokens.length).toBe(3);
expect(results.tokens[2]).toBe(results.lastToken); expect(results.tokens[2]).toBe(results.lastToken);
...@@ -102,6 +106,7 @@ describe('Filtered Search Tokenizer', () => { ...@@ -102,6 +106,7 @@ describe('Filtered Search Tokenizer', () => {
it('returns search value for invalid tokens', () => { it('returns search value for invalid tokens', () => {
const results = FilteredSearchTokenizer.processTokens('fake:token', allowedKeys); const results = FilteredSearchTokenizer.processTokens('fake:token', allowedKeys);
expect(results.lastToken).toBe('fake:token'); expect(results.lastToken).toBe('fake:token');
expect(results.searchToken).toBe('fake:token'); expect(results.searchToken).toBe('fake:token');
expect(results.tokens.length).toEqual(0); expect(results.tokens.length).toEqual(0);
...@@ -109,6 +114,7 @@ describe('Filtered Search Tokenizer', () => { ...@@ -109,6 +114,7 @@ describe('Filtered Search Tokenizer', () => {
it('returns search value and token for mix of valid and invalid tokens', () => { it('returns search value and token for mix of valid and invalid tokens', () => {
const results = FilteredSearchTokenizer.processTokens('label:real fake:token', allowedKeys); const results = FilteredSearchTokenizer.processTokens('label:real fake:token', allowedKeys);
expect(results.tokens.length).toEqual(1); expect(results.tokens.length).toEqual(1);
expect(results.tokens[0].key).toBe('label'); expect(results.tokens[0].key).toBe('label');
expect(results.tokens[0].value).toBe('real'); expect(results.tokens[0].value).toBe('real');
...@@ -119,12 +125,14 @@ describe('Filtered Search Tokenizer', () => { ...@@ -119,12 +125,14 @@ describe('Filtered Search Tokenizer', () => {
it('returns search value for invalid symbols', () => { it('returns search value for invalid symbols', () => {
const results = FilteredSearchTokenizer.processTokens('std::includes', allowedKeys); const results = FilteredSearchTokenizer.processTokens('std::includes', allowedKeys);
expect(results.lastToken).toBe('std::includes'); expect(results.lastToken).toBe('std::includes');
expect(results.searchToken).toBe('std::includes'); expect(results.searchToken).toBe('std::includes');
}); });
it('removes duplicated values', () => { it('removes duplicated values', () => {
const results = FilteredSearchTokenizer.processTokens('label:~foo label:~foo', allowedKeys); const results = FilteredSearchTokenizer.processTokens('label:~foo label:~foo', allowedKeys);
expect(results.tokens.length).toBe(1); expect(results.tokens.length).toBe(1);
expect(results.tokens[0].key).toBe('label'); expect(results.tokens[0].key).toBe('label');
expect(results.tokens[0].value).toBe('foo'); expect(results.tokens[0].value).toBe('foo');
......
...@@ -131,6 +131,7 @@ describe('Filtered Search Visual Tokens', () => { ...@@ -131,6 +131,7 @@ describe('Filtered Search Visual Tokens', () => {
describe('getEndpointWithQueryParams', () => { describe('getEndpointWithQueryParams', () => {
it('returns `endpoint` string as is when second param `endpointQueryParams` is undefined, null or empty string', () => { it('returns `endpoint` string as is when second param `endpointQueryParams` is undefined, null or empty string', () => {
const endpoint = 'foo/bar/labels.json'; const endpoint = 'foo/bar/labels.json';
expect(subject.getEndpointWithQueryParams(endpoint)).toBe(endpoint); expect(subject.getEndpointWithQueryParams(endpoint)).toBe(endpoint);
expect(subject.getEndpointWithQueryParams(endpoint, null)).toBe(endpoint); expect(subject.getEndpointWithQueryParams(endpoint, null)).toBe(endpoint);
expect(subject.getEndpointWithQueryParams(endpoint, '')).toBe(endpoint); expect(subject.getEndpointWithQueryParams(endpoint, '')).toBe(endpoint);
...@@ -161,6 +162,7 @@ describe('Filtered Search Visual Tokens', () => { ...@@ -161,6 +162,7 @@ describe('Filtered Search Visual Tokens', () => {
`); `);
const selected = tokensContainer.querySelector('.js-visual-token .selected'); const selected = tokensContainer.querySelector('.js-visual-token .selected');
expect(selected.classList.contains('selected')).toEqual(true); expect(selected.classList.contains('selected')).toEqual(true);
subject.unselectTokens(); subject.unselectTokens();
...@@ -675,6 +677,7 @@ describe('Filtered Search Visual Tokens', () => { ...@@ -675,6 +677,7 @@ describe('Filtered Search Visual Tokens', () => {
subject.moveInputToTheRight(); subject.moveInputToTheRight();
const token = tokensContainer.children[1]; const token = tokensContainer.children[1];
expect(token.querySelector('.value').innerText).toEqual('~bug'); expect(token.querySelector('.value').innerText).toEqual('~bug');
}); });
}); });
...@@ -712,6 +715,7 @@ describe('Filtered Search Visual Tokens', () => { ...@@ -712,6 +715,7 @@ describe('Filtered Search Visual Tokens', () => {
expect(tokenValueElement.innerText).toBe(tokenValue); expect(tokenValueElement.innerText).toBe(tokenValue);
expect(updateUserTokenAppearanceSpy.calls.count()).toBe(1); expect(updateUserTokenAppearanceSpy.calls.count()).toBe(1);
const expectedArgs = [tokenValueContainer, tokenValueElement, tokenValue]; const expectedArgs = [tokenValueContainer, tokenValueElement, tokenValue];
expect(updateUserTokenAppearanceSpy.calls.argsFor(0)).toEqual(expectedArgs); expect(updateUserTokenAppearanceSpy.calls.argsFor(0)).toEqual(expectedArgs);
expect(updateLabelTokenColorSpy.calls.count()).toBe(0); expect(updateLabelTokenColorSpy.calls.count()).toBe(0);
}); });
...@@ -727,6 +731,7 @@ describe('Filtered Search Visual Tokens', () => { ...@@ -727,6 +731,7 @@ describe('Filtered Search Visual Tokens', () => {
expect(tokenValueElement.innerText).toBe(tokenValue); expect(tokenValueElement.innerText).toBe(tokenValue);
expect(updateLabelTokenColorSpy.calls.count()).toBe(1); expect(updateLabelTokenColorSpy.calls.count()).toBe(1);
const expectedArgs = [tokenValueContainer, tokenValue]; const expectedArgs = [tokenValueContainer, tokenValue];
expect(updateLabelTokenColorSpy.calls.argsFor(0)).toEqual(expectedArgs); expect(updateLabelTokenColorSpy.calls.argsFor(0)).toEqual(expectedArgs);
expect(updateUserTokenAppearanceSpy.calls.count()).toBe(0); expect(updateUserTokenAppearanceSpy.calls.count()).toBe(0);
}); });
...@@ -814,6 +819,7 @@ describe('Filtered Search Visual Tokens', () => { ...@@ -814,6 +819,7 @@ describe('Filtered Search Visual Tokens', () => {
expect(tokenValueContainer.dataset.originalValue).toBe(tokenValue); expect(tokenValueContainer.dataset.originalValue).toBe(tokenValue);
expect(tokenValueElement.innerText.trim()).toBe(dummyUser.name); expect(tokenValueElement.innerText.trim()).toBe(dummyUser.name);
const avatar = tokenValueElement.querySelector('img.avatar'); const avatar = tokenValueElement.querySelector('img.avatar');
expect(avatar.src).toBe(dummyUser.avatar_url); expect(avatar.src).toBe(dummyUser.avatar_url);
expect(avatar.alt).toBe(''); expect(avatar.alt).toBe('');
}) })
...@@ -837,6 +843,7 @@ describe('Filtered Search Visual Tokens', () => { ...@@ -837,6 +843,7 @@ describe('Filtered Search Visual Tokens', () => {
.then(() => { .then(() => {
expect(tokenValueElement.innerText.trim()).toBe(dummyUser.name); expect(tokenValueElement.innerText.trim()).toBe(dummyUser.name);
tokenValueElement.querySelector('.avatar').remove(); tokenValueElement.querySelector('.avatar').remove();
expect(tokenValueElement.innerHTML.trim()).toBe(_.escape(dummyUser.name)); expect(tokenValueElement.innerHTML.trim()).toBe(_.escape(dummyUser.name));
}) })
.then(done) .then(done)
...@@ -854,23 +861,27 @@ describe('Filtered Search Visual Tokens', () => { ...@@ -854,23 +861,27 @@ describe('Filtered Search Visual Tokens', () => {
it('should set backgroundColor', () => { it('should set backgroundColor', () => {
const originalBackgroundColor = bugLabelToken.style.backgroundColor; const originalBackgroundColor = bugLabelToken.style.backgroundColor;
const token = subject.setTokenStyle(bugLabelToken, 'blue', 'white'); const token = subject.setTokenStyle(bugLabelToken, 'blue', 'white');
expect(token.style.backgroundColor).toEqual('blue'); expect(token.style.backgroundColor).toEqual('blue');
expect(token.style.backgroundColor).not.toEqual(originalBackgroundColor); expect(token.style.backgroundColor).not.toEqual(originalBackgroundColor);
}); });
it('should not set backgroundColor when it is a linear-gradient', () => { it('should not set backgroundColor when it is a linear-gradient', () => {
const token = subject.setTokenStyle(bugLabelToken, 'linear-gradient(135deg, red, blue)', 'white'); const token = subject.setTokenStyle(bugLabelToken, 'linear-gradient(135deg, red, blue)', 'white');
expect(token.style.backgroundColor).toEqual(bugLabelToken.style.backgroundColor); expect(token.style.backgroundColor).toEqual(bugLabelToken.style.backgroundColor);
}); });
it('should set textColor', () => { it('should set textColor', () => {
const token = subject.setTokenStyle(bugLabelToken, 'white', 'black'); const token = subject.setTokenStyle(bugLabelToken, 'white', 'black');
expect(token.style.color).toEqual('black'); expect(token.style.color).toEqual('black');
expect(token.style.color).not.toEqual(originalTextColor); expect(token.style.color).not.toEqual(originalTextColor);
}); });
it('should add inverted class when textColor is #FFFFFF', () => { it('should add inverted class when textColor is #FFFFFF', () => {
const token = subject.setTokenStyle(bugLabelToken, 'black', '#FFFFFF'); const token = subject.setTokenStyle(bugLabelToken, 'black', '#FFFFFF');
expect(token.style.color).toEqual('rgb(255, 255, 255)'); expect(token.style.color).toEqual('rgb(255, 255, 255)');
expect(token.style.color).not.toEqual(originalTextColor); expect(token.style.color).not.toEqual(originalTextColor);
expect(token.querySelector('.remove-token').classList.contains('inverted')).toEqual(true); expect(token.querySelector('.remove-token').classList.contains('inverted')).toEqual(true);
...@@ -894,14 +905,17 @@ describe('Filtered Search Visual Tokens', () => { ...@@ -894,14 +905,17 @@ describe('Filtered Search Visual Tokens', () => {
describe('not preprocessed before', () => { describe('not preprocessed before', () => {
it('returns preprocessed labels', () => { it('returns preprocessed labels', () => {
let labels = []; let labels = [];
expect(labels.preprocessed).not.toEqual(true); expect(labels.preprocessed).not.toEqual(true);
labels = FilteredSearchVisualTokens.preprocessLabel(endpoint, labels); labels = FilteredSearchVisualTokens.preprocessLabel(endpoint, labels);
expect(labels.preprocessed).toEqual(true); expect(labels.preprocessed).toEqual(true);
}); });
it('overrides AjaxCache with preprocessed results', () => { it('overrides AjaxCache with preprocessed results', () => {
spyOn(AjaxCache, 'override').and.callFake(() => {}); spyOn(AjaxCache, 'override').and.callFake(() => {});
FilteredSearchVisualTokens.preprocessLabel(endpoint, []); FilteredSearchVisualTokens.preprocessLabel(endpoint, []);
expect(AjaxCache.override.calls.count()).toEqual(1); expect(AjaxCache.override.calls.count()).toEqual(1);
}); });
}); });
...@@ -982,6 +996,7 @@ describe('Filtered Search Visual Tokens', () => { ...@@ -982,6 +996,7 @@ describe('Filtered Search Visual Tokens', () => {
const { tokenValueContainer, tokenValueElement } = findElements(missingLabelToken); const { tokenValueContainer, tokenValueElement } = findElements(missingLabelToken);
const tokenValue = tokenValueElement.innerText; const tokenValue = tokenValueElement.innerText;
const matchingLabel = findLabel(tokenValue); const matchingLabel = findLabel(tokenValue);
expect(matchingLabel).toBe(undefined); expect(matchingLabel).toBe(undefined);
subject.updateLabelTokenColor(tokenValueContainer, tokenValue) subject.updateLabelTokenColor(tokenValueContainer, tokenValue)
......
...@@ -92,6 +92,7 @@ describe('RecentSearchesService', () => { ...@@ -92,6 +92,7 @@ describe('RecentSearchesService', () => {
const items = ['foo', 'bar']; const items = ['foo', 'bar'];
service.save(items); service.save(items);
const newLocalStorageValue = window.localStorage.getItem(service.localStorageKey); const newLocalStorageValue = window.localStorage.getItem(service.localStorageKey);
expect(JSON.parse(newLocalStorageValue)).toEqual(items); expect(JSON.parse(newLocalStorageValue)).toEqual(items);
}); });
}); });
......
...@@ -39,6 +39,7 @@ describe('Flash', () => { ...@@ -39,6 +39,7 @@ describe('Flash', () => {
expect( expect(
el.querySelector('.flash-text').classList.contains('container-fluid'), el.querySelector('.flash-text').classList.contains('container-fluid'),
).toBeTruthy(); ).toBeTruthy();
expect( expect(
el.querySelector('.flash-text').classList.contains('container-limited'), el.querySelector('.flash-text').classList.contains('container-limited'),
).toBeTruthy(); ).toBeTruthy();
...@@ -59,6 +60,7 @@ describe('Flash', () => { ...@@ -59,6 +60,7 @@ describe('Flash', () => {
expect( expect(
el.style['transition-property'], el.style['transition-property'],
).toBe('opacity'); ).toBe('opacity');
expect( expect(
el.style['transition-duration'], el.style['transition-duration'],
).toBe('0.3s'); ).toBe('0.3s');
...@@ -78,6 +80,7 @@ describe('Flash', () => { ...@@ -78,6 +80,7 @@ describe('Flash', () => {
expect( expect(
el.style.opacity, el.style.opacity,
).toBe(''); ).toBe('');
expect( expect(
el.style.transition, el.style.transition,
).toBe(''); ).toBe('');
...@@ -166,6 +169,7 @@ describe('Flash', () => { ...@@ -166,6 +169,7 @@ describe('Flash', () => {
expect( expect(
flashEl, flashEl,
).toBeNull(); ).toBeNull();
expect( expect(
document.querySelector('.flash-alert'), document.querySelector('.flash-alert'),
).toBeNull(); ).toBeNull();
......
...@@ -30,9 +30,11 @@ describe('FrequentItemsListItemComponent', () => { ...@@ -30,9 +30,11 @@ describe('FrequentItemsListItemComponent', () => {
describe('hasAvatar', () => { describe('hasAvatar', () => {
it('should return `true` or `false` if whether avatar is present or not', () => { it('should return `true` or `false` if whether avatar is present or not', () => {
vm.avatarUrl = 'path/to/avatar.png'; vm.avatarUrl = 'path/to/avatar.png';
expect(vm.hasAvatar).toBe(true); expect(vm.hasAvatar).toBe(true);
vm.avatarUrl = null; vm.avatarUrl = null;
expect(vm.hasAvatar).toBe(false); expect(vm.hasAvatar).toBe(false);
}); });
}); });
...@@ -40,11 +42,13 @@ describe('FrequentItemsListItemComponent', () => { ...@@ -40,11 +42,13 @@ describe('FrequentItemsListItemComponent', () => {
describe('highlightedItemName', () => { describe('highlightedItemName', () => {
it('should enclose part of project name in <b> & </b> which matches with `matcher` prop', () => { it('should enclose part of project name in <b> & </b> which matches with `matcher` prop', () => {
vm.matcher = 'lab'; vm.matcher = 'lab';
expect(vm.highlightedItemName).toContain('<b>Lab</b>'); expect(vm.highlightedItemName).toContain('<b>Lab</b>');
}); });
it('should return project name as it is if `matcher` is not available', () => { it('should return project name as it is if `matcher` is not available', () => {
vm.matcher = null; vm.matcher = null;
expect(vm.highlightedItemName).toBe(mockProject.name); expect(vm.highlightedItemName).toBe(mockProject.name);
}); });
}); });
...@@ -52,11 +56,13 @@ describe('FrequentItemsListItemComponent', () => { ...@@ -52,11 +56,13 @@ describe('FrequentItemsListItemComponent', () => {
describe('truncatedNamespace', () => { describe('truncatedNamespace', () => {
it('should truncate project name from namespace string', () => { it('should truncate project name from namespace string', () => {
vm.namespace = 'platform / nokia-3310'; vm.namespace = 'platform / nokia-3310';
expect(vm.truncatedNamespace).toBe('platform'); expect(vm.truncatedNamespace).toBe('platform');
}); });
it('should truncate namespace string from the middle if it includes more than two groups in path', () => { it('should truncate namespace string from the middle if it includes more than two groups in path', () => {
vm.namespace = 'platform / hardware / broadcom / Wifi Group / Mobile Chipset / nokia-3310'; vm.namespace = 'platform / hardware / broadcom / Wifi Group / Mobile Chipset / nokia-3310';
expect(vm.truncatedNamespace).toBe('platform / ... / Mobile Chipset'); expect(vm.truncatedNamespace).toBe('platform / ... / Mobile Chipset');
}); });
}); });
......
...@@ -30,9 +30,11 @@ describe('FrequentItemsListComponent', () => { ...@@ -30,9 +30,11 @@ describe('FrequentItemsListComponent', () => {
describe('isListEmpty', () => { describe('isListEmpty', () => {
it('should return `true` or `false` representing whether if `items` is empty or not with projects', () => { it('should return `true` or `false` representing whether if `items` is empty or not with projects', () => {
vm.items = []; vm.items = [];
expect(vm.isListEmpty).toBe(true); expect(vm.isListEmpty).toBe(true);
vm.items = mockFrequentProjects; vm.items = mockFrequentProjects;
expect(vm.isListEmpty).toBe(false); expect(vm.isListEmpty).toBe(false);
}); });
}); });
...@@ -40,9 +42,11 @@ describe('FrequentItemsListComponent', () => { ...@@ -40,9 +42,11 @@ describe('FrequentItemsListComponent', () => {
describe('fetched item messages', () => { describe('fetched item messages', () => {
it('should return appropriate empty list message based on value of `localStorageFailed` prop with projects', () => { it('should return appropriate empty list message based on value of `localStorageFailed` prop with projects', () => {
vm.isFetchFailed = true; vm.isFetchFailed = true;
expect(vm.listEmptyMessage).toBe('This feature requires browser localStorage support'); expect(vm.listEmptyMessage).toBe('This feature requires browser localStorage support');
vm.isFetchFailed = false; vm.isFetchFailed = false;
expect(vm.listEmptyMessage).toBe('Projects you visit often will appear here'); expect(vm.listEmptyMessage).toBe('Projects you visit often will appear here');
}); });
}); });
...@@ -51,9 +55,11 @@ describe('FrequentItemsListComponent', () => { ...@@ -51,9 +55,11 @@ describe('FrequentItemsListComponent', () => {
it('should return appropriate empty list message based on value of `searchFailed` prop with projects', () => { it('should return appropriate empty list message based on value of `searchFailed` prop with projects', () => {
vm.hasSearchQuery = true; vm.hasSearchQuery = true;
vm.isFetchFailed = true; vm.isFetchFailed = true;
expect(vm.listEmptyMessage).toBe('Something went wrong on our end.'); expect(vm.listEmptyMessage).toBe('Something went wrong on our end.');
vm.isFetchFailed = false; vm.isFetchFailed = false;
expect(vm.listEmptyMessage).toBe('Sorry, no projects matched your search'); expect(vm.listEmptyMessage).toBe('Sorry, no projects matched your search');
}); });
}); });
......
...@@ -26,6 +26,7 @@ describe('FrequentItemsSearchInputComponent', () => { ...@@ -26,6 +26,7 @@ describe('FrequentItemsSearchInputComponent', () => {
spyOn(vm.$refs.search, 'focus'); spyOn(vm.$refs.search, 'focus');
vm.setFocus(); vm.setFocus();
expect(vm.$refs.search.focus).toHaveBeenCalled(); expect(vm.$refs.search.focus).toHaveBeenCalled();
}); });
}); });
......
...@@ -70,8 +70,10 @@ describe('glDropdown', function describeDropdown() { ...@@ -70,8 +70,10 @@ describe('glDropdown', function describeDropdown() {
it('should open on click', () => { it('should open on click', () => {
initDropDown.call(this, false); initDropDown.call(this, false);
expect(this.dropdownContainerElement).not.toHaveClass('show'); expect(this.dropdownContainerElement).not.toHaveClass('show');
this.dropdownButtonElement.click(); this.dropdownButtonElement.click();
expect(this.dropdownContainerElement).toHaveClass('show'); expect(this.dropdownContainerElement).toHaveClass('show');
}); });
...@@ -141,9 +143,12 @@ describe('glDropdown', function describeDropdown() { ...@@ -141,9 +143,12 @@ describe('glDropdown', function describeDropdown() {
navigateWithKeys('enter', null, () => { navigateWithKeys('enter', null, () => {
expect(this.dropdownContainerElement).not.toHaveClass('show'); expect(this.dropdownContainerElement).not.toHaveClass('show');
const link = $(`${ITEM_SELECTOR}:eq(${randomIndex}) a`, this.$dropdownMenuElement); const link = $(`${ITEM_SELECTOR}:eq(${randomIndex}) a`, this.$dropdownMenuElement);
expect(link).toHaveClass('is-active'); expect(link).toHaveClass('is-active');
const linkedLocation = link.attr('href'); const linkedLocation = link.attr('href');
if (linkedLocation && linkedLocation !== '#') expect(visitUrl).toHaveBeenCalledWith(linkedLocation); if (linkedLocation && linkedLocation !== '#') {
expect(visitUrl).toHaveBeenCalledWith(linkedLocation);
}
}); });
}); });
}); });
...@@ -155,6 +160,7 @@ describe('glDropdown', function describeDropdown() { ...@@ -155,6 +160,7 @@ describe('glDropdown', function describeDropdown() {
which: ARROW_KEYS.ESC, which: ARROW_KEYS.ESC,
keyCode: ARROW_KEYS.ESC keyCode: ARROW_KEYS.ESC
}); });
expect(this.dropdownContainerElement).not.toHaveClass('show'); expect(this.dropdownContainerElement).not.toHaveClass('show');
}); });
}); });
...@@ -170,17 +176,20 @@ describe('glDropdown', function describeDropdown() { ...@@ -170,17 +176,20 @@ describe('glDropdown', function describeDropdown() {
expect(dropdownMenu.className.indexOf('is-loading')).not.toBe(-1); expect(dropdownMenu.className.indexOf('is-loading')).not.toBe(-1);
remoteCallback(); remoteCallback();
expect(dropdownMenu.className.indexOf('is-loading')).toBe(-1); expect(dropdownMenu.className.indexOf('is-loading')).toBe(-1);
}); });
it('should not focus search input while remote task is not complete', () => { it('should not focus search input while remote task is not complete', () => {
expect($(document.activeElement)).not.toEqual($(SEARCH_INPUT_SELECTOR)); expect($(document.activeElement)).not.toEqual($(SEARCH_INPUT_SELECTOR));
remoteCallback(); remoteCallback();
expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR)); expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR));
}); });
it('should focus search input after remote task is complete', () => { it('should focus search input after remote task is complete', () => {
remoteCallback(); remoteCallback();
expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR)); expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR));
}); });
...@@ -193,6 +202,7 @@ describe('glDropdown', function describeDropdown() { ...@@ -193,6 +202,7 @@ describe('glDropdown', function describeDropdown() {
}); });
this.dropdownButtonElement.click(); this.dropdownButtonElement.click();
this.dropdownContainerElement.trigger('transitionend'); this.dropdownContainerElement.trigger('transitionend');
expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR)); expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR));
}); });
}); });
...@@ -202,6 +212,7 @@ describe('glDropdown', function describeDropdown() { ...@@ -202,6 +212,7 @@ describe('glDropdown', function describeDropdown() {
initDropDown.call(this, false, true); initDropDown.call(this, false, true);
this.dropdownButtonElement.click(); this.dropdownButtonElement.click();
this.dropdownContainerElement.trigger('transitionend'); this.dropdownContainerElement.trigger('transitionend');
expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR)); expect($(document.activeElement)).toEqual($(SEARCH_INPUT_SELECTOR));
}); });
}); });
...@@ -213,11 +224,13 @@ describe('glDropdown', function describeDropdown() { ...@@ -213,11 +224,13 @@ describe('glDropdown', function describeDropdown() {
.trigger('focus') .trigger('focus')
.val('g') .val('g')
.trigger('input'); .trigger('input');
expect($searchInput.val()).toEqual('g'); expect($searchInput.val()).toEqual('g');
this.dropdownButtonElement.trigger('hidden.bs.dropdown'); this.dropdownButtonElement.trigger('hidden.bs.dropdown');
$searchInput $searchInput
.trigger('blur') .trigger('blur')
.trigger('focus'); .trigger('focus');
expect($searchInput.val()).toEqual('g'); expect($searchInput.val()).toEqual('g');
}); });
...@@ -240,6 +253,7 @@ describe('glDropdown', function describeDropdown() { ...@@ -240,6 +253,7 @@ describe('glDropdown', function describeDropdown() {
const html = dropdown.renderItem(dummyData, null, null); const html = dropdown.renderItem(dummyData, null, null);
const link = html.querySelector('a'); const link = html.querySelector('a');
expect(link).toHaveClass('is-active'); expect(link).toHaveClass('is-active');
}); });
...@@ -251,6 +265,7 @@ describe('glDropdown', function describeDropdown() { ...@@ -251,6 +265,7 @@ describe('glDropdown', function describeDropdown() {
const html = dropdown.renderItem(dummyData, null, null); const html = dropdown.renderItem(dummyData, null, null);
const link = html.querySelector('a'); const link = html.querySelector('a');
expect(link).not.toHaveClass('is-active'); expect(link).not.toHaveClass('is-active');
}); });
}); });
...@@ -271,10 +286,12 @@ describe('glDropdown', function describeDropdown() { ...@@ -271,10 +286,12 @@ describe('glDropdown', function describeDropdown() {
// select item the first time // select item the first time
this.dropdownButtonElement.click(); this.dropdownButtonElement.click();
$item.click(); $item.click();
expect($item).toHaveClass('is-active'); expect($item).toHaveClass('is-active');
// select item the second time // select item the second time
this.dropdownButtonElement.click(); this.dropdownButtonElement.click();
$item.click(); $item.click();
expect($item).toHaveClass('is-active'); expect($item).toHaveClass('is-active');
expect($('.dropdown-toggle-text')).toHaveText(this.projectsData[0].id.toString()); expect($('.dropdown-toggle-text')).toHaveText(this.projectsData[0].id.toString());
......
...@@ -19,6 +19,7 @@ describe('GL Style Field Errors', function() { ...@@ -19,6 +19,7 @@ describe('GL Style Field Errors', function() {
expect(this.$form.length).toBe(1); expect(this.$form.length).toBe(1);
expect(this.fieldErrors).toBeDefined(); expect(this.fieldErrors).toBeDefined();
const { inputs } = this.fieldErrors.state; const { inputs } = this.fieldErrors.state;
expect(inputs.length).toBe(4); expect(inputs.length).toBe(4);
}); });
...@@ -31,6 +32,7 @@ describe('GL Style Field Errors', function() { ...@@ -31,6 +32,7 @@ describe('GL Style Field Errors', function() {
const customErrors = this.fieldErrors.state.inputs.filter((input) => { const customErrors = this.fieldErrors.state.inputs.filter((input) => {
return input.inputElement.hasClass(customErrorFlag); return input.inputElement.hasClass(customErrorFlag);
}); });
expect(customErrors.length).toBe(0); expect(customErrors.length).toBe(0);
}); });
...@@ -40,6 +42,7 @@ describe('GL Style Field Errors', function() { ...@@ -40,6 +42,7 @@ describe('GL Style Field Errors', function() {
this.$form.find('.alphanumberic').val('?---*').keyup(); this.$form.find('.alphanumberic').val('?---*').keyup();
const errorsShown = this.$form.find('.gl-field-error-outline'); const errorsShown = this.$form.find('.gl-field-error-outline');
expect(errorsShown.length).toBe(0); expect(errorsShown.length).toBe(0);
}); });
...@@ -51,6 +54,7 @@ describe('GL Style Field Errors', function() { ...@@ -51,6 +54,7 @@ describe('GL Style Field Errors', function() {
this.$form.submit(); this.$form.submit();
const errorsShown = this.$form.find('.gl-field-error-outline'); const errorsShown = this.$form.find('.gl-field-error-outline');
expect(errorsShown.length).toBe(4); expect(errorsShown.length).toBe(4);
}); });
...@@ -68,30 +72,35 @@ describe('GL Style Field Errors', function() { ...@@ -68,30 +72,35 @@ describe('GL Style Field Errors', function() {
// Then invalid input // Then invalid input
emailInputElement.val('not-a-valid-email').keyup(); emailInputElement.val('not-a-valid-email').keyup();
expect(emailInputElement).toHaveClass('gl-field-error-outline'); expect(emailInputElement).toHaveClass('gl-field-error-outline');
expect(fieldState.empty).toBe(false); expect(fieldState.empty).toBe(false);
expect(fieldState.valid).toBe(false); expect(fieldState.valid).toBe(false);
// Then valid input // Then valid input
emailInputElement.val('email@gitlab.com').keyup(); emailInputElement.val('email@gitlab.com').keyup();
expect(emailInputElement).not.toHaveClass('gl-field-error-outline'); expect(emailInputElement).not.toHaveClass('gl-field-error-outline');
expect(fieldState.empty).toBe(false); expect(fieldState.empty).toBe(false);
expect(fieldState.valid).toBe(true); expect(fieldState.valid).toBe(true);
// Then invalid input // Then invalid input
emailInputElement.val('not-a-valid-email').keyup(); emailInputElement.val('not-a-valid-email').keyup();
expect(emailInputElement).toHaveClass('gl-field-error-outline'); expect(emailInputElement).toHaveClass('gl-field-error-outline');
expect(fieldState.empty).toBe(false); expect(fieldState.empty).toBe(false);
expect(fieldState.valid).toBe(false); expect(fieldState.valid).toBe(false);
// Then empty input // Then empty input
emailInputElement.val('').keyup(); emailInputElement.val('').keyup();
expect(emailInputElement).toHaveClass('gl-field-error-outline'); expect(emailInputElement).toHaveClass('gl-field-error-outline');
expect(fieldState.empty).toBe(true); expect(fieldState.empty).toBe(true);
expect(fieldState.valid).toBe(false); expect(fieldState.valid).toBe(false);
// Then valid input // Then valid input
emailInputElement.val('email@gitlab.com').keyup(); emailInputElement.val('email@gitlab.com').keyup();
expect(emailInputElement).not.toHaveClass('gl-field-error-outline'); expect(emailInputElement).not.toHaveClass('gl-field-error-outline');
expect(fieldState.empty).toBe(false); expect(fieldState.empty).toBe(false);
expect(fieldState.valid).toBe(true); expect(fieldState.valid).toBe(true);
......
...@@ -101,6 +101,7 @@ describe('GLForm', () => { ...@@ -101,6 +101,7 @@ describe('GLForm', () => {
spyOn($.prototype, 'outerHeight').and.returnValue(200); spyOn($.prototype, 'outerHeight').and.returnValue(200);
spyOn($.prototype, 'data').and.returnValue(200); spyOn($.prototype, 'data').and.returnValue(200);
spyOn(autosize, 'destroy'); spyOn(autosize, 'destroy');
expect(this.glForm.destroyAutosize()).toBeUndefined(); expect(this.glForm.destroyAutosize()).toBeUndefined();
expect(autosize.destroy).not.toHaveBeenCalled(); expect(autosize.destroy).not.toHaveBeenCalled();
}); });
......
...@@ -69,6 +69,7 @@ describe('GpgBadges', () => { ...@@ -69,6 +69,7 @@ describe('GpgBadges', () => {
.then(() => { .then(() => {
expect(document.querySelector('.js-loading-gpg-badge:empty')).toBe(null); expect(document.querySelector('.js-loading-gpg-badge:empty')).toBe(null);
const spinners = document.querySelectorAll('.js-loading-gpg-badge i.fa.fa-spinner.fa-spin'); const spinners = document.querySelectorAll('.js-loading-gpg-badge i.fa.fa-spinner.fa-spin');
expect(spinners.length).toBe(1); expect(spinners.length).toBe(1);
done(); done();
}) })
...@@ -82,6 +83,7 @@ describe('GpgBadges', () => { ...@@ -82,6 +83,7 @@ describe('GpgBadges', () => {
.then(() => { .then(() => {
expect(document.querySelector('.js-loading-gpg-badge')).toBe(null); expect(document.querySelector('.js-loading-gpg-badge')).toBe(null);
const parentContainer = document.querySelector('.parent-container'); const parentContainer = document.querySelector('.parent-container');
expect(parentContainer.innerHTML.trim()).toEqual(dummyBadgeHtml); expect(parentContainer.innerHTML.trim()).toEqual(dummyBadgeHtml);
done(); done();
}) })
......
...@@ -10,6 +10,7 @@ describe("ContributorsGraph", function () { ...@@ -10,6 +10,7 @@ describe("ContributorsGraph", function () {
describe("#set_x_domain", function () { describe("#set_x_domain", function () {
it("set the x_domain", function () { it("set the x_domain", function () {
ContributorsGraph.set_x_domain(20); ContributorsGraph.set_x_domain(20);
expect(ContributorsGraph.prototype.x_domain).toEqual(20); expect(ContributorsGraph.prototype.x_domain).toEqual(20);
}); });
}); });
...@@ -17,6 +18,7 @@ describe("ContributorsGraph", function () { ...@@ -17,6 +18,7 @@ describe("ContributorsGraph", function () {
describe("#set_y_domain", function () { describe("#set_y_domain", function () {
it("sets the y_domain", function () { it("sets the y_domain", function () {
ContributorsGraph.set_y_domain([{ commits: 30 }]); ContributorsGraph.set_y_domain([{ commits: 30 }]);
expect(ContributorsGraph.prototype.y_domain).toEqual([0, 30]); expect(ContributorsGraph.prototype.y_domain).toEqual([0, 30]);
}); });
}); });
...@@ -24,6 +26,7 @@ describe("ContributorsGraph", function () { ...@@ -24,6 +26,7 @@ describe("ContributorsGraph", function () {
describe("#init_x_domain", function () { describe("#init_x_domain", function () {
it("sets the initial x_domain", function () { it("sets the initial x_domain", function () {
ContributorsGraph.init_x_domain([{ date: "2013-01-31" }, { date: "2012-01-31" }]); ContributorsGraph.init_x_domain([{ date: "2013-01-31" }, { date: "2012-01-31" }]);
expect(ContributorsGraph.prototype.x_domain).toEqual(["2012-01-31", "2013-01-31"]); expect(ContributorsGraph.prototype.x_domain).toEqual(["2012-01-31", "2013-01-31"]);
}); });
}); });
...@@ -31,6 +34,7 @@ describe("ContributorsGraph", function () { ...@@ -31,6 +34,7 @@ describe("ContributorsGraph", function () {
describe("#init_y_domain", function () { describe("#init_y_domain", function () {
it("sets the initial y_domain", function () { it("sets the initial y_domain", function () {
ContributorsGraph.init_y_domain([{ commits: 30 }]); ContributorsGraph.init_y_domain([{ commits: 30 }]);
expect(ContributorsGraph.prototype.y_domain).toEqual([0, 30]); expect(ContributorsGraph.prototype.y_domain).toEqual([0, 30]);
}); });
}); });
...@@ -40,6 +44,7 @@ describe("ContributorsGraph", function () { ...@@ -40,6 +44,7 @@ describe("ContributorsGraph", function () {
spyOn(ContributorsGraph, "init_x_domain"); spyOn(ContributorsGraph, "init_x_domain");
spyOn(ContributorsGraph, "init_y_domain"); spyOn(ContributorsGraph, "init_y_domain");
ContributorsGraph.init_domain(); ContributorsGraph.init_domain();
expect(ContributorsGraph.init_x_domain).toHaveBeenCalled(); expect(ContributorsGraph.init_x_domain).toHaveBeenCalled();
expect(ContributorsGraph.init_y_domain).toHaveBeenCalled(); expect(ContributorsGraph.init_y_domain).toHaveBeenCalled();
}); });
...@@ -48,6 +53,7 @@ describe("ContributorsGraph", function () { ...@@ -48,6 +53,7 @@ describe("ContributorsGraph", function () {
describe("#set_dates", function () { describe("#set_dates", function () {
it("sets the dates", function () { it("sets the dates", function () {
ContributorsGraph.set_dates("2013-12-01"); ContributorsGraph.set_dates("2013-12-01");
expect(ContributorsGraph.prototype.dates).toEqual("2013-12-01"); expect(ContributorsGraph.prototype.dates).toEqual("2013-12-01");
}); });
}); });
...@@ -59,6 +65,7 @@ describe("ContributorsGraph", function () { ...@@ -59,6 +65,7 @@ describe("ContributorsGraph", function () {
instance.x = d3.scaleTime().range([0, 100]).clamp(true); instance.x = d3.scaleTime().range([0, 100]).clamp(true);
spyOn(instance.x, 'domain'); spyOn(instance.x, 'domain');
instance.set_x_domain(); instance.set_x_domain();
expect(instance.x.domain).toHaveBeenCalledWith(20); expect(instance.x.domain).toHaveBeenCalledWith(20);
}); });
}); });
...@@ -70,6 +77,7 @@ describe("ContributorsGraph", function () { ...@@ -70,6 +77,7 @@ describe("ContributorsGraph", function () {
instance.y = d3.scaleLinear().range([100, 0]).nice(); instance.y = d3.scaleLinear().range([100, 0]).nice();
spyOn(instance.y, 'domain'); spyOn(instance.y, 'domain');
instance.set_y_domain(); instance.set_y_domain();
expect(instance.y.domain).toHaveBeenCalledWith(30); expect(instance.y.domain).toHaveBeenCalledWith(30);
}); });
}); });
...@@ -80,6 +88,7 @@ describe("ContributorsGraph", function () { ...@@ -80,6 +88,7 @@ describe("ContributorsGraph", function () {
spyOn(instance, 'set_x_domain'); spyOn(instance, 'set_x_domain');
spyOn(instance, 'set_y_domain'); spyOn(instance, 'set_y_domain');
instance.set_domain(); instance.set_domain();
expect(instance.set_x_domain).toHaveBeenCalled(); expect(instance.set_x_domain).toHaveBeenCalled();
expect(instance.set_y_domain).toHaveBeenCalled(); expect(instance.set_y_domain).toHaveBeenCalled();
}); });
...@@ -89,6 +98,7 @@ describe("ContributorsGraph", function () { ...@@ -89,6 +98,7 @@ describe("ContributorsGraph", function () {
it("sets the data", function () { it("sets the data", function () {
var instance = new ContributorsGraph(); var instance = new ContributorsGraph();
instance.set_data("20"); instance.set_data("20");
expect(instance.data).toEqual("20"); expect(instance.data).toEqual("20");
}); });
}); });
...@@ -114,6 +124,7 @@ describe("ContributorsMasterGraph", function () { ...@@ -114,6 +124,7 @@ describe("ContributorsMasterGraph", function () {
it("plucks the date field from data collection", function () { it("plucks the date field from data collection", function () {
var graph = new ContributorsMasterGraph(); var graph = new ContributorsMasterGraph();
var data = [{ date: "2013-01-01" }, { date: "2012-12-15" }]; var data = [{ date: "2013-01-01" }, { date: "2012-12-15" }];
expect(graph.get_dates(data)).toEqual(["2013-01-01", "2012-12-15"]); expect(graph.get_dates(data)).toEqual(["2013-01-01", "2012-12-15"]);
}); });
}); });
...@@ -125,6 +136,7 @@ describe("ContributorsMasterGraph", function () { ...@@ -125,6 +136,7 @@ describe("ContributorsMasterGraph", function () {
var data = [{ date: "2013-01-01" }, { date: "2012-12-15" }]; var data = [{ date: "2013-01-01" }, { date: "2012-12-15" }];
var correct = [{ date: parseDate(data[0].date) }, { date: parseDate(data[1].date) }]; var correct = [{ date: parseDate(data[0].date) }, { date: parseDate(data[1].date) }];
graph.parse_dates(data); graph.parse_dates(data);
expect(data).toEqual(correct); expect(data).toEqual(correct);
}); });
}); });
......
...@@ -28,6 +28,7 @@ describe("ContributorsStatGraphUtil", function () { ...@@ -28,6 +28,7 @@ describe("ContributorsStatGraphUtil", function () {
} }
] ]
}; };
expect(ContributorsStatGraphUtil.parse_log(fake_log)).toEqual(correct_parsed_log); expect(ContributorsStatGraphUtil.parse_log(fake_log)).toEqual(correct_parsed_log);
}); });
}); });
...@@ -40,18 +41,21 @@ describe("ContributorsStatGraphUtil", function () { ...@@ -40,18 +41,21 @@ describe("ContributorsStatGraphUtil", function () {
it("calls #store_commits", function () { it("calls #store_commits", function () {
spyOn(ContributorsStatGraphUtil, 'store_commits'); spyOn(ContributorsStatGraphUtil, 'store_commits');
ContributorsStatGraphUtil.store_data(fake_entry, fake_total, fake_by_author); ContributorsStatGraphUtil.store_data(fake_entry, fake_total, fake_by_author);
expect(ContributorsStatGraphUtil.store_commits).toHaveBeenCalled(); expect(ContributorsStatGraphUtil.store_commits).toHaveBeenCalled();
}); });
it("calls #store_additions", function () { it("calls #store_additions", function () {
spyOn(ContributorsStatGraphUtil, 'store_additions'); spyOn(ContributorsStatGraphUtil, 'store_additions');
ContributorsStatGraphUtil.store_data(fake_entry, fake_total, fake_by_author); ContributorsStatGraphUtil.store_data(fake_entry, fake_total, fake_by_author);
expect(ContributorsStatGraphUtil.store_additions).toHaveBeenCalled(); expect(ContributorsStatGraphUtil.store_additions).toHaveBeenCalled();
}); });
it("calls #store_deletions", function () { it("calls #store_deletions", function () {
spyOn(ContributorsStatGraphUtil, 'store_deletions'); spyOn(ContributorsStatGraphUtil, 'store_deletions');
ContributorsStatGraphUtil.store_data(fake_entry, fake_total, fake_by_author); ContributorsStatGraphUtil.store_data(fake_entry, fake_total, fake_by_author);
expect(ContributorsStatGraphUtil.store_deletions).toHaveBeenCalled(); expect(ContributorsStatGraphUtil.store_deletions).toHaveBeenCalled();
}); });
}); });
...@@ -72,12 +76,14 @@ describe("ContributorsStatGraphUtil", function () { ...@@ -72,12 +76,14 @@ describe("ContributorsStatGraphUtil", function () {
it("adds 1 to current test_field in collection", function () { it("adds 1 to current test_field in collection", function () {
var fake_collection = { test_field: 10 }; var fake_collection = { test_field: 10 };
ContributorsStatGraphUtil.add(fake_collection, "test_field", 1); ContributorsStatGraphUtil.add(fake_collection, "test_field", 1);
expect(fake_collection.test_field).toEqual(11); expect(fake_collection.test_field).toEqual(11);
}); });
it("inits and adds 1 if test_field in collection is not defined", function () { it("inits and adds 1 if test_field in collection is not defined", function () {
var fake_collection = {}; var fake_collection = {};
ContributorsStatGraphUtil.add(fake_collection, "test_field", 1); ContributorsStatGraphUtil.add(fake_collection, "test_field", 1);
expect(fake_collection.test_field).toEqual(1); expect(fake_collection.test_field).toEqual(1);
}); });
}); });
...@@ -111,6 +117,7 @@ describe("ContributorsStatGraphUtil", function () { ...@@ -111,6 +117,7 @@ describe("ContributorsStatGraphUtil", function () {
var fake_date = "2013-10-02"; var fake_date = "2013-10-02";
var fake_collection = {}; var fake_collection = {};
ContributorsStatGraphUtil.add_date(fake_date, fake_collection); ContributorsStatGraphUtil.add_date(fake_date, fake_collection);
expect(fake_collection[fake_date].date).toEqual("2013-10-02"); expect(fake_collection[fake_date].date).toEqual("2013-10-02");
}); });
}); });
...@@ -121,6 +128,7 @@ describe("ContributorsStatGraphUtil", function () { ...@@ -121,6 +128,7 @@ describe("ContributorsStatGraphUtil", function () {
var fake_author_collection = {}; var fake_author_collection = {};
var fake_email_collection = {}; var fake_email_collection = {};
ContributorsStatGraphUtil.add_author(fake_author, fake_author_collection, fake_email_collection); ContributorsStatGraphUtil.add_author(fake_author, fake_author_collection, fake_email_collection);
expect(fake_author_collection[fake_author.author_name].author_name).toEqual("Author"); expect(fake_author_collection[fake_author.author_name].author_name).toEqual("Author");
expect(fake_email_collection[fake_author.author_email].author_name).toEqual("Author"); expect(fake_email_collection[fake_author.author_email].author_name).toEqual("Author");
}); });
...@@ -148,6 +156,7 @@ describe("ContributorsStatGraphUtil", function () { ...@@ -148,6 +156,7 @@ describe("ContributorsStatGraphUtil", function () {
{ date: "2013-05-08", commits: 3 }, { date: "2013-05-08", commits: 3 },
{ date: "2013-05-09", commits: 1 } { date: "2013-05-09", commits: 1 }
]; ];
expect(ContributorsStatGraphUtil.get_total_data(fake_parsed_log, "commits")).toEqual(correct_total_data); expect(ContributorsStatGraphUtil.get_total_data(fake_parsed_log, "commits")).toEqual(correct_total_data);
}); });
}); });
...@@ -160,6 +169,7 @@ describe("ContributorsStatGraphUtil", function () { ...@@ -160,6 +169,7 @@ describe("ContributorsStatGraphUtil", function () {
]; ];
ContributorsStatGraphUtil.pick_field(fake_parsed_log_total, "commits"); ContributorsStatGraphUtil.pick_field(fake_parsed_log_total, "commits");
var correct_pick_field_data = [{ date: "2013-05-09", commits: 1 }, { date: "2013-05-08", commits: 3 }]; var correct_pick_field_data = [{ date: "2013-05-09", commits: 1 }, { date: "2013-05-08", commits: 3 }];
expect(ContributorsStatGraphUtil.pick_field(fake_parsed_log_total, "commits")).toEqual(correct_pick_field_data); expect(ContributorsStatGraphUtil.pick_field(fake_parsed_log_total, "commits")).toEqual(correct_pick_field_data);
}); });
}); });
...@@ -186,6 +196,7 @@ describe("ContributorsStatGraphUtil", function () { ...@@ -186,6 +196,7 @@ describe("ContributorsStatGraphUtil", function () {
{ author_name: "Dmitriy Zaporozhets", author_email: "dzaporozhets@email.com", dates: { "2013-05-08": 3 }, deletions: 7, additions: 54, "commits": 3 }, { author_name: "Dmitriy Zaporozhets", author_email: "dzaporozhets@email.com", dates: { "2013-05-08": 3 }, deletions: 7, additions: 54, "commits": 3 },
{ author_name: "Karlo Soriano", author_email: "karlo@email.com", dates: { "2013-05-09": 1 }, deletions: 0, additions: 471, commits: 1 } { author_name: "Karlo Soriano", author_email: "karlo@email.com", dates: { "2013-05-09": 1 }, deletions: 0, additions: 471, commits: 1 }
]; ];
expect(ContributorsStatGraphUtil.get_author_data(fake_parsed_log, "commits")).toEqual(correct_author_data); expect(ContributorsStatGraphUtil.get_author_data(fake_parsed_log, "commits")).toEqual(correct_author_data);
}); });
}); });
...@@ -196,6 +207,7 @@ describe("ContributorsStatGraphUtil", function () { ...@@ -196,6 +207,7 @@ describe("ContributorsStatGraphUtil", function () {
"2013-05-09": { date: "2013-05-09", additions: 471, deletions: 0, commits: 1 } "2013-05-09": { date: "2013-05-09", additions: 471, deletions: 0, commits: 1 }
}; };
var correct_parsed_log = { author_name: "Karlo Soriano", author_email: "karlo@email.com", dates: { "2013-05-09": 1 }, deletions: 0, additions: 471, commits: 1 }; var correct_parsed_log = { author_name: "Karlo Soriano", author_email: "karlo@email.com", dates: { "2013-05-09": 1 }, deletions: 0, additions: 471, commits: 1 };
expect(ContributorsStatGraphUtil.parse_log_entry(fake_log_entry, 'commits', null)).toEqual(correct_parsed_log); expect(ContributorsStatGraphUtil.parse_log_entry(fake_log_entry, 'commits', null)).toEqual(correct_parsed_log);
}); });
}); });
...@@ -208,11 +220,13 @@ describe("ContributorsStatGraphUtil", function () { ...@@ -208,11 +220,13 @@ describe("ContributorsStatGraphUtil", function () {
it("returns true if date is in range", function () { it("returns true if date is in range", function () {
var date_range = [new Date("2013-01-01"), new Date("2013-12-12")]; var date_range = [new Date("2013-01-01"), new Date("2013-12-12")];
expect(ContributorsStatGraphUtil.in_range(date, date_range)).toEqual(true); expect(ContributorsStatGraphUtil.in_range(date, date_range)).toEqual(true);
}); });
it("returns false if date is not in range", function () { it("returns false if date is not in range", function () {
var date_range = [new Date("1999-12-01"), new Date("2000-12-01")]; var date_range = [new Date("1999-12-01"), new Date("2000-12-01")];
expect(ContributorsStatGraphUtil.in_range(date, date_range)).toEqual(false); expect(ContributorsStatGraphUtil.in_range(date, date_range)).toEqual(false);
}); });
}); });
......
...@@ -76,6 +76,7 @@ describe('AppComponent', () => { ...@@ -76,6 +76,7 @@ describe('AppComponent', () => {
spyOn(vm.store, 'getGroups'); spyOn(vm.store, 'getGroups');
const { groups } = vm; const { groups } = vm;
expect(vm.store.getGroups).toHaveBeenCalled(); expect(vm.store.getGroups).toHaveBeenCalled();
expect(groups).not.toBeDefined(); expect(groups).not.toBeDefined();
}); });
...@@ -86,6 +87,7 @@ describe('AppComponent', () => { ...@@ -86,6 +87,7 @@ describe('AppComponent', () => {
spyOn(vm.store, 'getPaginationInfo'); spyOn(vm.store, 'getPaginationInfo');
const { pageInfo } = vm; const { pageInfo } = vm;
expect(vm.store.getPaginationInfo).toHaveBeenCalled(); expect(vm.store.getPaginationInfo).toHaveBeenCalled();
expect(pageInfo).not.toBeDefined(); expect(pageInfo).not.toBeDefined();
}); });
...@@ -154,6 +156,7 @@ describe('AppComponent', () => { ...@@ -154,6 +156,7 @@ describe('AppComponent', () => {
spyOn(vm, 'updateGroups').and.callThrough(); spyOn(vm, 'updateGroups').and.callThrough();
vm.fetchAllGroups(); vm.fetchAllGroups();
expect(vm.isLoading).toBe(true); expect(vm.isLoading).toBe(true);
expect(vm.fetchGroups).toHaveBeenCalled(); expect(vm.fetchGroups).toHaveBeenCalled();
setTimeout(() => { setTimeout(() => {
...@@ -168,6 +171,7 @@ describe('AppComponent', () => { ...@@ -168,6 +171,7 @@ describe('AppComponent', () => {
spyOn(vm, 'updateGroups').and.callThrough(); spyOn(vm, 'updateGroups').and.callThrough();
vm.fetchAllGroups(); vm.fetchAllGroups();
expect(vm.fetchGroups).toHaveBeenCalledWith({ expect(vm.fetchGroups).toHaveBeenCalledWith({
page: null, page: null,
filterGroupsBy: null, filterGroupsBy: null,
...@@ -191,6 +195,7 @@ describe('AppComponent', () => { ...@@ -191,6 +195,7 @@ describe('AppComponent', () => {
spyOn($, 'scrollTo'); spyOn($, 'scrollTo');
vm.fetchPage(2, null, null, true); vm.fetchPage(2, null, null, true);
expect(vm.isLoading).toBe(true); expect(vm.isLoading).toBe(true);
expect(vm.fetchGroups).toHaveBeenCalledWith({ expect(vm.fetchGroups).toHaveBeenCalledWith({
page: 2, page: 2,
...@@ -210,6 +215,7 @@ describe('AppComponent', () => { ...@@ -210,6 +215,7 @@ describe('AppComponent', () => {
jasmine.any(String), jasmine.any(String),
jasmine.any(String), jasmine.any(String),
); );
expect(vm.updateGroups).toHaveBeenCalled(); expect(vm.updateGroups).toHaveBeenCalled();
done(); done();
}, 0); }, 0);
...@@ -230,6 +236,7 @@ describe('AppComponent', () => { ...@@ -230,6 +236,7 @@ describe('AppComponent', () => {
spyOn(vm.store, 'setGroupChildren'); spyOn(vm.store, 'setGroupChildren');
vm.toggleChildren(groupItem); vm.toggleChildren(groupItem);
expect(groupItem.isChildrenLoading).toBe(true); expect(groupItem.isChildrenLoading).toBe(true);
expect(vm.fetchGroups).toHaveBeenCalledWith({ expect(vm.fetchGroups).toHaveBeenCalledWith({
parentId: groupItem.id, parentId: groupItem.id,
...@@ -245,6 +252,7 @@ describe('AppComponent', () => { ...@@ -245,6 +252,7 @@ describe('AppComponent', () => {
groupItem.children = mockRawChildren; groupItem.children = mockRawChildren;
vm.toggleChildren(groupItem); vm.toggleChildren(groupItem);
expect(vm.fetchGroups).not.toHaveBeenCalled(); expect(vm.fetchGroups).not.toHaveBeenCalled();
expect(groupItem.isOpen).toBe(true); expect(groupItem.isOpen).toBe(true);
}); });
...@@ -254,6 +262,7 @@ describe('AppComponent', () => { ...@@ -254,6 +262,7 @@ describe('AppComponent', () => {
groupItem.isOpen = true; groupItem.isOpen = true;
vm.toggleChildren(groupItem); vm.toggleChildren(groupItem);
expect(vm.fetchGroups).not.toHaveBeenCalled(); expect(vm.fetchGroups).not.toHaveBeenCalled();
expect(groupItem.isOpen).toBe(false); expect(groupItem.isOpen).toBe(false);
}); });
...@@ -262,6 +271,7 @@ describe('AppComponent', () => { ...@@ -262,6 +271,7 @@ describe('AppComponent', () => {
spyOn(vm, 'fetchGroups').and.returnValue(returnServicePromise({}, true)); spyOn(vm, 'fetchGroups').and.returnValue(returnServicePromise({}, true));
vm.toggleChildren(groupItem); vm.toggleChildren(groupItem);
expect(groupItem.isChildrenLoading).toBe(true); expect(groupItem.isChildrenLoading).toBe(true);
setTimeout(() => { setTimeout(() => {
expect(groupItem.isChildrenLoading).toBe(false); expect(groupItem.isChildrenLoading).toBe(false);
...@@ -273,18 +283,22 @@ describe('AppComponent', () => { ...@@ -273,18 +283,22 @@ describe('AppComponent', () => {
describe('showLeaveGroupModal', () => { describe('showLeaveGroupModal', () => {
it('caches candidate group (as props) which is to be left', () => { it('caches candidate group (as props) which is to be left', () => {
const group = Object.assign({}, mockParentGroupItem); const group = Object.assign({}, mockParentGroupItem);
expect(vm.targetGroup).toBe(null); expect(vm.targetGroup).toBe(null);
expect(vm.targetParentGroup).toBe(null); expect(vm.targetParentGroup).toBe(null);
vm.showLeaveGroupModal(group, mockParentGroupItem); vm.showLeaveGroupModal(group, mockParentGroupItem);
expect(vm.targetGroup).not.toBe(null); expect(vm.targetGroup).not.toBe(null);
expect(vm.targetParentGroup).not.toBe(null); expect(vm.targetParentGroup).not.toBe(null);
}); });
it('updates props which show modal confirmation dialog', () => { it('updates props which show modal confirmation dialog', () => {
const group = Object.assign({}, mockParentGroupItem); const group = Object.assign({}, mockParentGroupItem);
expect(vm.showModal).toBe(false); expect(vm.showModal).toBe(false);
expect(vm.groupLeaveConfirmationMessage).toBe(''); expect(vm.groupLeaveConfirmationMessage).toBe('');
vm.showLeaveGroupModal(group, mockParentGroupItem); vm.showLeaveGroupModal(group, mockParentGroupItem);
expect(vm.showModal).toBe(true); expect(vm.showModal).toBe(true);
expect(vm.groupLeaveConfirmationMessage).toBe( expect(vm.groupLeaveConfirmationMessage).toBe(
`Are you sure you want to leave the "${group.fullName}" group?`, `Are you sure you want to leave the "${group.fullName}" group?`,
...@@ -296,8 +310,10 @@ describe('AppComponent', () => { ...@@ -296,8 +310,10 @@ describe('AppComponent', () => {
it('hides modal confirmation which is shown before leaving the group', () => { it('hides modal confirmation which is shown before leaving the group', () => {
const group = Object.assign({}, mockParentGroupItem); const group = Object.assign({}, mockParentGroupItem);
vm.showLeaveGroupModal(group, mockParentGroupItem); vm.showLeaveGroupModal(group, mockParentGroupItem);
expect(vm.showModal).toBe(true); expect(vm.showModal).toBe(true);
vm.hideLeaveGroupModal(); vm.hideLeaveGroupModal();
expect(vm.showModal).toBe(false); expect(vm.showModal).toBe(false);
}); });
}); });
...@@ -323,6 +339,7 @@ describe('AppComponent', () => { ...@@ -323,6 +339,7 @@ describe('AppComponent', () => {
spyOn($, 'scrollTo'); spyOn($, 'scrollTo');
vm.leaveGroup(); vm.leaveGroup();
expect(vm.showModal).toBe(false); expect(vm.showModal).toBe(false);
expect(vm.targetGroup.isBeingRemoved).toBe(true); expect(vm.targetGroup.isBeingRemoved).toBe(true);
expect(vm.service.leaveGroup).toHaveBeenCalledWith(vm.targetGroup.leavePath); expect(vm.service.leaveGroup).toHaveBeenCalledWith(vm.targetGroup.leavePath);
...@@ -343,6 +360,7 @@ describe('AppComponent', () => { ...@@ -343,6 +360,7 @@ describe('AppComponent', () => {
spyOn(window, 'Flash'); spyOn(window, 'Flash');
vm.leaveGroup(); vm.leaveGroup();
expect(vm.targetGroup.isBeingRemoved).toBe(true); expect(vm.targetGroup.isBeingRemoved).toBe(true);
expect(vm.service.leaveGroup).toHaveBeenCalledWith(childGroupItem.leavePath); expect(vm.service.leaveGroup).toHaveBeenCalledWith(childGroupItem.leavePath);
setTimeout(() => { setTimeout(() => {
...@@ -362,6 +380,7 @@ describe('AppComponent', () => { ...@@ -362,6 +380,7 @@ describe('AppComponent', () => {
spyOn(window, 'Flash'); spyOn(window, 'Flash');
vm.leaveGroup(childGroupItem, groupItem); vm.leaveGroup(childGroupItem, groupItem);
expect(vm.targetGroup.isBeingRemoved).toBe(true); expect(vm.targetGroup.isBeingRemoved).toBe(true);
expect(vm.service.leaveGroup).toHaveBeenCalledWith(childGroupItem.leavePath); expect(vm.service.leaveGroup).toHaveBeenCalledWith(childGroupItem.leavePath);
setTimeout(() => { setTimeout(() => {
...@@ -378,6 +397,7 @@ describe('AppComponent', () => { ...@@ -378,6 +397,7 @@ describe('AppComponent', () => {
spyOn(vm.store, 'setPaginationInfo'); spyOn(vm.store, 'setPaginationInfo');
vm.updatePagination(mockRawPageInfo); vm.updatePagination(mockRawPageInfo);
expect(vm.store.setPaginationInfo).toHaveBeenCalledWith(mockRawPageInfo); expect(vm.store.setPaginationInfo).toHaveBeenCalledWith(mockRawPageInfo);
}); });
}); });
...@@ -387,6 +407,7 @@ describe('AppComponent', () => { ...@@ -387,6 +407,7 @@ describe('AppComponent', () => {
spyOn(vm.store, 'setGroups'); spyOn(vm.store, 'setGroups');
vm.updateGroups(mockGroups); vm.updateGroups(mockGroups);
expect(vm.store.setGroups).toHaveBeenCalledWith(mockGroups); expect(vm.store.setGroups).toHaveBeenCalledWith(mockGroups);
}); });
...@@ -394,14 +415,17 @@ describe('AppComponent', () => { ...@@ -394,14 +415,17 @@ describe('AppComponent', () => {
spyOn(vm.store, 'setSearchedGroups'); spyOn(vm.store, 'setSearchedGroups');
vm.updateGroups(mockGroups, true); vm.updateGroups(mockGroups, true);
expect(vm.store.setSearchedGroups).toHaveBeenCalledWith(mockGroups); expect(vm.store.setSearchedGroups).toHaveBeenCalledWith(mockGroups);
}); });
it('should set `isSearchEmpty` prop based on groups count', () => { it('should set `isSearchEmpty` prop based on groups count', () => {
vm.updateGroups(mockGroups); vm.updateGroups(mockGroups);
expect(vm.isSearchEmpty).toBe(false); expect(vm.isSearchEmpty).toBe(false);
vm.updateGroups([]); vm.updateGroups([]);
expect(vm.isSearchEmpty).toBe(true); expect(vm.isSearchEmpty).toBe(true);
}); });
}); });
...@@ -497,6 +521,7 @@ describe('AppComponent', () => { ...@@ -497,6 +521,7 @@ describe('AppComponent', () => {
vm.showModal = true; vm.showModal = true;
Vue.nextTick(() => { Vue.nextTick(() => {
const modalDialogEl = vm.$el.querySelector('.modal'); const modalDialogEl = vm.$el.querySelector('.modal');
expect(modalDialogEl).not.toBe(null); expect(modalDialogEl).not.toBe(null);
expect(modalDialogEl.querySelector('.modal-title').innerText.trim()).toBe('Are you sure?'); expect(modalDialogEl.querySelector('.modal-title').innerText.trim()).toBe('Are you sure?');
expect(modalDialogEl.querySelector('.btn.btn-warning').innerText.trim()).toBe('Leave'); expect(modalDialogEl.querySelector('.btn.btn-warning').innerText.trim()).toBe('Leave');
......
...@@ -59,6 +59,7 @@ describe('GroupFolderComponent', () => { ...@@ -59,6 +59,7 @@ describe('GroupFolderComponent', () => {
const newVm = createComponent(mockGroups, parentGroup); const newVm = createComponent(mockGroups, parentGroup);
newVm.$mount(); newVm.$mount();
expect(newVm.$el.querySelector('li.group-row a.has-more-items')).toBeDefined(); expect(newVm.$el.querySelector('li.group-row a.has-more-items')).toBeDefined();
newVm.$destroy(); newVm.$destroy();
}); });
......
...@@ -57,11 +57,13 @@ describe('GroupItemComponent', () => { ...@@ -57,11 +57,13 @@ describe('GroupItemComponent', () => {
group.childrenCount = 5; group.childrenCount = 5;
newVm = createComponent(group); newVm = createComponent(group);
expect(newVm.hasChildren).toBeTruthy(); expect(newVm.hasChildren).toBeTruthy();
newVm.$destroy(); newVm.$destroy();
group.childrenCount = 0; group.childrenCount = 0;
newVm = createComponent(group); newVm = createComponent(group);
expect(newVm.hasChildren).toBeFalsy(); expect(newVm.hasChildren).toBeFalsy();
newVm.$destroy(); newVm.$destroy();
}); });
...@@ -74,11 +76,13 @@ describe('GroupItemComponent', () => { ...@@ -74,11 +76,13 @@ describe('GroupItemComponent', () => {
group.avatarUrl = null; group.avatarUrl = null;
newVm = createComponent(group); newVm = createComponent(group);
expect(newVm.hasAvatar).toBeFalsy(); expect(newVm.hasAvatar).toBeFalsy();
newVm.$destroy(); newVm.$destroy();
group.avatarUrl = '/uploads/group_avatar.png'; group.avatarUrl = '/uploads/group_avatar.png';
newVm = createComponent(group); newVm = createComponent(group);
expect(newVm.hasAvatar).toBeTruthy(); expect(newVm.hasAvatar).toBeTruthy();
newVm.$destroy(); newVm.$destroy();
}); });
...@@ -91,11 +95,13 @@ describe('GroupItemComponent', () => { ...@@ -91,11 +95,13 @@ describe('GroupItemComponent', () => {
group.type = 'group'; group.type = 'group';
newVm = createComponent(group); newVm = createComponent(group);
expect(newVm.isGroup).toBeTruthy(); expect(newVm.isGroup).toBeTruthy();
newVm.$destroy(); newVm.$destroy();
group.type = 'project'; group.type = 'project';
newVm = createComponent(group); newVm = createComponent(group);
expect(newVm.isGroup).toBeFalsy(); expect(newVm.isGroup).toBeFalsy();
newVm.$destroy(); newVm.$destroy();
}); });
...@@ -127,6 +133,7 @@ describe('GroupItemComponent', () => { ...@@ -127,6 +133,7 @@ describe('GroupItemComponent', () => {
spyOn(eventHub, '$emit'); spyOn(eventHub, '$emit');
vm.onClickRowGroup(event); vm.onClickRowGroup(event);
expect(eventHub.$emit).toHaveBeenCalledWith('toggleChildren', vm.group); expect(eventHub.$emit).toHaveBeenCalledWith('toggleChildren', vm.group);
}); });
......
...@@ -42,6 +42,7 @@ describe('GroupsComponent', () => { ...@@ -42,6 +42,7 @@ describe('GroupsComponent', () => {
spyOn(eventHub, '$emit').and.stub(); spyOn(eventHub, '$emit').and.stub();
vm.change(2); vm.change(2);
expect(eventHub.$emit).toHaveBeenCalledWith('fetchPage', 2, jasmine.any(Object), jasmine.any(Object), jasmine.any(Object)); expect(eventHub.$emit).toHaveBeenCalledWith('fetchPage', 2, jasmine.any(Object), jasmine.any(Object), jasmine.any(Object));
}); });
}); });
......
...@@ -30,6 +30,7 @@ describe('ItemActionsComponent', () => { ...@@ -30,6 +30,7 @@ describe('ItemActionsComponent', () => {
it('emits `showLeaveGroupModal` event with `group` and `parentGroup` props', () => { it('emits `showLeaveGroupModal` event with `group` and `parentGroup` props', () => {
spyOn(eventHub, '$emit'); spyOn(eventHub, '$emit');
vm.onLeaveGroup(); vm.onLeaveGroup();
expect(eventHub.$emit).toHaveBeenCalledWith('showLeaveGroupModal', vm.group, vm.parentGroup); expect(eventHub.$emit).toHaveBeenCalledWith('showLeaveGroupModal', vm.group, vm.parentGroup);
}); });
}); });
...@@ -46,6 +47,7 @@ describe('ItemActionsComponent', () => { ...@@ -46,6 +47,7 @@ describe('ItemActionsComponent', () => {
const newVm = createComponent(group); const newVm = createComponent(group);
const editBtn = newVm.$el.querySelector('a.edit-group'); const editBtn = newVm.$el.querySelector('a.edit-group');
expect(editBtn).toBeDefined(); expect(editBtn).toBeDefined();
expect(editBtn.classList.contains('no-expand')).toBeTruthy(); expect(editBtn.classList.contains('no-expand')).toBeTruthy();
expect(editBtn.getAttribute('href')).toBe(group.editPath); expect(editBtn.getAttribute('href')).toBe(group.editPath);
...@@ -63,6 +65,7 @@ describe('ItemActionsComponent', () => { ...@@ -63,6 +65,7 @@ describe('ItemActionsComponent', () => {
const newVm = createComponent(group); const newVm = createComponent(group);
const leaveBtn = newVm.$el.querySelector('a.leave-group'); const leaveBtn = newVm.$el.querySelector('a.leave-group');
expect(leaveBtn).toBeDefined(); expect(leaveBtn).toBeDefined();
expect(leaveBtn.classList.contains('no-expand')).toBeTruthy(); expect(leaveBtn.classList.contains('no-expand')).toBeTruthy();
expect(leaveBtn.getAttribute('href')).toBe(group.leavePath); expect(leaveBtn.getAttribute('href')).toBe(group.leavePath);
......
...@@ -16,6 +16,7 @@ describe('ItemCaretComponent', () => { ...@@ -16,6 +16,7 @@ describe('ItemCaretComponent', () => {
describe('template', () => { describe('template', () => {
it('should render component template correctly', () => { it('should render component template correctly', () => {
const vm = createComponent(); const vm = createComponent();
expect(vm.$el.classList.contains('folder-caret')).toBeTruthy(); expect(vm.$el.classList.contains('folder-caret')).toBeTruthy();
expect(vm.$el.querySelectorAll('svg').length).toBe(1); expect(vm.$el.querySelectorAll('svg').length).toBe(1);
vm.$destroy(); vm.$destroy();
...@@ -23,12 +24,14 @@ describe('ItemCaretComponent', () => { ...@@ -23,12 +24,14 @@ describe('ItemCaretComponent', () => {
it('should render caret down icon if `isGroupOpen` prop is `true`', () => { it('should render caret down icon if `isGroupOpen` prop is `true`', () => {
const vm = createComponent(true); const vm = createComponent(true);
expect(vm.$el.querySelector('svg use').getAttribute('xlink:href')).toContain('angle-down'); expect(vm.$el.querySelector('svg use').getAttribute('xlink:href')).toContain('angle-down');
vm.$destroy(); vm.$destroy();
}); });
it('should render caret right icon if `isGroupOpen` prop is `false`', () => { it('should render caret right icon if `isGroupOpen` prop is `false`', () => {
const vm = createComponent(); const vm = createComponent();
expect(vm.$el.querySelector('svg use').getAttribute('xlink:href')).toContain('angle-right'); expect(vm.$el.querySelector('svg use').getAttribute('xlink:href')).toContain('angle-right');
vm.$destroy(); vm.$destroy();
}); });
......
...@@ -25,6 +25,7 @@ describe('ItemStatsComponent', () => { ...@@ -25,6 +25,7 @@ describe('ItemStatsComponent', () => {
Object.keys(VISIBILITY_TYPE_ICON).forEach((visibility) => { Object.keys(VISIBILITY_TYPE_ICON).forEach((visibility) => {
const item = Object.assign({}, mockParentGroupItem, { visibility }); const item = Object.assign({}, mockParentGroupItem, { visibility });
const vm = createComponent(item); const vm = createComponent(item);
expect(vm.visibilityIcon).toBe(VISIBILITY_TYPE_ICON[visibility]); expect(vm.visibilityIcon).toBe(VISIBILITY_TYPE_ICON[visibility]);
vm.$destroy(); vm.$destroy();
}); });
...@@ -39,6 +40,7 @@ describe('ItemStatsComponent', () => { ...@@ -39,6 +40,7 @@ describe('ItemStatsComponent', () => {
type: ITEM_TYPE.GROUP, type: ITEM_TYPE.GROUP,
}); });
const vm = createComponent(item); const vm = createComponent(item);
expect(vm.visibilityTooltip).toBe(GROUP_VISIBILITY_TYPE[visibility]); expect(vm.visibilityTooltip).toBe(GROUP_VISIBILITY_TYPE[visibility]);
vm.$destroy(); vm.$destroy();
}); });
...@@ -51,6 +53,7 @@ describe('ItemStatsComponent', () => { ...@@ -51,6 +53,7 @@ describe('ItemStatsComponent', () => {
type: ITEM_TYPE.PROJECT, type: ITEM_TYPE.PROJECT,
}); });
const vm = createComponent(item); const vm = createComponent(item);
expect(vm.visibilityTooltip).toBe(PROJECT_VISIBILITY_TYPE[visibility]); expect(vm.visibilityTooltip).toBe(PROJECT_VISIBILITY_TYPE[visibility]);
vm.$destroy(); vm.$destroy();
}); });
...@@ -64,11 +67,13 @@ describe('ItemStatsComponent', () => { ...@@ -64,11 +67,13 @@ describe('ItemStatsComponent', () => {
item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.PROJECT }); item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.PROJECT });
vm = createComponent(item); vm = createComponent(item);
expect(vm.isProject).toBeTruthy(); expect(vm.isProject).toBeTruthy();
vm.$destroy(); vm.$destroy();
item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.GROUP }); item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.GROUP });
vm = createComponent(item); vm = createComponent(item);
expect(vm.isProject).toBeFalsy(); expect(vm.isProject).toBeFalsy();
vm.$destroy(); vm.$destroy();
}); });
...@@ -81,11 +86,13 @@ describe('ItemStatsComponent', () => { ...@@ -81,11 +86,13 @@ describe('ItemStatsComponent', () => {
item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.GROUP }); item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.GROUP });
vm = createComponent(item); vm = createComponent(item);
expect(vm.isGroup).toBeTruthy(); expect(vm.isGroup).toBeTruthy();
vm.$destroy(); vm.$destroy();
item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.PROJECT }); item = Object.assign({}, mockParentGroupItem, { type: ITEM_TYPE.PROJECT });
vm = createComponent(item); vm = createComponent(item);
expect(vm.isGroup).toBeFalsy(); expect(vm.isGroup).toBeFalsy();
vm.$destroy(); vm.$destroy();
}); });
...@@ -105,6 +112,7 @@ describe('ItemStatsComponent', () => { ...@@ -105,6 +112,7 @@ describe('ItemStatsComponent', () => {
const vm = createComponent(); const vm = createComponent();
const visibilityIconEl = vm.$el.querySelector('.item-visibility'); const visibilityIconEl = vm.$el.querySelector('.item-visibility');
expect(visibilityIconEl).not.toBe(null); expect(visibilityIconEl).not.toBe(null);
expect(visibilityIconEl.dataset.originalTitle).toBe(vm.visibilityTooltip); expect(visibilityIconEl.dataset.originalTitle).toBe(vm.visibilityTooltip);
expect(visibilityIconEl.querySelectorAll('svg').length).toBeGreaterThan(0); expect(visibilityIconEl.querySelectorAll('svg').length).toBeGreaterThan(0);
...@@ -120,6 +128,7 @@ describe('ItemStatsComponent', () => { ...@@ -120,6 +128,7 @@ describe('ItemStatsComponent', () => {
const vm = createComponent(item); const vm = createComponent(item);
const projectStarIconEl = vm.$el.querySelector('.project-stars'); const projectStarIconEl = vm.$el.querySelector('.project-stars');
expect(projectStarIconEl).not.toBeNull(); expect(projectStarIconEl).not.toBeNull();
expect(projectStarIconEl.querySelectorAll('svg').length).toBeGreaterThan(0); expect(projectStarIconEl.querySelectorAll('svg').length).toBeGreaterThan(0);
expect(projectStarIconEl.querySelectorAll('.stat-value').length).toBeGreaterThan(0); expect(projectStarIconEl.querySelectorAll('.stat-value').length).toBeGreaterThan(0);
......
...@@ -29,11 +29,13 @@ describe('ItemStatsValueComponent', () => { ...@@ -29,11 +29,13 @@ describe('ItemStatsValueComponent', () => {
describe('isValuePresent', () => { describe('isValuePresent', () => {
it('returns true if non-empty `value` is present', () => { it('returns true if non-empty `value` is present', () => {
vm = createComponent(Object.assign({}, itemConfig, { value: 10 })); vm = createComponent(Object.assign({}, itemConfig, { value: 10 }));
expect(vm.isValuePresent).toBeTruthy(); expect(vm.isValuePresent).toBeTruthy();
}); });
it('returns false if empty `value` is present', () => { it('returns false if empty `value` is present', () => {
vm = createComponent(itemConfig); vm = createComponent(itemConfig);
expect(vm.isValuePresent).toBeFalsy(); expect(vm.isValuePresent).toBeFalsy();
}); });
......
...@@ -18,6 +18,7 @@ describe('ItemTypeIconComponent', () => { ...@@ -18,6 +18,7 @@ describe('ItemTypeIconComponent', () => {
it('should render component template correctly', () => { it('should render component template correctly', () => {
const vm = createComponent(); const vm = createComponent();
vm.$mount(); vm.$mount();
expect(vm.$el.classList.contains('item-type-icon')).toBeTruthy(); expect(vm.$el.classList.contains('item-type-icon')).toBeTruthy();
vm.$destroy(); vm.$destroy();
}); });
...@@ -27,11 +28,13 @@ describe('ItemTypeIconComponent', () => { ...@@ -27,11 +28,13 @@ describe('ItemTypeIconComponent', () => {
vm = createComponent(ITEM_TYPE.GROUP, true); vm = createComponent(ITEM_TYPE.GROUP, true);
vm.$mount(); vm.$mount();
expect(vm.$el.querySelector('use').getAttribute('xlink:href')).toContain('folder-open'); expect(vm.$el.querySelector('use').getAttribute('xlink:href')).toContain('folder-open');
vm.$destroy(); vm.$destroy();
vm = createComponent(ITEM_TYPE.GROUP); vm = createComponent(ITEM_TYPE.GROUP);
vm.$mount(); vm.$mount();
expect(vm.$el.querySelector('use').getAttribute('xlink:href')).toContain('folder'); expect(vm.$el.querySelector('use').getAttribute('xlink:href')).toContain('folder');
vm.$destroy(); vm.$destroy();
}); });
...@@ -41,11 +44,13 @@ describe('ItemTypeIconComponent', () => { ...@@ -41,11 +44,13 @@ describe('ItemTypeIconComponent', () => {
vm = createComponent(ITEM_TYPE.PROJECT); vm = createComponent(ITEM_TYPE.PROJECT);
vm.$mount(); vm.$mount();
expect(vm.$el.querySelector('use').getAttribute('xlink:href')).toContain('bookmark'); expect(vm.$el.querySelector('use').getAttribute('xlink:href')).toContain('bookmark');
vm.$destroy(); vm.$destroy();
vm = createComponent(ITEM_TYPE.GROUP); vm = createComponent(ITEM_TYPE.GROUP);
vm.$mount(); vm.$mount();
expect(vm.$el.querySelector('use').getAttribute('xlink:href')).not.toContain('bookmark'); expect(vm.$el.querySelector('use').getAttribute('xlink:href')).not.toContain('bookmark');
vm.$destroy(); vm.$destroy();
}); });
......
...@@ -24,9 +24,11 @@ describe('GroupsService', () => { ...@@ -24,9 +24,11 @@ describe('GroupsService', () => {
}; };
service.getGroups(55, 2, 'git', 'created_asc', true); service.getGroups(55, 2, 'git', 'created_asc', true);
expect(service.groups.get).toHaveBeenCalledWith({ parent_id: 55 }); expect(service.groups.get).toHaveBeenCalledWith({ parent_id: 55 });
service.getGroups(null, 2, 'git', 'created_asc', true); service.getGroups(null, 2, 'git', 'created_asc', true);
expect(service.groups.get).toHaveBeenCalledWith(queryParams); expect(service.groups.get).toHaveBeenCalledWith(queryParams);
}); });
}); });
...@@ -36,6 +38,7 @@ describe('GroupsService', () => { ...@@ -36,6 +38,7 @@ describe('GroupsService', () => {
spyOn(Vue.http, 'delete').and.stub(); spyOn(Vue.http, 'delete').and.stub();
service.leaveGroup(mockParentGroupItem.leavePath); service.leaveGroup(mockParentGroupItem.leavePath);
expect(Vue.http.delete).toHaveBeenCalledWith(mockParentGroupItem.leavePath); expect(Vue.http.delete).toHaveBeenCalledWith(mockParentGroupItem.leavePath);
}); });
}); });
......
...@@ -11,12 +11,14 @@ describe('ProjectsStore', () => { ...@@ -11,12 +11,14 @@ describe('ProjectsStore', () => {
let store; let store;
store = new GroupsStore(); store = new GroupsStore();
expect(Object.keys(store.state).length).toBe(2); expect(Object.keys(store.state).length).toBe(2);
expect(Array.isArray(store.state.groups)).toBeTruthy(); expect(Array.isArray(store.state.groups)).toBeTruthy();
expect(Object.keys(store.state.pageInfo).length).toBe(0); expect(Object.keys(store.state.pageInfo).length).toBe(0);
expect(store.hideProjects).not.toBeDefined(); expect(store.hideProjects).not.toBeDefined();
store = new GroupsStore(true); store = new GroupsStore(true);
expect(store.hideProjects).toBeTruthy(); expect(store.hideProjects).toBeTruthy();
}); });
}); });
...@@ -27,6 +29,7 @@ describe('ProjectsStore', () => { ...@@ -27,6 +29,7 @@ describe('ProjectsStore', () => {
spyOn(store, 'formatGroupItem').and.callThrough(); spyOn(store, 'formatGroupItem').and.callThrough();
store.setGroups(mockGroups); store.setGroups(mockGroups);
expect(store.state.groups.length).toBe(mockGroups.length); expect(store.state.groups.length).toBe(mockGroups.length);
expect(store.formatGroupItem).toHaveBeenCalledWith(jasmine.any(Object)); expect(store.formatGroupItem).toHaveBeenCalledWith(jasmine.any(Object));
expect(Object.keys(store.state.groups[0]).indexOf('fullName')).toBeGreaterThan(-1); expect(Object.keys(store.state.groups[0]).indexOf('fullName')).toBeGreaterThan(-1);
...@@ -39,6 +42,7 @@ describe('ProjectsStore', () => { ...@@ -39,6 +42,7 @@ describe('ProjectsStore', () => {
spyOn(store, 'formatGroupItem').and.callThrough(); spyOn(store, 'formatGroupItem').and.callThrough();
store.setSearchedGroups(mockSearchedGroups); store.setSearchedGroups(mockSearchedGroups);
expect(store.state.groups.length).toBe(mockSearchedGroups.length); expect(store.state.groups.length).toBe(mockSearchedGroups.length);
expect(store.formatGroupItem).toHaveBeenCalledWith(jasmine.any(Object)); expect(store.formatGroupItem).toHaveBeenCalledWith(jasmine.any(Object));
expect(Object.keys(store.state.groups[0]).indexOf('fullName')).toBeGreaterThan(-1); expect(Object.keys(store.state.groups[0]).indexOf('fullName')).toBeGreaterThan(-1);
...@@ -52,6 +56,7 @@ describe('ProjectsStore', () => { ...@@ -52,6 +56,7 @@ describe('ProjectsStore', () => {
spyOn(store, 'formatGroupItem').and.callThrough(); spyOn(store, 'formatGroupItem').and.callThrough();
store.setGroupChildren(mockParentGroupItem, mockRawChildren); store.setGroupChildren(mockParentGroupItem, mockRawChildren);
expect(store.formatGroupItem).toHaveBeenCalledWith(jasmine.any(Object)); expect(store.formatGroupItem).toHaveBeenCalledWith(jasmine.any(Object));
expect(mockParentGroupItem.children.length).toBe(1); expect(mockParentGroupItem.children.length).toBe(1);
expect(Object.keys(mockParentGroupItem.children[0]).indexOf('fullName')).toBeGreaterThan(-1); expect(Object.keys(mockParentGroupItem.children[0]).indexOf('fullName')).toBeGreaterThan(-1);
...@@ -65,6 +70,7 @@ describe('ProjectsStore', () => { ...@@ -65,6 +70,7 @@ describe('ProjectsStore', () => {
const store = new GroupsStore(); const store = new GroupsStore();
store.setPaginationInfo(mockRawPageInfo); store.setPaginationInfo(mockRawPageInfo);
expect(store.state.pageInfo.perPage).toBe(10); expect(store.state.pageInfo.perPage).toBe(10);
expect(store.state.pageInfo.page).toBe(10); expect(store.state.pageInfo.page).toBe(10);
expect(store.state.pageInfo.total).toBe(10); expect(store.state.pageInfo.total).toBe(10);
...@@ -81,6 +87,7 @@ describe('ProjectsStore', () => { ...@@ -81,6 +87,7 @@ describe('ProjectsStore', () => {
store = new GroupsStore(); store = new GroupsStore();
updatedGroupItem = store.formatGroupItem(mockRawChildren[0]); updatedGroupItem = store.formatGroupItem(mockRawChildren[0]);
expect(Object.keys(updatedGroupItem).indexOf('fullName')).toBeGreaterThan(-1); expect(Object.keys(updatedGroupItem).indexOf('fullName')).toBeGreaterThan(-1);
expect(updatedGroupItem.childrenCount).toBe(mockRawChildren[0].children_count); expect(updatedGroupItem.childrenCount).toBe(mockRawChildren[0].children_count);
expect(updatedGroupItem.isChildrenLoading).toBe(false); expect(updatedGroupItem.isChildrenLoading).toBe(false);
...@@ -88,6 +95,7 @@ describe('ProjectsStore', () => { ...@@ -88,6 +95,7 @@ describe('ProjectsStore', () => {
store = new GroupsStore(true); store = new GroupsStore(true);
updatedGroupItem = store.formatGroupItem(mockRawChildren[0]); updatedGroupItem = store.formatGroupItem(mockRawChildren[0]);
expect(Object.keys(updatedGroupItem).indexOf('fullName')).toBeGreaterThan(-1); expect(Object.keys(updatedGroupItem).indexOf('fullName')).toBeGreaterThan(-1);
expect(updatedGroupItem.childrenCount).toBe(mockRawChildren[0].subgroup_count); expect(updatedGroupItem.childrenCount).toBe(mockRawChildren[0].subgroup_count);
}); });
...@@ -104,6 +112,7 @@ describe('ProjectsStore', () => { ...@@ -104,6 +112,7 @@ describe('ProjectsStore', () => {
const childItem = store.state.groups[0].children[0]; const childItem = store.state.groups[0].children[0];
store.removeGroup(childItem, store.state.groups[0]); store.removeGroup(childItem, store.state.groups[0]);
expect(store.state.groups[0].children.length).toBe(0); expect(store.state.groups[0].children.length).toBe(0);
}); });
}); });
......
...@@ -21,16 +21,19 @@ describe('Header', function () { ...@@ -21,16 +21,19 @@ describe('Header', function () {
it('should update todos-count after receiving the todo:toggle event', () => { it('should update todos-count after receiving the todo:toggle event', () => {
triggerToggle('5'); triggerToggle('5');
expect($(todosPendingCount).text()).toEqual('5'); expect($(todosPendingCount).text()).toEqual('5');
}); });
it('should hide todos-count when it is 0', () => { it('should hide todos-count when it is 0', () => {
triggerToggle('0'); triggerToggle('0');
expect(isTodosCountHidden()).toEqual(true); expect(isTodosCountHidden()).toEqual(true);
}); });
it('should show todos-count when it is more than 0', () => { it('should show todos-count when it is more than 0', () => {
triggerToggle('10'); triggerToggle('10');
expect(isTodosCountHidden()).toEqual(false); expect(isTodosCountHidden()).toEqual(false);
}); });
......
...@@ -29,6 +29,7 @@ describe('IDE branch item', () => { ...@@ -29,6 +29,7 @@ describe('IDE branch item', () => {
it('renders branch name and timeago', () => { it('renders branch name and timeago', () => {
const timeText = getTimeago().format(TEST_BRANCH.committedDate); const timeText = getTimeago().format(TEST_BRANCH.committedDate);
expect(vm.$el).toContainText(TEST_BRANCH.name); expect(vm.$el).toContainText(TEST_BRANCH.name);
expect(vm.$el.querySelector('time')).toHaveText(timeText); expect(vm.$el.querySelector('time')).toHaveText(timeText);
expect(vm.$el.querySelector('.ic-mobile-issue-close')).toBe(null); expect(vm.$el.querySelector('.ic-mobile-issue-close')).toBe(null);
...@@ -36,6 +37,7 @@ describe('IDE branch item', () => { ...@@ -36,6 +37,7 @@ describe('IDE branch item', () => {
it('renders link to branch', () => { it('renders link to branch', () => {
const expectedHref = router.resolve(`/project/${TEST_PROJECT_ID}/edit/${TEST_BRANCH.name}`).href; const expectedHref = router.resolve(`/project/${TEST_PROJECT_ID}/edit/${TEST_BRANCH.name}`).href;
expect(vm.$el).toMatch('a'); expect(vm.$el).toMatch('a');
expect(vm.$el).toHaveAttr('href', expectedHref); expect(vm.$el).toHaveAttr('href', expectedHref);
}); });
......
...@@ -76,6 +76,7 @@ describe('IDE commit message field', () => { ...@@ -76,6 +76,7 @@ describe('IDE commit message field', () => {
expect(vm.$el.querySelector('.highlights span').textContent).toContain( expect(vm.$el.querySelector('.highlights span').textContent).toContain(
'text less than 50 chars', 'text less than 50 chars',
); );
expect(vm.$el.querySelector('mark').style.display).toBe('none'); expect(vm.$el.querySelector('mark').style.display).toBe('none');
}) })
.then(done) .then(done)
...@@ -92,6 +93,7 @@ describe('IDE commit message field', () => { ...@@ -92,6 +93,7 @@ describe('IDE commit message field', () => {
expect(vm.$el.querySelector('.highlights span').textContent).toContain( expect(vm.$el.querySelector('.highlights span').textContent).toContain(
'text less than 50 chars that should not highlighte', 'text less than 50 chars that should not highlighte',
); );
expect(vm.$el.querySelector('mark').style.display).not.toBe('none'); expect(vm.$el.querySelector('mark').style.display).not.toBe('none');
expect(vm.$el.querySelector('mark').textContent).toBe( expect(vm.$el.querySelector('mark').textContent).toBe(
'd. text more than 50 should be highlighted', 'd. text more than 50 should be highlighted',
......
...@@ -50,9 +50,11 @@ describe('ideStatusBar', () => { ...@@ -50,9 +50,11 @@ describe('ideStatusBar', () => {
expect(vm.commitAgeUpdate).not.toHaveBeenCalled(); expect(vm.commitAgeUpdate).not.toHaveBeenCalled();
jasmine.clock().tick(1100); jasmine.clock().tick(1100);
expect(vm.commitAgeUpdate.calls.count()).toEqual(1); expect(vm.commitAgeUpdate.calls.count()).toEqual(1);
jasmine.clock().tick(1000); jasmine.clock().tick(1000);
expect(vm.commitAgeUpdate.calls.count()).toEqual(2); expect(vm.commitAgeUpdate.calls.count()).toEqual(2);
}); });
}); });
......
...@@ -30,6 +30,7 @@ describe('IDE merge request item', () => { ...@@ -30,6 +30,7 @@ describe('IDE merge request item', () => {
it('renders link with href', () => { it('renders link with href', () => {
const expectedHref = router.resolve(`/project/${vm.item.projectPathWithNamespace}/merge_requests/${vm.item.iid}`).href; const expectedHref = router.resolve(`/project/${vm.item.projectPathWithNamespace}/merge_requests/${vm.item.iid}`).href;
expect(vm.$el).toMatch('a'); expect(vm.$el).toMatch('a');
expect(vm.$el).toHaveAttr('href', expectedHref); expect(vm.$el).toHaveAttr('href', expectedHref);
}); });
......
...@@ -36,6 +36,7 @@ describe('new dropdown component', () => { ...@@ -36,6 +36,7 @@ describe('new dropdown component', () => {
it('renders new file, upload and new directory links', () => { it('renders new file, upload and new directory links', () => {
const buttons = vm.$el.querySelectorAll('.dropdown-menu button'); const buttons = vm.$el.querySelectorAll('.dropdown-menu button');
expect(buttons[0].textContent.trim()).toBe('New file'); expect(buttons[0].textContent.trim()).toBe('New file');
expect(buttons[1].textContent.trim()).toBe('Upload file'); expect(buttons[1].textContent.trim()).toBe('Upload file');
expect(buttons[2].textContent.trim()).toBe('New directory'); expect(buttons[2].textContent.trim()).toBe('New directory');
......
...@@ -52,6 +52,7 @@ describe('RepoEditor', () => { ...@@ -52,6 +52,7 @@ describe('RepoEditor', () => {
it('renders only an edit tab', done => { it('renders only an edit tab', done => {
Vue.nextTick(() => { Vue.nextTick(() => {
const tabs = vm.$el.querySelectorAll('.ide-mode-tabs .nav-links li'); const tabs = vm.$el.querySelectorAll('.ide-mode-tabs .nav-links li');
expect(tabs.length).toBe(1); expect(tabs.length).toBe(1);
expect(tabs[0].textContent.trim()).toBe('Edit'); expect(tabs[0].textContent.trim()).toBe('Edit');
...@@ -72,6 +73,7 @@ describe('RepoEditor', () => { ...@@ -72,6 +73,7 @@ describe('RepoEditor', () => {
it('renders an Edit and a Preview Tab', done => { it('renders an Edit and a Preview Tab', done => {
Vue.nextTick(() => { Vue.nextTick(() => {
const tabs = vm.$el.querySelectorAll('.ide-mode-tabs .nav-links li'); const tabs = vm.$el.querySelectorAll('.ide-mode-tabs .nav-links li');
expect(tabs.length).toBe(2); expect(tabs.length).toBe(2);
expect(tabs[0].textContent.trim()).toBe('Edit'); expect(tabs[0].textContent.trim()).toBe('Edit');
expect(tabs[1].textContent.trim()).toBe('Preview Markdown'); expect(tabs[1].textContent.trim()).toBe('Preview Markdown');
...@@ -109,6 +111,7 @@ describe('RepoEditor', () => { ...@@ -109,6 +111,7 @@ describe('RepoEditor', () => {
it('renders an Edit and a Preview Tab', done => { it('renders an Edit and a Preview Tab', done => {
Vue.nextTick(() => { Vue.nextTick(() => {
const tabs = vm.$el.querySelectorAll('.ide-mode-tabs .nav-links li'); const tabs = vm.$el.querySelectorAll('.ide-mode-tabs .nav-links li');
expect(tabs.length).toBe(2); expect(tabs.length).toBe(2);
expect(tabs[0].textContent.trim()).toBe('Review'); expect(tabs[0].textContent.trim()).toBe('Review');
expect(tabs[1].textContent.trim()).toBe('Preview Markdown'); expect(tabs[1].textContent.trim()).toBe('Preview Markdown');
......
...@@ -85,10 +85,12 @@ describe('IDE shared/TokenedInput', () => { ...@@ -85,10 +85,12 @@ describe('IDE shared/TokenedInput', () => {
vm.value = ''; vm.value = '';
vm.onBackspace(); vm.onBackspace();
expect(vm.$emit).not.toHaveBeenCalled(); expect(vm.$emit).not.toHaveBeenCalled();
expect(vm.backspaceCount).toEqual(1); expect(vm.backspaceCount).toEqual(1);
vm.onBackspace(); vm.onBackspace();
expect(vm.$emit).toHaveBeenCalledWith('removeToken', TEST_TOKENS[TEST_TOKENS.length - 1]); expect(vm.$emit).toHaveBeenCalledWith('removeToken', TEST_TOKENS[TEST_TOKENS.length - 1]);
expect(vm.backspaceCount).toEqual(0); expect(vm.backspaceCount).toEqual(0);
}); });
......
...@@ -311,6 +311,7 @@ describe('IDE store merge request actions', () => { ...@@ -311,6 +311,7 @@ describe('IDE store merge request actions', () => {
file: store.state.entries[change.new_path], file: store.state.entries[change.new_path],
mrChange: change, mrChange: change,
}); });
expect(store.dispatch).toHaveBeenCalledWith('getFileData', { expect(store.dispatch).toHaveBeenCalledWith('getFileData', {
path: change.new_path, path: change.new_path,
makeFileActive: i === 0, makeFileActive: i === 0,
......
...@@ -71,6 +71,7 @@ describe('Multi-file store tree actions', () => { ...@@ -71,6 +71,7 @@ describe('Multi-file store tree actions', () => {
.dispatch('getFiles', basicCallParameters) .dispatch('getFiles', basicCallParameters)
.then(() => { .then(() => {
projectTree = store.state.trees['abcproject/master']; projectTree = store.state.trees['abcproject/master'];
expect(projectTree.tree.length).toBe(2); expect(projectTree.tree.length).toBe(2);
expect(projectTree.tree[0].type).toBe('tree'); expect(projectTree.tree[0].type).toBe('tree');
expect(projectTree.tree[0].tree[1].name).toBe('fileinfolder.js'); expect(projectTree.tree[0].tree[1].name).toBe('fileinfolder.js');
......
...@@ -45,6 +45,7 @@ describe('IDE store merge request mutations', () => { ...@@ -45,6 +45,7 @@ describe('IDE store merge request mutations', () => {
}); });
const newMr = localState.projects.abcproject.mergeRequests[1]; const newMr = localState.projects.abcproject.mergeRequests[1];
expect(newMr.changes.diff).toBe('abc'); expect(newMr.changes.diff).toBe('abc');
}); });
}); });
...@@ -58,6 +59,7 @@ describe('IDE store merge request mutations', () => { ...@@ -58,6 +59,7 @@ describe('IDE store merge request mutations', () => {
}); });
const newMr = localState.projects.abcproject.mergeRequests[1]; const newMr = localState.projects.abcproject.mergeRequests[1];
expect(newMr.versions.length).toBe(1); expect(newMr.versions.length).toBe(1);
expect(newMr.versions[0].id).toBe(123); expect(newMr.versions[0].id).toBe(123);
}); });
......
...@@ -90,6 +90,7 @@ describe('badge helper', () => { ...@@ -90,6 +90,7 @@ describe('badge helper', () => {
it('should create icon comment button', () => { it('should create icon comment button', () => {
const iconEl = buttonEl.querySelector('svg'); const iconEl = buttonEl.querySelector('svg');
expect(iconEl).toBeDefined(); expect(iconEl).toBeDefined();
}); });
}); });
......
...@@ -29,9 +29,11 @@ describe('commentIndicatorHelper', () => { ...@@ -29,9 +29,11 @@ describe('commentIndicatorHelper', () => {
it('should contain image-comment-dark svg', () => { it('should contain image-comment-dark svg', () => {
const svgEl = buttonEl.querySelector('svg'); const svgEl = buttonEl.querySelector('svg');
expect(svgEl).toBeDefined(); expect(svgEl).toBeDefined();
const svgLink = svgEl.querySelector('use').getAttribute('xlink:href'); const svgLink = svgEl.querySelector('use').getAttribute('xlink:href');
expect(svgLink.indexOf('image-comment-dark')).not.toBe(-1); expect(svgLink.indexOf('image-comment-dark')).not.toBe(-1);
}); });
}); });
...@@ -40,6 +42,7 @@ describe('commentIndicatorHelper', () => { ...@@ -40,6 +42,7 @@ describe('commentIndicatorHelper', () => {
describe('removeCommentIndicator', () => { describe('removeCommentIndicator', () => {
it('should return removed false if there is no comment-indicator', () => { it('should return removed false if there is no comment-indicator', () => {
const result = commentIndicatorHelper.removeCommentIndicator(containerEl); const result = commentIndicatorHelper.removeCommentIndicator(containerEl);
expect(result.removed).toEqual(false); expect(result.removed).toEqual(false);
}); });
...@@ -84,6 +87,7 @@ describe('commentIndicatorHelper', () => { ...@@ -84,6 +87,7 @@ describe('commentIndicatorHelper', () => {
it('should set commentIndicator coordinates', () => { it('should set commentIndicator coordinates', () => {
const commentIndicatorEl = containerEl.querySelector('.comment-indicator'); const commentIndicatorEl = containerEl.querySelector('.comment-indicator');
expect(commentIndicatorEl.style.left).toEqual(`${coordinate.x}px`); expect(commentIndicatorEl.style.left).toEqual(`${coordinate.x}px`);
expect(commentIndicatorEl.style.top).toEqual(`${coordinate.y}px`); expect(commentIndicatorEl.style.top).toEqual(`${coordinate.y}px`);
}); });
...@@ -96,6 +100,7 @@ describe('commentIndicatorHelper', () => { ...@@ -96,6 +100,7 @@ describe('commentIndicatorHelper', () => {
it('should addCommentIndicator', () => { it('should addCommentIndicator', () => {
const buttonEl = containerEl.querySelector('.comment-indicator'); const buttonEl = containerEl.querySelector('.comment-indicator');
expect(buttonEl).toBeDefined(); expect(buttonEl).toBeDefined();
expect(buttonEl.style.left).toEqual(`${coordinate.x}px`); expect(buttonEl.style.left).toEqual(`${coordinate.x}px`);
expect(buttonEl.style.top).toEqual(`${coordinate.y}px`); expect(buttonEl.style.top).toEqual(`${coordinate.y}px`);
......
...@@ -92,6 +92,7 @@ describe('domHelper', () => { ...@@ -92,6 +92,7 @@ describe('domHelper', () => {
it('should force formEl to display none', () => { it('should force formEl to display none', () => {
const formEl = element.querySelector('.discussion-form'); const formEl = element.querySelector('.discussion-form');
expect(formEl.style.display).toEqual('none'); expect(formEl.style.display).toEqual('none');
}); });
}); });
...@@ -111,6 +112,7 @@ describe('domHelper', () => { ...@@ -111,6 +112,7 @@ describe('domHelper', () => {
it('should force formEl to display block', () => { it('should force formEl to display block', () => {
const formEl = element.querySelector('.discussion-form'); const formEl = element.querySelector('.discussion-form');
expect(formEl.style.display).toEqual('block'); expect(formEl.style.display).toEqual('block');
}); });
}); });
......
...@@ -57,6 +57,7 @@ describe('utilsHelper', () => { ...@@ -57,6 +57,7 @@ describe('utilsHelper', () => {
it('should return actual image properties', () => { it('should return actual image properties', () => {
const { actual } = result; const { actual } = result;
expect(actual.x).toEqual(imageMeta.x); expect(actual.x).toEqual(imageMeta.x);
expect(actual.y).toEqual(imageMeta.y); expect(actual.y).toEqual(imageMeta.y);
expect(actual.width).toEqual(imageMeta.width); expect(actual.width).toEqual(imageMeta.width);
...@@ -65,6 +66,7 @@ describe('utilsHelper', () => { ...@@ -65,6 +66,7 @@ describe('utilsHelper', () => {
it('should return browser image properties', () => { it('should return browser image properties', () => {
const { browser } = result; const { browser } = result;
expect(browser.x).toBeDefined(); expect(browser.x).toBeDefined();
expect(browser.y).toBeDefined(); expect(browser.y).toBeDefined();
expect(browser.width).toBeDefined(); expect(browser.width).toBeDefined();
...@@ -106,6 +108,7 @@ describe('utilsHelper', () => { ...@@ -106,6 +108,7 @@ describe('utilsHelper', () => {
const result = utilsHelper.getTargetSelection(event); const result = utilsHelper.getTargetSelection(event);
const { browser } = result; const { browser } = result;
expect(browser.x).toEqual(event.offsetX); expect(browser.x).toEqual(event.offsetX);
expect(browser.y).toEqual(event.offsetY); expect(browser.y).toEqual(event.offsetY);
expect(browser.width).toEqual(imageProperties.width); expect(browser.width).toEqual(imageProperties.width);
...@@ -117,6 +120,7 @@ describe('utilsHelper', () => { ...@@ -117,6 +120,7 @@ describe('utilsHelper', () => {
const result = utilsHelper.getTargetSelection(event); const result = utilsHelper.getTargetSelection(event);
const { actual } = result; const { actual } = result;
expect(actual.x).toEqual(100); expect(actual.x).toEqual(100);
expect(actual.y).toEqual(100); expect(actual.y).toEqual(100);
expect(actual.width).toEqual(imageProperties.naturalWidth); expect(actual.width).toEqual(imageProperties.naturalWidth);
...@@ -127,24 +131,28 @@ describe('utilsHelper', () => { ...@@ -127,24 +131,28 @@ describe('utilsHelper', () => {
it('should return x = 0 if x < 0', () => { it('should return x = 0 if x < 0', () => {
const event = generateEvent(-5, 50); const event = generateEvent(-5, 50);
const result = utilsHelper.getTargetSelection(event); const result = utilsHelper.getTargetSelection(event);
expect(result.browser.x).toEqual(0); expect(result.browser.x).toEqual(0);
}); });
it('should return x = width if x > width', () => { it('should return x = width if x > width', () => {
const event = generateEvent(1000, 50); const event = generateEvent(1000, 50);
const result = utilsHelper.getTargetSelection(event); const result = utilsHelper.getTargetSelection(event);
expect(result.browser.x).toEqual(imageProperties.width); expect(result.browser.x).toEqual(imageProperties.width);
}); });
it('should return y = 0 if y < 0', () => { it('should return y = 0 if y < 0', () => {
const event = generateEvent(50, -10); const event = generateEvent(50, -10);
const result = utilsHelper.getTargetSelection(event); const result = utilsHelper.getTargetSelection(event);
expect(result.browser.y).toEqual(0); expect(result.browser.y).toEqual(0);
}); });
it('should return y = height if y > height', () => { it('should return y = height if y > height', () => {
const event = generateEvent(50, 1000); const event = generateEvent(50, 1000);
const result = utilsHelper.getTargetSelection(event); const result = utilsHelper.getTargetSelection(event);
expect(result.browser.y).toEqual(imageProperties.height); expect(result.browser.y).toEqual(imageProperties.height);
}); });
}); });
...@@ -178,6 +186,7 @@ describe('utilsHelper', () => { ...@@ -178,6 +186,7 @@ describe('utilsHelper', () => {
`; `;
const imageDiff = utilsHelper.initImageDiff(fileEl, true, false); const imageDiff = utilsHelper.initImageDiff(fileEl, true, false);
expect(ImageDiff.prototype.init).toHaveBeenCalled(); expect(ImageDiff.prototype.init).toHaveBeenCalled();
expect(imageDiff.canCreateNote).toEqual(true); expect(imageDiff.canCreateNote).toEqual(true);
expect(imageDiff.renderCommentBadge).toEqual(false); expect(imageDiff.renderCommentBadge).toEqual(false);
...@@ -191,6 +200,7 @@ describe('utilsHelper', () => { ...@@ -191,6 +200,7 @@ describe('utilsHelper', () => {
`; `;
const replacedImageDiff = utilsHelper.initImageDiff(fileEl, false, true); const replacedImageDiff = utilsHelper.initImageDiff(fileEl, false, true);
expect(ReplacedImageDiff.prototype.init).toHaveBeenCalled(); expect(ReplacedImageDiff.prototype.init).toHaveBeenCalled();
expect(replacedImageDiff.canCreateNote).toEqual(false); expect(replacedImageDiff.canCreateNote).toEqual(false);
expect(replacedImageDiff.renderCommentBadge).toEqual(true); expect(replacedImageDiff.renderCommentBadge).toEqual(true);
......
...@@ -15,6 +15,7 @@ describe('ImageBadge', () => { ...@@ -15,6 +15,7 @@ describe('ImageBadge', () => {
})); }));
const { actual } = imageBadge; const { actual } = imageBadge;
expect(actual.x).toEqual(imageMeta.x); expect(actual.x).toEqual(imageMeta.x);
expect(actual.y).toEqual(imageMeta.y); expect(actual.y).toEqual(imageMeta.y);
expect(actual.width).toEqual(imageMeta.width); expect(actual.width).toEqual(imageMeta.width);
...@@ -27,6 +28,7 @@ describe('ImageBadge', () => { ...@@ -27,6 +28,7 @@ describe('ImageBadge', () => {
})); }));
const { browser } = imageBadge; const { browser } = imageBadge;
expect(browser.x).toEqual(imageMeta.x); expect(browser.x).toEqual(imageMeta.x);
expect(browser.y).toEqual(imageMeta.y); expect(browser.y).toEqual(imageMeta.y);
expect(browser.width).toEqual(imageMeta.width); expect(browser.width).toEqual(imageMeta.width);
...@@ -35,11 +37,13 @@ describe('ImageBadge', () => { ...@@ -35,11 +37,13 @@ describe('ImageBadge', () => {
it('should save noteId', () => { it('should save noteId', () => {
const imageBadge = new ImageBadge(options); const imageBadge = new ImageBadge(options);
expect(imageBadge.noteId).toEqual(noteId); expect(imageBadge.noteId).toEqual(noteId);
}); });
it('should save discussionId', () => { it('should save discussionId', () => {
const imageBadge = new ImageBadge(options); const imageBadge = new ImageBadge(options);
expect(imageBadge.discussionId).toEqual(discussionId); expect(imageBadge.discussionId).toEqual(discussionId);
}); });
...@@ -52,6 +56,7 @@ describe('ImageBadge', () => { ...@@ -52,6 +56,7 @@ describe('ImageBadge', () => {
it('should return defaultimageMeta if actual property is not provided', () => { it('should return defaultimageMeta if actual property is not provided', () => {
const { actual } = imageBadge; const { actual } = imageBadge;
expect(actual.x).toEqual(0); expect(actual.x).toEqual(0);
expect(actual.y).toEqual(0); expect(actual.y).toEqual(0);
expect(actual.width).toEqual(0); expect(actual.width).toEqual(0);
...@@ -60,6 +65,7 @@ describe('ImageBadge', () => { ...@@ -60,6 +65,7 @@ describe('ImageBadge', () => {
it('should return defaultimageMeta if browser property is not provided', () => { it('should return defaultimageMeta if browser property is not provided', () => {
const { browser } = imageBadge; const { browser } = imageBadge;
expect(browser.x).toEqual(0); expect(browser.x).toEqual(0);
expect(browser.y).toEqual(0); expect(browser.y).toEqual(0);
expect(browser.width).toEqual(0); expect(browser.width).toEqual(0);
......
...@@ -117,11 +117,13 @@ describe('ImageDiff', () => { ...@@ -117,11 +117,13 @@ describe('ImageDiff', () => {
it('should register click event delegation to js-diff-notes-toggle', () => { it('should register click event delegation to js-diff-notes-toggle', () => {
element.querySelector('.js-diff-notes-toggle').click(); element.querySelector('.js-diff-notes-toggle').click();
expect(imageDiffHelper.toggleCollapsed).toHaveBeenCalled(); expect(imageDiffHelper.toggleCollapsed).toHaveBeenCalled();
}); });
it('should register click event delegation to comment-indicator', () => { it('should register click event delegation to comment-indicator', () => {
element.querySelector('.comment-indicator').click(); element.querySelector('.comment-indicator').click();
expect(imageDiffHelper.commentIndicatorOnClick).toHaveBeenCalled(); expect(imageDiffHelper.commentIndicatorOnClick).toHaveBeenCalled();
}); });
}); });
...@@ -147,6 +149,7 @@ describe('ImageDiff', () => { ...@@ -147,6 +149,7 @@ describe('ImageDiff', () => {
it('should registers load eventListener', () => { it('should registers load eventListener', () => {
const loadEvent = new Event('load'); const loadEvent = new Event('load');
imageEl.dispatchEvent(loadEvent); imageEl.dispatchEvent(loadEvent);
expect(imageDiff.renderBadges).toHaveBeenCalled(); expect(imageDiff.renderBadges).toHaveBeenCalled();
}); });
}); });
...@@ -164,24 +167,28 @@ describe('ImageDiff', () => { ...@@ -164,24 +167,28 @@ describe('ImageDiff', () => {
it('should register click.imageDiff event', () => { it('should register click.imageDiff event', () => {
const event = new CustomEvent('click.imageDiff'); const event = new CustomEvent('click.imageDiff');
element.dispatchEvent(event); element.dispatchEvent(event);
expect(imageDiff.imageClicked).toHaveBeenCalled(); expect(imageDiff.imageClicked).toHaveBeenCalled();
}); });
it('should register blur.imageDiff event', () => { it('should register blur.imageDiff event', () => {
const event = new CustomEvent('blur.imageDiff'); const event = new CustomEvent('blur.imageDiff');
element.dispatchEvent(event); element.dispatchEvent(event);
expect(imageDiffHelper.removeCommentIndicator).toHaveBeenCalled(); expect(imageDiffHelper.removeCommentIndicator).toHaveBeenCalled();
}); });
it('should register addBadge.imageDiff event', () => { it('should register addBadge.imageDiff event', () => {
const event = new CustomEvent('addBadge.imageDiff'); const event = new CustomEvent('addBadge.imageDiff');
element.dispatchEvent(event); element.dispatchEvent(event);
expect(imageDiff.addBadge).toHaveBeenCalled(); expect(imageDiff.addBadge).toHaveBeenCalled();
}); });
it('should register removeBadge.imageDiff event', () => { it('should register removeBadge.imageDiff event', () => {
const event = new CustomEvent('removeBadge.imageDiff'); const event = new CustomEvent('removeBadge.imageDiff');
element.dispatchEvent(event); element.dispatchEvent(event);
expect(imageDiff.removeBadge).toHaveBeenCalled(); expect(imageDiff.removeBadge).toHaveBeenCalled();
}); });
}); });
...@@ -197,6 +204,7 @@ describe('ImageDiff', () => { ...@@ -197,6 +204,7 @@ describe('ImageDiff', () => {
it('should not register click.imageDiff event', () => { it('should not register click.imageDiff event', () => {
const event = new CustomEvent('click.imageDiff'); const event = new CustomEvent('click.imageDiff');
element.dispatchEvent(event); element.dispatchEvent(event);
expect(imageDiff.imageClicked).not.toHaveBeenCalled(); expect(imageDiff.imageClicked).not.toHaveBeenCalled();
}); });
}); });
...@@ -240,6 +248,7 @@ describe('ImageDiff', () => { ...@@ -240,6 +248,7 @@ describe('ImageDiff', () => {
it('should call renderBadge for each discussionEl', () => { it('should call renderBadge for each discussionEl', () => {
const discussionEls = element.querySelectorAll('.note-container .discussion-notes .notes'); const discussionEls = element.querySelectorAll('.note-container .discussion-notes .notes');
expect(imageDiff.renderBadge.calls.count()).toEqual(discussionEls.length); expect(imageDiff.renderBadge.calls.count()).toEqual(discussionEls.length);
}); });
}); });
...@@ -336,6 +345,7 @@ describe('ImageDiff', () => { ...@@ -336,6 +345,7 @@ describe('ImageDiff', () => {
describe('cascade badge count', () => { describe('cascade badge count', () => {
it('should update next imageBadgeEl value', () => { it('should update next imageBadgeEl value', () => {
const imageBadgeEls = imageDiff.imageFrameEl.querySelectorAll('.badge'); const imageBadgeEls = imageDiff.imageFrameEl.querySelectorAll('.badge');
expect(imageBadgeEls[0].innerText).toEqual('1'); expect(imageBadgeEls[0].innerText).toEqual('1');
expect(imageBadgeEls[1].innerText).toEqual('2'); expect(imageBadgeEls[1].innerText).toEqual('2');
expect(imageBadgeEls.length).toEqual(2); expect(imageBadgeEls.length).toEqual(2);
......
...@@ -32,6 +32,7 @@ describe('initDiscussionTab', () => { ...@@ -32,6 +32,7 @@ describe('initDiscussionTab', () => {
it('should call initImageDiff for each diffFileEls', () => { it('should call initImageDiff for each diffFileEls', () => {
spyOn(imageDiffHelper, 'initImageDiff').and.callFake(() => {}); spyOn(imageDiffHelper, 'initImageDiff').and.callFake(() => {});
initDiscussionTab(); initDiscussionTab();
expect(imageDiffHelper.initImageDiff.calls.count()).toEqual(2); expect(imageDiffHelper.initImageDiff.calls.count()).toEqual(2);
}); });
}); });
...@@ -58,6 +58,7 @@ describe('ReplacedImageDiff', () => { ...@@ -58,6 +58,7 @@ describe('ReplacedImageDiff', () => {
it('should extend ImageDiff', () => { it('should extend ImageDiff', () => {
replacedImageDiff = new ReplacedImageDiff(element); replacedImageDiff = new ReplacedImageDiff(element);
expect(replacedImageDiff instanceof ImageDiff).toEqual(true); expect(replacedImageDiff instanceof ImageDiff).toEqual(true);
}); });
...@@ -72,6 +73,7 @@ describe('ReplacedImageDiff', () => { ...@@ -72,6 +73,7 @@ describe('ReplacedImageDiff', () => {
it('should set imageFrameEls', () => { it('should set imageFrameEls', () => {
const { imageFrameEls } = replacedImageDiff; const { imageFrameEls } = replacedImageDiff;
expect(imageFrameEls).toBeDefined(); expect(imageFrameEls).toBeDefined();
expect(imageFrameEls[viewTypes.TWO_UP]).toEqual(element.querySelector('.two-up .js-image-frame')); expect(imageFrameEls[viewTypes.TWO_UP]).toEqual(element.querySelector('.two-up .js-image-frame'));
expect(imageFrameEls[viewTypes.SWIPE]).toEqual(element.querySelector('.swipe .js-image-frame')); expect(imageFrameEls[viewTypes.SWIPE]).toEqual(element.querySelector('.swipe .js-image-frame'));
...@@ -80,6 +82,7 @@ describe('ReplacedImageDiff', () => { ...@@ -80,6 +82,7 @@ describe('ReplacedImageDiff', () => {
it('should set viewModesEls', () => { it('should set viewModesEls', () => {
const { viewModesEls } = replacedImageDiff; const { viewModesEls } = replacedImageDiff;
expect(viewModesEls).toBeDefined(); expect(viewModesEls).toBeDefined();
expect(viewModesEls[viewTypes.TWO_UP]).toEqual(element.querySelector('.view-modes-menu .two-up')); expect(viewModesEls[viewTypes.TWO_UP]).toEqual(element.querySelector('.view-modes-menu .two-up'));
expect(viewModesEls[viewTypes.SWIPE]).toEqual(element.querySelector('.view-modes-menu .swipe')); expect(viewModesEls[viewTypes.SWIPE]).toEqual(element.querySelector('.view-modes-menu .swipe'));
...@@ -97,6 +100,7 @@ describe('ReplacedImageDiff', () => { ...@@ -97,6 +100,7 @@ describe('ReplacedImageDiff', () => {
describe('currentView', () => { describe('currentView', () => {
it('should set currentView', () => { it('should set currentView', () => {
replacedImageDiff.init(viewTypes.ONION_SKIN); replacedImageDiff.init(viewTypes.ONION_SKIN);
expect(replacedImageDiff.currentView).toEqual(viewTypes.ONION_SKIN); expect(replacedImageDiff.currentView).toEqual(viewTypes.ONION_SKIN);
}); });
...@@ -121,6 +125,7 @@ describe('ReplacedImageDiff', () => { ...@@ -121,6 +125,7 @@ describe('ReplacedImageDiff', () => {
it('should set imageEls', () => { it('should set imageEls', () => {
replacedImageDiff.generateImageEls(); replacedImageDiff.generateImageEls();
const { imageEls } = replacedImageDiff; const { imageEls } = replacedImageDiff;
expect(imageEls).toBeDefined(); expect(imageEls).toBeDefined();
expect(imageEls[viewTypes.TWO_UP]).toEqual(element.querySelector('.two-up img')); expect(imageEls[viewTypes.TWO_UP]).toEqual(element.querySelector('.two-up img'));
expect(imageEls[viewTypes.SWIPE]).toEqual(element.querySelector('.swipe img')); expect(imageEls[viewTypes.SWIPE]).toEqual(element.querySelector('.swipe img'));
...@@ -138,6 +143,7 @@ describe('ReplacedImageDiff', () => { ...@@ -138,6 +143,7 @@ describe('ReplacedImageDiff', () => {
it('should call super.bindEvents', () => { it('should call super.bindEvents', () => {
replacedImageDiff.bindEvents(); replacedImageDiff.bindEvents();
expect(ImageDiff.prototype.bindEvents).toHaveBeenCalled(); expect(ImageDiff.prototype.bindEvents).toHaveBeenCalled();
}); });
...@@ -184,6 +190,7 @@ describe('ReplacedImageDiff', () => { ...@@ -184,6 +190,7 @@ describe('ReplacedImageDiff', () => {
expect(replacedImageDiff.imageEl).toEqual(element.querySelector('.two-up img')); expect(replacedImageDiff.imageEl).toEqual(element.querySelector('.two-up img'));
replacedImageDiff.currentView = viewTypes.SWIPE; replacedImageDiff.currentView = viewTypes.SWIPE;
expect(replacedImageDiff.imageEl).toEqual(element.querySelector('.swipe img')); expect(replacedImageDiff.imageEl).toEqual(element.querySelector('.swipe img'));
}); });
}); });
...@@ -199,6 +206,7 @@ describe('ReplacedImageDiff', () => { ...@@ -199,6 +206,7 @@ describe('ReplacedImageDiff', () => {
expect(replacedImageDiff.imageFrameEl).toEqual(element.querySelector('.two-up .js-image-frame')); expect(replacedImageDiff.imageFrameEl).toEqual(element.querySelector('.two-up .js-image-frame'));
replacedImageDiff.currentView = viewTypes.ONION_SKIN; replacedImageDiff.currentView = viewTypes.ONION_SKIN;
expect(replacedImageDiff.imageFrameEl).toEqual(element.querySelector('.onion-skin .js-image-frame')); expect(replacedImageDiff.imageFrameEl).toEqual(element.querySelector('.onion-skin .js-image-frame'));
}); });
}); });
...@@ -248,6 +256,7 @@ describe('ReplacedImageDiff', () => { ...@@ -248,6 +256,7 @@ describe('ReplacedImageDiff', () => {
it('should call renderNewView', () => { it('should call renderNewView', () => {
jasmine.clock().tick(251); jasmine.clock().tick(251);
expect(replacedImageDiff.renderNewView).toHaveBeenCalled(); expect(replacedImageDiff.renderNewView).toHaveBeenCalled();
}); });
}); });
......
...@@ -63,6 +63,7 @@ describe('Importer Status', () => { ...@@ -63,6 +63,7 @@ describe('Importer Status', () => {
}) })
.then(() => { .then(() => {
const flashMessage = document.querySelector('.flash-text'); const flashMessage = document.querySelector('.flash-text');
expect(flashMessage.textContent.trim()).toEqual('An error occurred while importing project: You forgot your lunch'); expect(flashMessage.textContent.trim()).toEqual('An error occurred while importing project: You forgot your lunch');
done(); done();
}) })
......
...@@ -68,6 +68,7 @@ describe('IntegrationSettingsForm', () => { ...@@ -68,6 +68,7 @@ describe('IntegrationSettingsForm', () => {
integrationSettingsForm.canTestService = true; integrationSettingsForm.canTestService = true;
integrationSettingsForm.toggleSubmitBtnLabel(true); integrationSettingsForm.toggleSubmitBtnLabel(true);
expect(integrationSettingsForm.$submitBtnLabel.text()).toEqual('Test settings and save changes'); expect(integrationSettingsForm.$submitBtnLabel.text()).toEqual('Test settings and save changes');
}); });
...@@ -75,14 +76,17 @@ describe('IntegrationSettingsForm', () => { ...@@ -75,14 +76,17 @@ describe('IntegrationSettingsForm', () => {
integrationSettingsForm.canTestService = false; integrationSettingsForm.canTestService = false;
integrationSettingsForm.toggleSubmitBtnLabel(false); integrationSettingsForm.toggleSubmitBtnLabel(false);
expect(integrationSettingsForm.$submitBtnLabel.text()).toEqual('Save changes'); expect(integrationSettingsForm.$submitBtnLabel.text()).toEqual('Save changes');
integrationSettingsForm.toggleSubmitBtnLabel(true); integrationSettingsForm.toggleSubmitBtnLabel(true);
expect(integrationSettingsForm.$submitBtnLabel.text()).toEqual('Save changes'); expect(integrationSettingsForm.$submitBtnLabel.text()).toEqual('Save changes');
integrationSettingsForm.canTestService = true; integrationSettingsForm.canTestService = true;
integrationSettingsForm.toggleSubmitBtnLabel(false); integrationSettingsForm.toggleSubmitBtnLabel(false);
expect(integrationSettingsForm.$submitBtnLabel.text()).toEqual('Save changes'); expect(integrationSettingsForm.$submitBtnLabel.text()).toEqual('Save changes');
}); });
}); });
...@@ -149,6 +153,7 @@ describe('IntegrationSettingsForm', () => { ...@@ -149,6 +153,7 @@ describe('IntegrationSettingsForm', () => {
integrationSettingsForm.testSettings(formData) integrationSettingsForm.testSettings(formData)
.then(() => { .then(() => {
const $flashContainer = $('.flash-container'); const $flashContainer = $('.flash-container');
expect($flashContainer.find('.flash-text').text().trim()).toEqual('Test failed. some error'); expect($flashContainer.find('.flash-text').text().trim()).toEqual('Test failed. some error');
expect($flashContainer.find('.flash-action')).toBeDefined(); expect($flashContainer.find('.flash-action')).toBeDefined();
expect($flashContainer.find('.flash-action').text().trim()).toEqual('Save anyway'); expect($flashContainer.find('.flash-action').text().trim()).toEqual('Save anyway');
...@@ -170,6 +175,7 @@ describe('IntegrationSettingsForm', () => { ...@@ -170,6 +175,7 @@ describe('IntegrationSettingsForm', () => {
integrationSettingsForm.testSettings(formData) integrationSettingsForm.testSettings(formData)
.then(() => { .then(() => {
const $flashContainer = $('.flash-container'); const $flashContainer = $('.flash-container');
expect($flashContainer.find('.flash-text').text().trim()).toEqual('Validations failed. some error'); expect($flashContainer.find('.flash-text').text().trim()).toEqual('Validations failed. some error');
expect($flashContainer.find('.flash-action')).toBeDefined(); expect($flashContainer.find('.flash-action')).toBeDefined();
expect($flashContainer.find('.flash-action').text().trim()).toEqual(''); expect($flashContainer.find('.flash-action').text().trim()).toEqual('');
...@@ -208,6 +214,7 @@ describe('IntegrationSettingsForm', () => { ...@@ -208,6 +214,7 @@ describe('IntegrationSettingsForm', () => {
integrationSettingsForm.testSettings(formData) integrationSettingsForm.testSettings(formData)
.then(() => { .then(() => {
const $flashAction = $('.flash-container .flash-action'); const $flashAction = $('.flash-container .flash-action');
expect($flashAction).toBeDefined(); expect($flashAction).toBeDefined();
$flashAction.get(0).click(); $flashAction.get(0).click();
......
...@@ -8,6 +8,7 @@ describe('Issuable', () => { ...@@ -8,6 +8,7 @@ describe('Issuable', () => {
describe('initBulkUpdate', () => { describe('initBulkUpdate', () => {
it('should not set bulkUpdateSidebar', () => { it('should not set bulkUpdateSidebar', () => {
Issuable = new IssuableIndex('issue_'); Issuable = new IssuableIndex('issue_');
expect(Issuable.bulkUpdateSidebar).not.toBeDefined(); expect(Issuable.bulkUpdateSidebar).not.toBeDefined();
}); });
...@@ -17,6 +18,7 @@ describe('Issuable', () => { ...@@ -17,6 +18,7 @@ describe('Issuable', () => {
document.body.appendChild(element); document.body.appendChild(element);
Issuable = new IssuableIndex('issue_'); Issuable = new IssuableIndex('issue_');
expect(Issuable.bulkUpdateSidebar).toBeDefined(); expect(Issuable.bulkUpdateSidebar).toBeDefined();
}); });
}); });
......
...@@ -258,6 +258,7 @@ describe('Issuable output', () => { ...@@ -258,6 +258,7 @@ describe('Issuable output', () => {
expect( expect(
eventHub.$emit, eventHub.$emit,
).toHaveBeenCalledWith('close.form'); ).toHaveBeenCalledWith('close.form');
expect( expect(
window.Flash, window.Flash,
).toHaveBeenCalledWith('Error updating issue'); ).toHaveBeenCalledWith('Error updating issue');
...@@ -276,6 +277,7 @@ describe('Issuable output', () => { ...@@ -276,6 +277,7 @@ describe('Issuable output', () => {
expect( expect(
eventHub.$emit, eventHub.$emit,
).toHaveBeenCalledWith('close.form'); ).toHaveBeenCalledWith('close.form');
expect( expect(
window.Flash, window.Flash,
).toHaveBeenCalledWith('Error updating merge request'); ).toHaveBeenCalledWith('Error updating merge request');
...@@ -383,6 +385,7 @@ describe('Issuable output', () => { ...@@ -383,6 +385,7 @@ describe('Issuable output', () => {
expect( expect(
eventHub.$emit, eventHub.$emit,
).toHaveBeenCalledWith('close.form'); ).toHaveBeenCalledWith('close.form');
expect( expect(
window.Flash, window.Flash,
).toHaveBeenCalledWith('Error deleting issue'); ).toHaveBeenCalledWith('Error deleting issue');
...@@ -422,6 +425,7 @@ describe('Issuable output', () => { ...@@ -422,6 +425,7 @@ describe('Issuable output', () => {
it('should render if showInlineEditButton', () => { it('should render if showInlineEditButton', () => {
vm.showInlineEditButton = true; vm.showInlineEditButton = true;
expect(vm.$el.querySelector('.title-container .note-action-button')).toBeDefined(); expect(vm.$el.querySelector('.title-container .note-action-button')).toBeDefined();
}); });
}); });
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment