All files bim-select-config.provider.js

96.3% Statements 26/27
96.3% Branches 26/27
100% Functions 3/3
96.3% Lines 26/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 961x   1x                                           121x                                       15x       15x   3x 2x   1x   2x     3x 2x   1x   2x     3x 2x   1x   2x     3x 2x   1x   2x     3x 2x   1x   2x         11x      
exports.name = 'bimSelectConfig';
 
const config = {
    diacritics: null,
    itemTemplateUrl: null,
    placeholder: null,
    sorter: null,
    selectedItemTemplateUrl: null
};
 
/**
 * @ngdoc provider
 * @name bimSelectConfigProvider
 * @description
 * Use bimSelectConfigProvider to be able to reuse a set of configuration
 * options for all instances of `bimSelect` in an application.
 *
 * @example
 * const randomSorter = () => 2 * Math.random() - 1;
 *
 * angular.module('app').config(function(bimSelectConfigProvider) {
 *     bimSelectConfigProvider.set('sorter', randomSorter);
 * });
 */
exports.impl = class bimSelectConfigProvider {
    /**
     * @ngdoc method
     * @name bimSelectConfigProvider.set
     * @description
     * Set global default values for these options:
     *
     * - `placeholder`: Must be a string.
     * - `sorter`: Must be a function.
     * - `itemTemplateUrl`: Must be a string.
     * - `diacritics`: Must be a string.
     * - `selectedItemTemplateUrl`: Must be a string.
     *
     * For details on the values, see the documentation for `bimSelect`.
     * @param {String} option
     *   The name of the option to set.
     * @param {Any} value
     *   The value for the option.
     */
    set(option, value) {
        Iif (!Object.keys(config).includes(option)) {
            throw new Error(`Invalid configuration name: ${option}`);
        }
 
        switch (option) {
            case 'sorter':
                if (value === null || typeof value === 'function') {
                    config[option] = value;
                } else {
                    throw new Error('The sorter value must be a function');
                }
                break;
 
            case 'placeholder':
                if (value === null || typeof value === 'string') {
                    config[option] = value;
                } else {
                    throw new Error('The placeholder value must be a string');
                }
                break;
 
            case 'diacritics':
                if (value === null || typeof value === 'string') {
                    config[option] = value;
                } else {
                    throw new Error('The diacritics value must be a string');
                }
                break;
 
            case 'itemTemplateUrl':
                if (value === null || typeof value === 'string') {
                    config[option] = value;
                } else {
                    throw new Error('The itemTemplateUrl value must be a string');
                }
                break;
 
            case 'selectedItemTemplateUrl':
                if (value === null || typeof value === 'string') {
                    config[option] = value;
                } else {
                    throw new Error('The selectedItemTemplateUrl value must be a string');
                }
                break;
        }
    }
 
    $get() {
        return Object.freeze(Object.assign({}, config));
    }
};