Skip to content

Commit d88c46d

Browse files
author
Pooya Parsa
committed
🙌 Unit Tests
1 parent ed412ea commit d88c46d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1003
-58
lines changed

‎.babelrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"targets": {
5+
"browsers": ["last 2 versions", "safari >= 7"]
6+
},
7+
"modules": "umd"
8+
}]
9+
],
10+
"plugins": [
11+
"transform-object-rest-spread",
12+
["transform-runtime", {
13+
"polyfill": false,
14+
"regenerator": true
15+
}]
16+
]
17+
}

‎__tests__/.eslintrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"env": {
3+
"jest": true
4+
}
5+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {loadFixture, testVM, nextTick, setData} from '../helpers';
2+
import Vue from 'vue/dist/vue.common';
3+
4+
describe('alert', async () => {
5+
beforeEach(loadFixture('alert'));
6+
testVM();
7+
8+
it('check class names', async () => {
9+
const {app: {$refs, $el}} = window;
10+
11+
expect($refs.default_alert).toHaveClass('alert alert-info');
12+
expect($refs.success_alert).toHaveClass('alert alert-success');
13+
});
14+
15+
it('show prop', async () => {
16+
const {app: {$refs, $el}} = window;
17+
18+
// Default is hidden
19+
expect($el.textContent).not.toContain('Dismissible Alert!');
20+
21+
// Make visible by changing visible state
22+
await setData(app, 'showDismissibleAlert', true);
23+
expect($el.textContent).toContain('Dismissible Alert!');
24+
});
25+
26+
it('dismiss button', async () => {
27+
const {app: {$refs, $el}} = window;
28+
const alert = $refs.success_alert;
29+
30+
expect(alert).toHaveClass('alert-dismissible');
31+
32+
const closeBtn = alert.$el.querySelector('.close');
33+
expect(closeBtn).not.toBeNull();
34+
closeBtn.click();
35+
await nextTick();
36+
expect($el.textContent).not.toContain('Success Alert');
37+
});
38+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('badge', async() => {
4+
beforeEach(loadFixture('badge'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('breadcrumb', async() => {
4+
beforeEach(loadFixture('breadcrumb'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('button-group', async() => {
4+
beforeEach(loadFixture('button-group'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('button', async() => {
4+
beforeEach(loadFixture('button'));
5+
testVM();
6+
});

‎__tests__/components/card.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('card', async() => {
4+
beforeEach(loadFixture('card'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('carousel', async() => {
4+
beforeEach(loadFixture('carousel'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('collapse', async() => {
4+
beforeEach(loadFixture('collapse'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('dropdown', async() => {
4+
beforeEach(loadFixture('dropdown'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('form-checkbox', async() => {
4+
beforeEach(loadFixture('form-checkbox'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('form-fieldset', async() => {
4+
beforeEach(loadFixture('form-fieldset'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('form-file', async() => {
4+
beforeEach(loadFixture('form-file'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('form-input', async() => {
4+
beforeEach(loadFixture('form-input'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('form-radio', async() => {
4+
beforeEach(loadFixture('form-radio'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('form-select', async() => {
4+
beforeEach(loadFixture('form-select'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('jumbotron', async() => {
4+
beforeEach(loadFixture('jumbotron'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('list-group', async() => {
4+
beforeEach(loadFixture('list-group'));
5+
testVM();
6+
});

‎__tests__/components/media.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('media', async() => {
4+
beforeEach(loadFixture('media'));
5+
testVM();
6+
});

‎__tests__/components/modal.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('modal', async() => {
4+
beforeEach(loadFixture('modal'));
5+
testVM();
6+
});

‎__tests__/components/nav.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('nav', async() => {
4+
beforeEach(loadFixture('nav'));
5+
testVM();
6+
});

‎__tests__/components/navbar.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('navbar', async() => {
4+
beforeEach(loadFixture('navbar'));
5+
testVM();
6+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('pagination', async() => {
4+
beforeEach(loadFixture('pagination'));
5+
testVM();
6+
});

‎__tests__/components/popover.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('popover', async() => {
4+
beforeEach(loadFixture('popover'));
5+
testVM();
6+
});

‎__tests__/components/progress.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('progress', async() => {
4+
beforeEach(loadFixture('progress'));
5+
testVM();
6+
});

‎__tests__/components/tab.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('tab', async() => {
4+
beforeEach(loadFixture('tab'));
5+
testVM();
6+
});

‎__tests__/components/table.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('table', async() => {
4+
beforeEach(loadFixture('table'));
5+
testVM();
6+
});

‎__tests__/components/tooltip.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import {loadFixture, testVM} from '../helpers';
2+
3+
describe('tooltip', async() => {
4+
beforeEach(loadFixture('tooltip'));
5+
testVM();
6+
});

‎__tests__/helpers.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {readFileSync} from 'fs';
2+
import {resolve} from 'path';
3+
import Vue from 'vue/dist/vue.common';
4+
import BootstrapVue from '../lib';
5+
6+
const readFile = (path) => String(readFileSync(resolve(__dirname, '../examples', path)));
7+
8+
export function loadFixture(name) {
9+
const template = readFile(`${name}/demo.html`);
10+
const js = readFile(`${name}/demo.js`);
11+
12+
return async () => {
13+
// Mount template
14+
document.body.innerHTML = template;
15+
16+
// Install Vue and BootstrapVue
17+
window.Vue = Vue;
18+
Vue.use(BootstrapVue);
19+
20+
// Eval js
21+
eval(js);
22+
23+
// Await for Vue render
24+
await Vue.nextTick();
25+
};
26+
}
27+
28+
export async function testVM() {
29+
it(`vm mounts`, async () => {
30+
return expect(window.app.$el).toBeDefined();
31+
});
32+
}
33+
34+
export async function nextTick() {
35+
await Vue.nextTick();
36+
}
37+
38+
export async function setData(app, key, value) {
39+
app[key] = value;
40+
await nextTick();
41+
}
42+
43+
// Extend Jest marchers
44+
expect.extend({
45+
toHaveClass(vnode, className) {
46+
return {
47+
message: `expected to have class '${className}'`,
48+
pass: vnode.$el._prevClass.indexOf(className) !== -1,
49+
};
50+
},
51+
isComponent(vnode, component) {
52+
return {
53+
message: `expected to be ${component}`,
54+
pass: vnode.$el.constructor.name === component
55+
};
56+
},
57+
});
File renamed without changes.
File renamed without changes.

‎examples/alert/demo.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<div id="app">
2+
<b-alert show
3+
ref="default_alert"
4+
>
5+
Default Alert
6+
</b-alert>
7+
8+
<b-alert ref="success_alert"
9+
variant="success"
10+
dismissible
11+
show
12+
>
13+
Success Alert
14+
</b-alert>
15+
16+
<b-alert variant="danger"
17+
dismissible
18+
:show="showDismissibleAlert"
19+
@dismissed="showDismissibleAlert=false"
20+
>
21+
Dismissible Alert!
22+
</b-alert>
23+
24+
<b-alert :show="dismissCountDown"
25+
dismissible
26+
variant="warning"
27+
@dismiss-count-down="countDownChanged"
28+
>
29+
This alert will dismiss after {{dismissCountDown}} seconds...
30+
</b-alert>
31+
32+
<b-btn @click="showAlert" variant="info" class="m-1">Show alert with count-down timer</b-btn>
33+
34+
<b-btn @click="showDismissibleAlert=true" variant="info" class="m-1" ref="dismissible_alert_btn">
35+
Show dismissible alert ({{showDismissibleAlert?'visible':'hidden'}})
36+
</b-btn>
37+
</div>

‎examples/alerts/demo.js renamed to ‎examples/alert/demo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ window.app = new Vue({
1212
this.dismissCountDown = 5;
1313
}
1414
}
15-
});
15+
});

0 commit comments

Comments
 (0)