<commit_before>var Backbone = require('backbone');
var CDB = require('cartodb.js');
var InputColorCategories = require('../../../../../../../../../javascripts/cartodb3/components/form-components/editors/fill/input-color/input-categories/input-color-categories');
var ConfigModel = require('../../../../../../../../../javascripts/cartodb3/data/config-model');
var UserModel = require('../../../../../../../../../javascripts/cartodb3/data/user-model');
var rampList = require('cartocolor');

describe('components/form-components/editors/fill/input-color/input-categories/input-color-categories', function () {
  beforeEach(function () {
    CDB.SQL.prototype.execute = function (query, vars, params) {
      params && params.success();
    };

    this.configModel = new ConfigModel({
      base_url: '/u/pepe',
      user_name: 'pepe'
    });

    this.userModel = new UserModel({}, {
      configModel: this.configModel,
      feature_flags: []
    });

    this.model = new Backbone.Model({
      domain: [0, '', 'Three'],
      range: ['#E7E1EF', '#C994C7', '#DD1C77'],
      images: ['', '', ''],
      attribute: 'column1',
      quantification: 'jenks'
    });

    this.view = new InputColorCategories(({
      model: this.model,
      userModel: this.userModel,
      modals: {},
      query: 'SELECT * FROM table',
      columns: [
        { label: 'column1', type: 'number' },
        { label: 'column2', type: 'number' },
        { label: 'column3', type: 'number' }
      ],
      configModel: this.configModel
    }));

    this.view.render();
  });

  it('should render properly', function () {
    expect(this.view.$el.html()).toContain('column1');

    expect(this.view.$('.js-listItem:eq(0)').text()).toContain('0');
    expect(this.view.$('.RampItem-bar:eq(0)').css('background-color')).toBe('rgb(231, 225, 239)');

    expect(this.view.$('.js-listItem:eq(1)').text()).toContain('null');
    expect(this.view.$('.RampItem-bar:eq(1)').css('background-color')).toBe('rgb(201, 148, 199)');

    expect(this.view.$('.js-listItem:eq(2)').text()).toContain('Three');
    expect(this.view.$('.RampItem-bar:eq(2)').css('background-color')).toBe('rgb(221, 28, 119)');

    expect(this.view.$('.js-loader').hasClass('is-hidden')).toBeTruthy();
    expect(this.view.$('.js-content').hasClass('is-hidden')).toBeFalsy();

    expect(this.view.$('.js-label').text()).toBe('column1');
    expect(this.view.$('.js-back').length).toBe(1);
  });

  it('should hide the title label back arrow', function () {
    this.view.$('.js-listItem:eq(0)').click();
    expect(this.view.$('.js-prevStep').attr('style')).toBe('display: none;');
    expect(this.view.$('.js-label').text()).not.toBe('column1');
    expect(this.view.$('.js-back').length).toBe(2);
  });

  it('should show the loader', function () {
    spyOn(this.view, '_startLoader');
    this.model.set('attribute', 'column2');
    expect(this.view._startLoader).toHaveBeenCalled();
  });

  describe('with booleans', function () {
    beforeEach(function () {
      this.model = new Backbone.Model({
        domain: [true, false, null, false, null],
        range: ['#E7E1EF', '#C994C7', '#DD1C77'],
        images: ['', '', ''],
        attribute: 'column1',
        attribute_type: 'boolean',
        quantification: 'jenks'
      });

      this.view = new InputColorCategories(({
        model: this.model,
        modals: {},
        userModel: this.userModel,
        query: 'SELECT * FROM table',
        columns: [
          { label: 'column1', type: 'boolean' },
          { label: 'column2', type: 'number' },<commit_msg>Fixed test in PhantomJS<commit_after>var Backbone = require('backbone');
var CDB = require('cartodb.js');
var InputColorCategories = require('../../../../../../../../../javascripts/cartodb3/components/form-components/editors/fill/input-color/input-categories/input-color-categories');
var ConfigModel = require('../../../../../../../../../javascripts/cartodb3/data/config-model');
var UserModel = require('../../../../../../../../../javascripts/cartodb3/data/user-model');
var rampList = require('cartocolor');

describe('components/form-components/editors/fill/input-color/input-categories/input-color-categories', function () {
  beforeEach(function () {
    CDB.SQL.prototype.execute = function (query, vars, params) {
      params && params.success();
    };

    this.configModel = new ConfigModel({
      base_url: '/u/pepe',
      user_name: 'pepe'
    });

    this.userModel = new UserModel({}, {
      configModel: this.configModel,
      feature_flags: []
    });

    this.model = new Backbone.Model({
      domain: [0, '', 'Three'],
      range: ['#E7E1EF', '#C994C7', '#DD1C77'],
      images: ['', '', ''],
      attribute: 'column1',
      quantification: 'jenks'
    });

    this.view = new InputColorCategories(({
      model: this.model,
      userModel: this.userModel,
      modals: {},
      query: 'SELECT * FROM table',
      columns: [
        { label: 'column1', type: 'number' },
        { label: 'column2', type: 'number' },
        { label: 'column3', type: 'number' }
      ],
      configModel: this.configModel
    }));

    this.view.render();
  });

  it('should render properly', function () {
    expect(this.view.$el.html()).toContain('column1');

    expect(this.view.$('.js-listItem:eq(0)').text()).toContain('0');
    expect(this.view.$('.RampItem-bar:eq(0)').css('background-color')).toBe('rgb(231, 225, 239)');

    expect(this.view.$('.js-listItem:eq(1)').text()).toContain('null');
    expect(this.view.$('.RampItem-bar:eq(1)').css('background-color')).toBe('rgb(201, 148, 199)');

    expect(this.view.$('.js-listItem:eq(2)').text()).toContain('Three');
    expect(this.view.$('.RampItem-bar:eq(2)').css('background-color')).toBe('rgb(221, 28, 119)');

    expect(this.view.$('.js-loader').hasClass('is-hidden')).toBeTruthy();
    expect(this.view.$('.js-content').hasClass('is-hidden')).toBeFalsy();

    expect(this.view.$('.js-label').text()).toBe('column1');
    expect(this.view.$('.js-back').length).toBe(1);
  });

  it('should hide the title label back arrow', function () {
    this.view.$('.js-listItem:eq(0)').click();
    expect(this.view.$('.js-prevStep').attr('style')).toContain('display: none;');
    expect(this.view.$('.js-label').text()).not.toBe('column1');
    expect(this.view.$('.js-back').length).toBe(2);
  });

  it('should show the loader', function () {
    spyOn(this.view, '_startLoader');
    this.model.set('attribute', 'column2');
    expect(this.view._startLoader).toHaveBeenCalled();
  });

  describe('with booleans', function () {
    beforeEach(function () {
      this.model = new Backbone.Model({
        domain: [true, false, null, false, null],
        range: ['#E7E1EF', '#C994C7', '#DD1C77'],
        images: ['', '', ''],
        attribute: 'column1',
        attribute_type: 'boolean',
        quantification: 'jenks'
      });

      this.view = new InputColorCategories(({
        model: this.model,
        modals: {},
        userModel: this.userModel,
        query: 'SELECT * FROM table',
        columns: [
          { label: 'column1', type: 'boolean' },
          { label: 'column2', type: 'number' },
{'fraction_non_alphanumeric': 0.22868270969536791, 'fraction_numerical': 0.019195993879538183, 'mean_word_length': 3.085227272727273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7156979', 'n_tokens_mistral': 2389, 'n_tokens_neox': 2301, 'n_words': 349}