PHP 8.2.30
Preview: build-feature.spec.ts Size: 2.49 KB
//proc/thread-self/root/home/byroehnu/.trash/node_modules11/adminjs/src/backend/utils/build-feature/build-feature.spec.ts

/* eslint-disable @typescript-eslint/no-empty-function */
import { expect } from 'chai'
import { mergeResourceOptions } from './build-feature.js'
import { Before, After, ActionResponse, ActionHandler } from '../../actions/action.interface.js'

describe('mergeResourceOptions', function () {
  it('chaines before hooks', function () {
    const existingOptions = {
      actions: {
        new: {
          before: function firstBeforeHook() {} as unknown as Before,
          handler: null,
        },
        edit: {
          after: [function firstAfterHook() {} as unknown as After<ActionResponse>],
        },
      },
    }
    const newOptions = {
      actions: {
        new: {
          before: function lastBeforeHook() {} as unknown as Before,
          handler: function lastHandler() {} as unknown as ActionHandler<ActionResponse>,
        },
        edit: {
          after: function lastAfterHook() {} as unknown as After<ActionResponse>,
        },
        newAction: {
          handler: function newHandler() {} as unknown as ActionHandler<ActionResponse>,
        },
      },
    }

    expect(mergeResourceOptions(existingOptions, newOptions)).to.deep.eq({
      actions: {
        new: {
          before: [
            existingOptions.actions.new.before,
            newOptions.actions.new.before,
          ],
          handler: [
            newOptions.actions.new.handler,
          ],
        },
        edit: {
          after: [
            existingOptions.actions.edit.after[0],
            newOptions.actions.edit.after,
          ],
        },
        newAction: {
          handler: [
            newOptions.actions.newAction.handler,
          ],
        },
      },
    })
  })

  it('chaines properties', function () {
    const existingOptions = {
      properties: {
        password: {
          isVisible: true,
          component: 'ala',
        },
      },
    }
    const newOptions = {
      properties: {
        password2: {
          isVisible: false,
          component: 'ela',
        },
      },
    }

    expect(mergeResourceOptions(existingOptions, newOptions)).to.deep.eq({
      properties: {
        ...existingOptions.properties,
        ...newOptions.properties,
      },
    })
  })

  it('merges falsey options', function () {
    const existingOptions = {
      navigation: {
        name: 'db',
      },
    }
    const newOptions = {
      navigation: false,
    }

    expect(mergeResourceOptions(existingOptions, newOptions)).to.deep.eq({
      navigation: false,
    })
  })
})

Directory Contents

Dirs: 0 × Files: 3

Name Size Perms Modified Actions
2.49 KB lrw-r--r-- 2026-02-28 00:32:02
Edit Download
4.45 KB lrw-r--r-- 2026-02-28 00:32:02
Edit Download
35 B lrw-r--r-- 2026-02-28 00:32:28
Edit Download

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