File size: 2,089 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { expect } from 'chai'

import layoutTemplate from './layout-template.js'
import AdminJS from '../adminjs.js'
import { BrandingOptions } from '../adminjs-options.interface.js'

describe('layoutTemplate', function () {
  context('AdminJS with branding options set as a function', function () {
    const companyName = 'Dynamic Company'
    let html: string

    beforeEach(async function () {
      const adminJs = new AdminJS({
        branding: async () => ({ companyName }),
      })

      html = await layoutTemplate(adminJs, undefined, '/')
    })

    it('renders default company name', function () {
      expect(html).to.contain(companyName)
    })

    it('links to global bundle', async function () {
      expect(html).to.contain('global.bundle.js')
    })
  })

  describe('AdminJS with branding options given', function () {
    const branding = {
      withMadeWithLove: false,
      companyName: 'Other name',
      favicon: '/someImage.png',
    } as BrandingOptions
    let html: string

    beforeEach(async function () {
      const adminJs = new AdminJS({ branding })

      html = await layoutTemplate(adminJs, undefined, '/')
    })

    it('renders company name', function () {
      expect(html).to.contain(branding.companyName)
    })

    it('renders favicon', function () {
      expect(html).to.contain(
        `<link rel="shortcut icon" type="image/png" href="${branding.favicon}" />`,
      )
    })
  })

  context('custom styles and scripts were defined in AdminJS options', function () {
    let html: string
    const scriptUrl = 'http://somescript.com'
    const styleUrl = 'http://somestyle.com'

    beforeEach(async function () {
      const adminJs = new AdminJS({
        assets: {
          styles: [styleUrl],
          scripts: [scriptUrl],
        },
      })

      html = await layoutTemplate(adminJs, undefined, '/')
    })

    it('adds styles to the head section', function () {
      expect(html).to.contain(styleUrl)
    })

    it('adds scripts to the body', function () {
      expect(html).to.contain(scriptUrl)
    })
  })
})