Skip to content

Commit

Permalink
Add container test
Browse files Browse the repository at this point in the history
  • Loading branch information
dixso committed Dec 27, 2016
1 parent 8fc2c91 commit 79c2e1b
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 3 deletions.
84 changes: 84 additions & 0 deletions src/custombox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,4 +620,88 @@ describe('Custombox', () => {
}, 1000);
});
});

describe('Container', () => {
let originalTimeout;
beforeEach(() => {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
});

beforeEach(() => {
for (let i = 1; i < 3; i++) {
let div = document.createElement('div');
div.innerHTML = `Lorem ipmsum (${i}) ...`;
div.setAttribute('id', `foo-${i}`);
document.body.appendChild(div);
}

let container = document.createElement('div');
container.setAttribute('id', 'container');
while (document.body.firstChild) {
container.appendChild(document.body.firstChild);
}
document.body.appendChild(container);
});

beforeEach(() => {
(jasmine as any).Ajax.install();
});

afterEach(()=> {
for (let i = 1; i < 3; i++) {
let elem = document.getElementById(`foo-${i}`);
elem.parentNode.removeChild(elem);
}

// custombox-content
let contents = document.querySelectorAll('.custombox-content');
for (let i = 0, t = contents.length; i < t; i++) {
contents[i].parentNode.removeChild(contents[i]);
}

// custombox-overlay
let overlays = document.querySelectorAll('.custombox-overlay');
for (let i = 0, t = overlays.length; i < t; i++) {
overlays[i].parentNode.removeChild(overlays[i]);
}

delete Custombox;

jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;

(jasmine as any).Ajax.uninstall();
});

it('should have put a container selector', (done) => {
new (Custombox as any).modal({
content: {
effect: 'makeway',
target: '#foo-1',
},
container: {
target: '#container'
}
}).open();

setTimeout(() => {
expect(hasElement('#container.custombox-container')).toBe(true);
done();
}, 200);
});

it('should have put a container automatically', (done) => {
new (Custombox as any).modal({
content: {
effect: 'makeway',
target: '#foo-1',
},
}).open();

setTimeout(() => {
expect(hasElement('.custombox-container')).toBe(true);
done();
}, 200);
});
});
});
12 changes: 9 additions & 3 deletions src/custombox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Custombox {
interface OptionsSchema {
overlay: OverlaySchema;
content: ContentSchema;
container: string;
container: ContainerSchema;
}

interface OverlaySchema extends Speed, Callback {
Expand All @@ -26,6 +26,10 @@ namespace Custombox {
id: string;
}

interface ContainerSchema {
target: string;
}

interface Speed {
speedIn: number;
speedOut: number;
Expand Down Expand Up @@ -102,7 +106,9 @@ namespace Custombox {
onComplete: null,
onClose: null,
};
container = null;
container = {
target: null
};
}

class Options extends DefaultSchema {
Expand All @@ -125,7 +131,7 @@ namespace Custombox {
throw new Error(`You need to instantiate Custombox when the document is fully loaded.`);
}

const selector: any = document.querySelector(this.options.container);
const selector: any = document.querySelector(this.options.container.target);
if (selector) {
this.element = selector;
this.addSimpleClass();
Expand Down

0 comments on commit 79c2e1b

Please sign in to comment.