PHP 8.2.30
Preview: get-navigation.spec.ts Size: 2.04 KB
//home/byroehnu/easepay.easetack.com/node_modules/adminjs/src/backend/decorators/resource/utils/get-navigation.spec.ts

import { expect } from 'chai'

import { ResourceOptions } from '../resource-options.interface.js'
import { getNavigation, DatabaseData, getIcon } from './get-navigation.js'

const databaseName = 'mysql-database'
const databaseType = 'MySQL'

const defaultDatabase: DatabaseData = {
  databaseName: () => databaseName,
  databaseType: () => databaseType,
}

const mappedIcon = getIcon(databaseType)

describe('.getNavigation', () => {
  let resourceOptions: ResourceOptions

  beforeEach(() => {
    resourceOptions = {}
  })

  it('returns parent with icon when no options are given', () => {
    resourceOptions.navigation = undefined

    expect(getNavigation(resourceOptions, defaultDatabase)).to.deep.eq({
      icon: mappedIcon,
      name: databaseName,
      show: true,
    })
  })

  it('returns null when options are set to null', () => {
    resourceOptions.navigation = null

    expect(getNavigation(resourceOptions, defaultDatabase)).to.be.null
  })

  it('returns show false when options are set to false', () => {
    resourceOptions.navigation = false

    expect(getNavigation(resourceOptions, defaultDatabase)).to.deep.eq({
      name: null,
      icon: '',
      show: false,
    })
  })

  it('returns parent with a default icon when options was set as a string', () => {
    const parentName = 'my navigation name'
    resourceOptions.navigation = parentName

    expect(getNavigation(resourceOptions, defaultDatabase)).to.deep.eq({
      icon: mappedIcon,
      name: parentName,
      show: true,
    })
  })

  it('returns empty parent with an icon when this was set in options', () => {
    const icon = 'Car'
    resourceOptions.navigation = { icon, name: null }

    expect(getNavigation(resourceOptions, defaultDatabase)).to.deep.eq({
      icon,
      name: null,
      show: true,
    })
  })

  it('works the same with old parent option', () => {
    const icon = 'Car'
    resourceOptions.parent = { icon, name: null }

    expect(getNavigation(resourceOptions, defaultDatabase)).to.deep.eq({
      icon,
      name: null,
      show: true,
    })
  })
})

Directory Contents

Dirs: 0 × Files: 10

Name Size Perms Modified Actions
127 B lr--r--r-- 2026-03-14 01:49:20
Edit Download
1.65 KB lrw-r--r-- 2026-02-28 00:32:04
Edit Download
7.02 KB lrw-r--r-- 2026-02-28 00:32:04
Edit Download
3.68 KB lrw-r--r-- 2026-02-28 00:32:06
Edit Download
1.15 KB lrw-r--r-- 2026-02-28 00:32:14
Edit Download
813 B lrw-r--r-- 2026-02-28 00:32:14
Edit Download
2.04 KB lrw-r--r-- 2026-02-28 00:32:20
Edit Download
1.62 KB lrw-r--r-- 2026-02-28 00:32:20
Edit Download
1.02 KB lrw-r--r-- 2026-02-28 00:32:20
Edit Download
236 B lrw-r--r-- 2026-02-28 00:32:28
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).