Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke "Jared" Bennett <lbennett@gitlab.com>2017-04-07 01:04:02 +0300
committerLuke "Jared" Bennett <lbennett@gitlab.com>2017-04-07 01:04:02 +0300
commit31c51c8c5f9f6277f9beb734a2579c35c609e707 (patch)
tree94075838e9203ee09afa90437233c0643648677d /spec/javascripts
parentde3e0834daddd7ba4904b14a37f95df7b993877c (diff)
parent993c2071ab95ffc96fcabb77042f64ca3c3d60d5 (diff)
Merge branch 'update-droplab-to-webpack-version' into new-resolvable-discussion
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/droplab/plugins/input_setter.js79
1 files changed, 74 insertions, 5 deletions
diff --git a/spec/javascripts/droplab/plugins/input_setter.js b/spec/javascripts/droplab/plugins/input_setter.js
index 81bb70fa6e5..c9b7b2b23dc 100644
--- a/spec/javascripts/droplab/plugins/input_setter.js
+++ b/spec/javascripts/droplab/plugins/input_setter.js
@@ -117,12 +117,13 @@ describe('InputSetter', function () {
describe('setInput', function () {
beforeEach(function () {
this.selectedItem = { getAttribute: () => {} };
- this.input = { value: 'oldValue', tagName: 'INPUT' };
+ this.input = { value: 'oldValue', tagName: 'INPUT', hasAttribute: () => {} };
this.config = { valueAttribute: {}, input: this.input };
this.inputSetter = { hook: { trigger: {} } };
this.newValue = 'newValue';
spyOn(this.selectedItem, 'getAttribute').and.returnValue(this.newValue);
+ spyOn(this.input, 'hasAttribute').and.returnValue(false);
InputSetter.setInput.call(this.inputSetter, this.config, this.selectedItem);
});
@@ -131,14 +132,34 @@ describe('InputSetter', function () {
expect(this.selectedItem.getAttribute).toHaveBeenCalledWith(this.config.valueAttribute);
});
+ it('should call .hasAttribute', function () {
+ expect(this.input.hasAttribute).toHaveBeenCalledWith(undefined);
+ });
+
it('should set the value of the input', function () {
expect(this.input.value).toBe(this.newValue);
- })
+ });
+
+ describe('if there is no newValue', function () {
+ beforeEach(function () {
+ this.newValue = '';
+ this.inputSetter = { hook: { trigger: {} } };
+ this.config = { valueAttribute: {}, input: this.input };
+ this.input = { value: 'oldValue', tagName: 'INPUT' };
+ this.selectedItem = { getAttribute: () => {} };
+
+ InputSetter.setInput.call(this.inputSetter, this.config, this.selectedItem);
+ });
+
+ it('should not set the value of the input', function () {
+ expect(this.input.value).toBe('oldValue');
+ })
+ });
describe('if no config.input is provided', function () {
beforeEach(function () {
this.config = { valueAttribute: {} };
- this.trigger = { value: 'oldValue', tagName: 'INPUT' };
+ this.trigger = { value: 'oldValue', tagName: 'INPUT', hasAttribute: () => {} };
this.inputSetter = { hook: { trigger: this.trigger } };
InputSetter.setInput.call(this.inputSetter, this.config, this.selectedItem);
@@ -151,14 +172,62 @@ describe('InputSetter', function () {
describe('if the input tag is not INPUT', function () {
beforeEach(function () {
- this.input = { textContent: 'oldValue', tagName: 'SPAN' };
+ this.input = { textContent: 'oldValue', tagName: 'SPAN', hasAttribute: () => {} };
this.config = { valueAttribute: {}, input: this.input };
InputSetter.setInput.call(this.inputSetter, this.config, this.selectedItem);
});
it('should set the textContent of the input', function () {
- expect(this.config.input.textContent).toBe(this.newValue);
+ expect(this.input.textContent).toBe(this.newValue);
+ });
+
+ describe('if there is no new value', function () {
+ beforeEach(function () {
+ this.selectedItem = { getAttribute: () => {} };
+ this.input = { textContent: 'oldValue', tagName: 'INPUT', hasAttribute: () => {} };
+ this.config = { valueAttribute: {}, input: this.input };
+ this.inputSetter = { hook: { trigger: {} } };
+ this.newValue = 'newValue';
+
+ spyOn(this.selectedItem, 'getAttribute').and.returnValue(this.newValue);
+
+ InputSetter.setInput.call(this.inputSetter, this.config, this.selectedItem);
+ });
+
+ it('should not set the value of the input', function () {
+ expect(this.input.textContent).toBe('oldValue');
+ });
+ });
+ });
+
+ describe('if there is an inputAttribute', function () {
+ beforeEach(function () {
+ this.selectedItem = { getAttribute: () => {} };
+ this.input = { id: 'oldValue', hasAttribute: () => {}, setAttribute: () => {} };
+ this.inputSetter = { hook: { trigger: {} } };
+ this.newValue = 'newValue';
+ this.inputAttribute = 'id';
+ this.config = {
+ valueAttribute: {},
+ input: this.input,
+ inputAttribute: this.inputAttribute,
+ };
+
+ spyOn(this.selectedItem, 'getAttribute').and.returnValue(this.newValue);
+ spyOn(this.input, 'hasAttribute').and.returnValue(true);
+ spyOn(this.input, 'setAttribute');
+
+ InputSetter.setInput.call(this.inputSetter, this.config, this.selectedItem);
+ });
+
+ it('should call setAttribute', function () {
+ expect(this.input.setAttribute).toHaveBeenCalledWith(this.inputAttribute, this.newValue);
+ });
+
+ it('should not set the value or textContent of the input', function () {
+ expect(this.input.value).not.toBe('newValue');
+ expect(this.input.textContent).not.toBe('newValue');
});
});
});