Sha256: bcf887de83c0eb9dbbe4aca35351a3e1d4caaebb4de565edccdb0294a29d088b

Contents?: true

Size: 1.45 KB

Versions: 46

Compression:

Stored size: 1.45 KB

Contents

import {
    expect
} from 'chai';
import chalk from 'chalk';
import calculateMaximumColumnWidthIndex from './../src/calculateMaximumColumnWidthIndex';

describe('calculateMaximumColumnWidthIndex', () => {
  it('throws an error when attempting to calculate maximum column value index for an empty data set', () => {
    expect(() => {
      calculateMaximumColumnWidthIndex([]);
    }).to.throw(Error, 'Dataset must have at least one row.');
  });
  it('calculates the maximum column value index', () => {
    const maximumColumnValueIndex = calculateMaximumColumnWidthIndex([
      [
        '',
        'a',
        'b',
        'c'
      ],
      [
        '',
        'a',
        'bbbbbbbbbb',
        'c'
      ],
      [
        '',
        '',
        'b',
        'ccccc'
      ]
    ]);

    expect(maximumColumnValueIndex).to.deep.equal([0, 1, 10, 5]);
  });
  context('cell values contain ANSI codes', () => {
    it('uses visual width of the string', () => {
      const maximumColumnValueIndex = calculateMaximumColumnWidthIndex([
        [
          chalk.red('aaaaa')
        ]
      ]);

      expect(maximumColumnValueIndex[0]).to.equal(5);
    });
  });
  context('cell values contain fullwidth characters', () => {
    it('uses visual width of the string', () => {
      const maximumColumnValueIndex = calculateMaximumColumnWidthIndex([
        [
          chalk.red('古')
        ]
      ]);

      expect(maximumColumnValueIndex[0]).to.equal(2);
    });
  });
});

Version data entries

46 entries across 46 versions & 3 rubygems

Version Path
govuk_publishing_components-17.6.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.5.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.4.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.3.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.2.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.1.1 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.1.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.0.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-16.29.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-16.28.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-16.27.1 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-16.27.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-16.26.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-16.25.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-16.24.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-16.23.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-16.22.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-16.21.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-16.20.1 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-16.20.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js