HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/quadcode.com/node_modules/intl-tel-input/src/spec/tests/options/hiddenInput.js
"use strict";

describe("hiddenInput: ", function() {

  beforeEach(function() {
    intlSetup();
  });

  afterEach(function() {
    intlTeardown();
  });

  describe("init plugin with hiddenInput returning a string", function() {

    beforeEach(function() {
      input = $("<input>").wrap("div");
      iti = window.intlTelInput(input[0], {
        hiddenInput: () => "phone_full"
      });
    });

    it("creates two hidden inputs", function() {
      expect(getHiddenInputs()).toHaveLength(2);
    });

    it("sets the name of the first hidden input to the returned string", function() {
      expect(getHiddenInputs().eq(0)).toHaveAttr("name", "phone_full");
    });

    it("sets the name of the second hidden input to the returned string with a '_country' suffix", function() {
      expect(getHiddenInputs().eq(1)).toHaveAttr("name", "phone_full_country");
    });
  });

  describe("init plugin with hiddenInput returning an object with correct properties", function() {

    beforeEach(function() {
      input = $("<input>").wrap("div");
      iti = window.intlTelInput(input[0], {
        hiddenInput: () => ({
          phone: "phone_full",
          country: "phone_country"
        })
      });
    });

    it("creates two hidden inputs", function() {
      expect(getHiddenInputs()).toHaveLength(2);
    });

    it("sets the name of the first hidden input to the returned object's 'phone' property", function() {
      expect(getHiddenInputs().eq(0)).toHaveAttr("name", "phone_full");
    });

    it("sets the name of the second hidden input to the returned object's 'country' property", function() {
      expect(getHiddenInputs().eq(1)).toHaveAttr("name", "phone_country");
    });
  });

  describe("init plugin with hiddenInput returning an object with incorrect properties", function() {

    beforeEach(function() {
      input = $("<input name='phone'>").wrap("div");
      iti = window.intlTelInput(input[0], {
        hiddenInput: () => ({
          test: "test",
          data: "data"
        })
      });
    });

    it("creates two hidden inputs", function() {
      expect(getHiddenInputs()).toHaveLength(2);
    });

    it("sets the name of the hidden input to the name of the input", function() {
      expect(getHiddenInputs().eq(0)).toHaveAttr("name", "phone");
    });

    it("sets the name of the second hidden input to the name of the input with a '_country' suffix", function() {
      expect(getHiddenInputs().eq(1)).toHaveAttr("name", "phone_country");
    });
  });

  describe("init plugin with hiddenInput returning an empty object", function() {

    beforeEach(function() {
      input = $("<input name='phone'>").wrap("div");
      iti = window.intlTelInput(input[0], {
        hiddenInput: () => ({})
      });
    });

    it("creates two hidden inputs", function() {
      expect(getHiddenInputs()).toHaveLength(2);
    });

    it("sets the name of the hidden input to the name of the input", function() {
      expect(getHiddenInputs().eq(0)).toHaveAttr("name", "phone");
    });

    it("sets the name of the second hidden input to the name of the input with a '_country' suffix", function() {
      expect(getHiddenInputs().eq(1)).toHaveAttr("name", "phone_country");
    });
  });

  describe("init plugin with no name attribute set on input and hiddenInput returning an empty object", function() {

    beforeEach(function() {
      input = $("<input>").wrap("div");
      iti = window.intlTelInput(input[0], {
        hiddenInput: () => ({})
      });
    });

    it("does not create any hidden inputs", function() {
      expect(getHiddenInputs()).toHaveLength(0);
    });
  });
});