Skip to content

Commit

Permalink
fix whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
bigopon committed Sep 3, 2017
1 parent 9ff2594 commit 8e28102
Showing 1 changed file with 54 additions and 54 deletions.
108 changes: 54 additions & 54 deletions test/focus.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,105 +8,105 @@ describe('focus', () => {
var focus, taskQueue, element, otherElement, observerLocator;

function hasElementFocus() {
return document.activeElement === element;
return document.activeElement === element;
}

function setBindedFocusValue(value) {
focus.value = value;
focus.valueChanged(value);
focus.value = value;
focus.valueChanged(value);
}

beforeEach(() => {
element = document.createElement('input');
document.body.appendChild(element);
element = document.createElement('input');
document.body.appendChild(element);

otherElement = document.createElement('input');
document.body.appendChild(otherElement);
otherElement = document.createElement('input');
document.body.appendChild(otherElement);

taskQueue = new TaskQueue();
taskQueue = new TaskQueue();

observerLocator = {
getObserver() {
return {
hasSubscribers() { return true; }
}
observerLocator = {
getObserver() {
return {
hasSubscribers() { return true; }
}
};
}
};

focus = new Focus(element, taskQueue, observerLocator);
focus = new Focus(element, taskQueue, observerLocator);
});

it('should give initial focus when attached and value is true', () => {
setBindedFocusValue(true);
focus.attached();
setBindedFocusValue(true);
focus.attached();

taskQueue.flushMicroTaskQueue();
expect(hasElementFocus()).toBe(true);
taskQueue.flushMicroTaskQueue();
expect(hasElementFocus()).toBe(true);
});

it('should not give initial focus when attached and value is false', () => {
focus.value = false;
focus.attached();
focus.value = false;
focus.attached();

taskQueue.flushMicroTaskQueue();
expect(hasElementFocus()).toBe(false);
taskQueue.flushMicroTaskQueue();
expect(hasElementFocus()).toBe(false);
});

it('should give focus when value is set to true', () => {
focus.attached();
focus.attached();

setBindedFocusValue(true);
setBindedFocusValue(true);

taskQueue.flushMicroTaskQueue();
expect(hasElementFocus()).toBe(true);
taskQueue.flushMicroTaskQueue();
expect(hasElementFocus()).toBe(true);
});

it('should remove focus when value is set to false', () => {
focus.attached();
setBindedFocusValue(true);
focus.attached();
setBindedFocusValue(true);

setBindedFocusValue(false);
setBindedFocusValue(false);

expect(hasElementFocus()).toBe(false);
expect(hasElementFocus()).toBe(false);
});

it('should set focus value to true when element gets focus', () => {
focus.attached();
setBindedFocusValue(false);
focus.attached();
setBindedFocusValue(false);

element.dispatchEvent(DOM.createCustomEvent('focus'));
element.dispatchEvent(DOM.createCustomEvent('focus'));

expect(focus.value).toBe(true);
expect(focus.value).toBe(true);
});

it('should set focus value to false when element loses focus', () => {
focus.attached();
setBindedFocusValue(true);
focus.attached();
setBindedFocusValue(true);

otherElement.focus();
element.dispatchEvent(DOM.createCustomEvent('blur'));
otherElement.focus();
element.dispatchEvent(DOM.createCustomEvent('blur'));

expect(focus.value).toBe(false);
expect(focus.value).toBe(false);
});

it('should not set focus value to true when element gets focus and behavior is detached', () => {
focus.attached();
focus.detached();
setBindedFocusValue(false);
focus.attached();
focus.detached();
setBindedFocusValue(false);

element.dispatchEvent(DOM.createCustomEvent('focus'));
element.dispatchEvent(DOM.createCustomEvent('focus'));

expect(focus.value).toBe(false);
expect(focus.value).toBe(false);
});

it('should not set focus value to false when element loses focus and behavior is detached', () => {
focus.attached();
focus.detached();
setBindedFocusValue(true);
focus.attached();
focus.detached();
setBindedFocusValue(true);

element.dispatchEvent(DOM.createCustomEvent('blur'));
element.dispatchEvent(DOM.createCustomEvent('blur'));

expect(focus.value).toBe(true);
expect(focus.value).toBe(true);
});

describe('when observer does not have subscribers', () => {
Expand Down Expand Up @@ -135,10 +135,10 @@ describe('focus', () => {
});

afterEach(() => {
focus.detached();
element.parentNode.removeChild(element);
focus.detached();
element.parentNode.removeChild(element);

focus = null;
element = null;
focus = null;
element = null;
});
});

0 comments on commit 8e28102

Please sign in to comment.