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-18.0.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.21.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.20.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.19.1 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.19.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.18.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.17.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.16.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.15.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.14.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.13.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.12.2 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.12.1 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.12.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.11.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.10.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.9.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.8.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.7.0 node_modules/table/test/calculateMaximumColumnWidthIndex.js
govuk_publishing_components-17.6.1 node_modules/table/test/calculateMaximumColumnWidthIndex.js