1 | import path from 'path'
|
2 |
|
3 | import AdminBro from './admin-bro'
|
4 |
|
5 | import BaseDatabase from './backend/adapters/base-database'
|
6 | import BaseResource from './backend/adapters/base-resource'
|
7 |
|
8 | describe('AdminBro', function () {
|
9 | beforeEach(function () {
|
10 | AdminBro.registeredAdapters = []
|
11 | })
|
12 |
|
13 | describe('#constructor', function () {
|
14 | it('sets default root path when no given', function () {
|
15 | expect(new AdminBro().options.rootPath).to.equal('/admin')
|
16 | })
|
17 | })
|
18 |
|
19 | describe('.AdminBro.registerAdapter', function () {
|
20 | beforeEach(function () {
|
21 | class Database extends BaseDatabase {}
|
22 | class Resource extends BaseResource {}
|
23 | this.DatabaseAdapter = { Database, Resource }
|
24 | })
|
25 |
|
26 | it('adds given adapter to list off all available adapters', function () {
|
27 | AdminBro.registerAdapter(this.DatabaseAdapter)
|
28 | expect(AdminBro.registeredAdapters).to.have.lengthOf(1)
|
29 | })
|
30 |
|
31 | it('throws an error when adapter is not full', function () {
|
32 | expect(() => {
|
33 | AdminBro.registerAdapter({ Resource: AdminBro.BaseResource })
|
34 | }).to.throw('Adapter has to have both Database and Resource')
|
35 | })
|
36 |
|
37 | it('throws an error when adapter has elements not being subclassed from base adapter', function () {
|
38 | expect(() => {
|
39 | AdminBro.registerAdapter({ Resource: {}, Database: {} })
|
40 | }).to.throw('Adapter elements has to be subclassess of AdminBro.BaseResource and AdminBro.BaseDatabase')
|
41 | })
|
42 | })
|
43 |
|
44 | describe('.require', function () {
|
45 | afterEach(function () {
|
46 | AdminBro.UserComponents = {}
|
47 | })
|
48 | context('file exists', function () {
|
49 | beforeEach(function () {
|
50 | this.result = AdminBro.bundle('../spec/fixtures/example-component')
|
51 | })
|
52 |
|
53 | it('adds given file to a UserComponents object', function () {
|
54 | expect(Object.keys(AdminBro.UserComponents)).to.have.lengthOf(1)
|
55 | })
|
56 |
|
57 | it('returns uniq id', function () {
|
58 | expect(AdminBro.UserComponents[this.result]).not.to.be.undefined
|
59 | expect(this.result).to.be.a('string')
|
60 | })
|
61 |
|
62 | it('converts relative path to absolute path', function () {
|
63 | expect(
|
64 | AdminBro.UserComponents[this.result],
|
65 | ).to.equal(path.join(__dirname, '../spec/fixtures/example-component'))
|
66 | })
|
67 | })
|
68 |
|
69 | it('throws an error when component doesn\t exist', function () {
|
70 | expect(() => {
|
71 | AdminBro.bundle('./fixtures/example-components')
|
72 | }).to.throw().property('name', 'ConfigurationError')
|
73 | })
|
74 | })
|
75 | })
|