2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-08-07 16:55:50 -04:00
|
|
|
import ProjectSelectComboButton from '~/project_select_combo_button';
|
|
|
|
|
|
|
|
const fixturePath = 'static/project_select_combo_button.html.raw';
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
describe('Project Select Combo Button', function() {
|
2017-08-07 16:55:50 -04:00
|
|
|
preloadFixtures(fixturePath);
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
beforeEach(function() {
|
2017-08-07 16:55:50 -04:00
|
|
|
this.defaults = {
|
|
|
|
label: 'Select project to create issue',
|
|
|
|
groupId: 12345,
|
|
|
|
projectMeta: {
|
|
|
|
name: 'My Cool Project',
|
|
|
|
url: 'http://mycoolproject.com',
|
|
|
|
},
|
|
|
|
newProjectMeta: {
|
|
|
|
name: 'My Other Cool Project',
|
|
|
|
url: 'http://myothercoolproject.com',
|
|
|
|
},
|
|
|
|
localStorageKey: 'group-12345-new-issue-recent-project',
|
|
|
|
relativePath: 'issues/new',
|
|
|
|
};
|
|
|
|
|
|
|
|
loadFixtures(fixturePath);
|
|
|
|
|
|
|
|
this.newItemBtn = document.querySelector('.new-project-item-link');
|
|
|
|
this.projectSelectInput = document.querySelector('.project-item-select');
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
describe('on page load when localStorage is empty', function() {
|
|
|
|
beforeEach(function() {
|
2017-08-07 16:55:50 -04:00
|
|
|
this.comboButton = new ProjectSelectComboButton(this.projectSelectInput);
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('newItemBtn href is null', function() {
|
2017-08-07 16:55:50 -04:00
|
|
|
expect(this.newItemBtn.getAttribute('href')).toBe('');
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('newItemBtn text is the plain default label', function() {
|
2017-08-07 16:55:50 -04:00
|
|
|
expect(this.newItemBtn.textContent).toBe(this.defaults.label);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
describe('on page load when localStorage is filled', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
window.localStorage.setItem(
|
|
|
|
this.defaults.localStorageKey,
|
|
|
|
JSON.stringify(this.defaults.projectMeta),
|
|
|
|
);
|
2017-08-07 16:55:50 -04:00
|
|
|
this.comboButton = new ProjectSelectComboButton(this.projectSelectInput);
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('newItemBtn href is correctly set', function() {
|
2017-08-07 16:55:50 -04:00
|
|
|
expect(this.newItemBtn.getAttribute('href')).toBe(this.defaults.projectMeta.url);
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('newItemBtn text is the cached label', function() {
|
|
|
|
expect(this.newItemBtn.textContent).toBe(`New issue in ${this.defaults.projectMeta.name}`);
|
2017-08-07 16:55:50 -04:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
afterEach(function() {
|
2017-08-07 16:55:50 -04:00
|
|
|
window.localStorage.clear();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
describe('after selecting a new project', function() {
|
|
|
|
beforeEach(function() {
|
2017-08-07 16:55:50 -04:00
|
|
|
this.comboButton = new ProjectSelectComboButton(this.projectSelectInput);
|
|
|
|
|
|
|
|
// mock the effect of selecting an item from the projects dropdown (select2)
|
|
|
|
$('.project-item-select')
|
|
|
|
.val(JSON.stringify(this.defaults.newProjectMeta))
|
|
|
|
.trigger('change');
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('newItemBtn href is correctly set', function() {
|
|
|
|
expect(this.newItemBtn.getAttribute('href')).toBe('http://myothercoolproject.com/issues/new');
|
2017-08-07 16:55:50 -04:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('newItemBtn text is the selected project label', function() {
|
|
|
|
expect(this.newItemBtn.textContent).toBe(`New issue in ${this.defaults.newProjectMeta.name}`);
|
2017-08-07 16:55:50 -04:00
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
afterEach(function() {
|
2017-08-07 16:55:50 -04:00
|
|
|
window.localStorage.clear();
|
|
|
|
});
|
|
|
|
});
|
2017-08-21 17:29:09 -04:00
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
describe('deriveTextVariants', function() {
|
|
|
|
beforeEach(function() {
|
2017-08-21 17:29:09 -04:00
|
|
|
this.mockExecutionContext = {
|
|
|
|
resourceType: '',
|
|
|
|
resourceLabel: '',
|
|
|
|
};
|
|
|
|
|
|
|
|
this.comboButton = new ProjectSelectComboButton(this.projectSelectInput);
|
|
|
|
|
|
|
|
this.method = this.comboButton.deriveTextVariants.bind(this.mockExecutionContext);
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('correctly derives test variants for merge requests', function() {
|
2017-08-21 17:29:09 -04:00
|
|
|
this.mockExecutionContext.resourceType = 'merge_requests';
|
|
|
|
this.mockExecutionContext.resourceLabel = 'New merge request';
|
|
|
|
|
|
|
|
const returnedVariants = this.method();
|
|
|
|
|
|
|
|
expect(returnedVariants.localStorageItemType).toBe('new-merge-request');
|
|
|
|
expect(returnedVariants.defaultTextPrefix).toBe('New merge request');
|
|
|
|
expect(returnedVariants.presetTextSuffix).toBe('merge request');
|
|
|
|
});
|
|
|
|
|
2018-10-17 03:13:26 -04:00
|
|
|
it('correctly derives text variants for issues', function() {
|
2017-08-21 17:29:09 -04:00
|
|
|
this.mockExecutionContext.resourceType = 'issues';
|
|
|
|
this.mockExecutionContext.resourceLabel = 'New issue';
|
|
|
|
|
|
|
|
const returnedVariants = this.method();
|
|
|
|
|
|
|
|
expect(returnedVariants.localStorageItemType).toBe('new-issue');
|
|
|
|
expect(returnedVariants.defaultTextPrefix).toBe('New issue');
|
|
|
|
expect(returnedVariants.presetTextSuffix).toBe('issue');
|
|
|
|
});
|
|
|
|
});
|
2017-08-07 16:55:50 -04:00
|
|
|
});
|