Commit 4342f81a authored by Filipa Lacerda's avatar Filipa Lacerda

Removes disabled state from projects dropdown in dashboard page

parent 8274e0fe
...@@ -13,8 +13,16 @@ export default class ProjectSelectComboButton { ...@@ -13,8 +13,16 @@ export default class ProjectSelectComboButton {
} }
bindEvents() { bindEvents() {
this.projectSelectInput.siblings('.new-project-item-select-button') const dropdownButton = this.projectSelectInput.siblings('.new-project-item-select-button');
.on('click', this.openDropdown);
dropdownButton.on('click', this.openDropdown);
this.newItemBtn.on('click', (e) => {
if (!this.getProjectFromLocalStorage()) {
e.preventDefault();
dropdownButton.trigger('click');
}
});
this.projectSelectInput.on('change', () => this.selectProject()); this.projectSelectInput.on('change', () => this.selectProject());
} }
...@@ -56,10 +64,8 @@ export default class ProjectSelectComboButton { ...@@ -56,10 +64,8 @@ export default class ProjectSelectComboButton {
if (project) { if (project) {
this.newItemBtn.attr('href', project.url); this.newItemBtn.attr('href', project.url);
this.newItemBtn.text(`${this.formattedText.defaultTextPrefix} in ${project.name}`); this.newItemBtn.text(`${this.formattedText.defaultTextPrefix} in ${project.name}`);
this.newItemBtn.enable();
} else { } else {
this.newItemBtn.text(`Select project to create ${this.formattedText.presetTextSuffix}`); this.newItemBtn.text(`Select project to create ${this.formattedText.presetTextSuffix}`);
this.newItemBtn.disable();
} }
} }
......
---
title: Removes disabled state from dashboard project button
merge_request:
author:
type: fixed
...@@ -2,10 +2,10 @@ import ProjectSelectComboButton from '~/project_select_combo_button'; ...@@ -2,10 +2,10 @@ import ProjectSelectComboButton from '~/project_select_combo_button';
const fixturePath = 'static/project_select_combo_button.html.raw'; const fixturePath = 'static/project_select_combo_button.html.raw';
describe('Project Select Combo Button', function () { describe('Project Select Combo Button', () => {
preloadFixtures(fixturePath); preloadFixtures(fixturePath);
beforeEach(function () { beforeEach(() => {
this.defaults = { this.defaults = {
label: 'Select project to create issue', label: 'Select project to create issue',
groupId: 12345, groupId: 12345,
...@@ -27,53 +27,43 @@ describe('Project Select Combo Button', function () { ...@@ -27,53 +27,43 @@ describe('Project Select Combo Button', function () {
this.projectSelectInput = document.querySelector('.project-item-select'); this.projectSelectInput = document.querySelector('.project-item-select');
}); });
describe('on page load when localStorage is empty', function () { describe('on page load when localStorage is empty', () => {
beforeEach(function () { beforeEach(() => {
this.comboButton = new ProjectSelectComboButton(this.projectSelectInput); this.comboButton = new ProjectSelectComboButton(this.projectSelectInput);
}); });
it('newItemBtn is disabled', function () { it('newItemBtn href is null', () => {
expect(this.newItemBtn.hasAttribute('disabled')).toBe(true);
expect(this.newItemBtn.classList.contains('disabled')).toBe(true);
});
it('newItemBtn href is null', function () {
expect(this.newItemBtn.getAttribute('href')).toBe(''); expect(this.newItemBtn.getAttribute('href')).toBe('');
}); });
it('newItemBtn text is the plain default label', function () { it('newItemBtn text is the plain default label', () => {
expect(this.newItemBtn.textContent).toBe(this.defaults.label); expect(this.newItemBtn.textContent).toBe(this.defaults.label);
}); });
}); });
describe('on page load when localStorage is filled', function () { describe('on page load when localStorage is filled', () => {
beforeEach(function () { beforeEach(() => {
window.localStorage window.localStorage
.setItem(this.defaults.localStorageKey, JSON.stringify(this.defaults.projectMeta)); .setItem(this.defaults.localStorageKey, JSON.stringify(this.defaults.projectMeta));
this.comboButton = new ProjectSelectComboButton(this.projectSelectInput); this.comboButton = new ProjectSelectComboButton(this.projectSelectInput);
}); });
it('newItemBtn is not disabled', function () { it('newItemBtn href is correctly set', () => {
expect(this.newItemBtn.hasAttribute('disabled')).toBe(false);
expect(this.newItemBtn.classList.contains('disabled')).toBe(false);
});
it('newItemBtn href is correctly set', function () {
expect(this.newItemBtn.getAttribute('href')).toBe(this.defaults.projectMeta.url); expect(this.newItemBtn.getAttribute('href')).toBe(this.defaults.projectMeta.url);
}); });
it('newItemBtn text is the cached label', function () { it('newItemBtn text is the cached label', () => {
expect(this.newItemBtn.textContent) expect(this.newItemBtn.textContent)
.toBe(`New issue in ${this.defaults.projectMeta.name}`); .toBe(`New issue in ${this.defaults.projectMeta.name}`);
}); });
afterEach(function () { afterEach(() => {
window.localStorage.clear(); window.localStorage.clear();
}); });
}); });
describe('after selecting a new project', function () { describe('after selecting a new project', () => {
beforeEach(function () { beforeEach(() => {
this.comboButton = new ProjectSelectComboButton(this.projectSelectInput); this.comboButton = new ProjectSelectComboButton(this.projectSelectInput);
// mock the effect of selecting an item from the projects dropdown (select2) // mock the effect of selecting an item from the projects dropdown (select2)
...@@ -82,28 +72,23 @@ describe('Project Select Combo Button', function () { ...@@ -82,28 +72,23 @@ describe('Project Select Combo Button', function () {
.trigger('change'); .trigger('change');
}); });
it('newItemBtn is not disabled', function () { it('newItemBtn href is correctly set', () => {
expect(this.newItemBtn.hasAttribute('disabled')).toBe(false);
expect(this.newItemBtn.classList.contains('disabled')).toBe(false);
});
it('newItemBtn href is correctly set', function () {
expect(this.newItemBtn.getAttribute('href')) expect(this.newItemBtn.getAttribute('href'))
.toBe('http://myothercoolproject.com/issues/new'); .toBe('http://myothercoolproject.com/issues/new');
}); });
it('newItemBtn text is the selected project label', function () { it('newItemBtn text is the selected project label', () => {
expect(this.newItemBtn.textContent) expect(this.newItemBtn.textContent)
.toBe(`New issue in ${this.defaults.newProjectMeta.name}`); .toBe(`New issue in ${this.defaults.newProjectMeta.name}`);
}); });
afterEach(function () { afterEach(() => {
window.localStorage.clear(); window.localStorage.clear();
}); });
}); });
describe('deriveTextVariants', function () { describe('deriveTextVariants', () => {
beforeEach(function () { beforeEach(() => {
this.mockExecutionContext = { this.mockExecutionContext = {
resourceType: '', resourceType: '',
resourceLabel: '', resourceLabel: '',
...@@ -114,7 +99,7 @@ describe('Project Select Combo Button', function () { ...@@ -114,7 +99,7 @@ describe('Project Select Combo Button', function () {
this.method = this.comboButton.deriveTextVariants.bind(this.mockExecutionContext); this.method = this.comboButton.deriveTextVariants.bind(this.mockExecutionContext);
}); });
it('correctly derives test variants for merge requests', function () { it('correctly derives test variants for merge requests', () => {
this.mockExecutionContext.resourceType = 'merge_requests'; this.mockExecutionContext.resourceType = 'merge_requests';
this.mockExecutionContext.resourceLabel = 'New merge request'; this.mockExecutionContext.resourceLabel = 'New merge request';
...@@ -125,7 +110,7 @@ describe('Project Select Combo Button', function () { ...@@ -125,7 +110,7 @@ describe('Project Select Combo Button', function () {
expect(returnedVariants.presetTextSuffix).toBe('merge request'); expect(returnedVariants.presetTextSuffix).toBe('merge request');
}); });
it('correctly derives text variants for issues', function () { it('correctly derives text variants for issues', () => {
this.mockExecutionContext.resourceType = 'issues'; this.mockExecutionContext.resourceType = 'issues';
this.mockExecutionContext.resourceLabel = 'New issue'; this.mockExecutionContext.resourceLabel = 'New issue';
......
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