All files cxp-statics.spec.js

100% Statements 52/52
100% Branches 0/0
100% Functions 10/10
100% Lines 52/52
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 1351x   1x   1x   1x                   1x                 1x                 1x 1x 1x   1x     1x 1x         1x 1x 1x     1x 1x       1x 1x 1x     1x 1x       1x 1x 1x     1x 1x       1x           1x 1x 1x     1x 1x         1x 1x 1x     1x 1x       1x 1x 1x     1x 1x       1x 1x 1x     1x 1x       1x           1x 1x 1x    
import { test } from 'blue-tape';
 
import { cxp5Statics, cxp5ItemPaths, cxp6Statics, cxp6ItemPaths } from './cxp-statics';
 
const DEFAULT_CONTEXT = '[BBHOST]';
 
const widget = {
  name: 'my-widget',
  srcDir: '/path/to/widget',
  type: 'widget',
  files: [
    'index.html',
    'assets/icon.png',
  ],
};
 
const item = {
  name: 'my-feature',
  srcDir: '/path/to/item',
  type: 'feature',
  files: [
    'scripts/my-feature.js',
  ],
};
 
const container = {
  name: 'my-container',
  srcDir: '/path/to/container',
  type: 'container',
  files: [
    'config.xml',
  ],
};
 
test('unit :: cxp-statics :: item :: unknown item type', (assert) => {
  assert.throws(() => {
    cxp5ItemPaths({ srcDir: '/path/to/item', type: 'baa', files: ['a'] }, DEFAULT_CONTEXT);
  }, /Unknown item type/, 'show throw');
  assert.end();
});
 
test('unit :: cxp-statics :: item :: widget file paths', (assert) => {
  const itemFiles = {
    '/path/to/widget/index.html': 'widgets/[BBHOST]/my-widget/index.html',
    '/path/to/widget/assets/icon.png': 'widgets/[BBHOST]/my-widget/assets/icon.png',
  };
 
  const cxpItemPaths = cxp5ItemPaths(widget, DEFAULT_CONTEXT);
  assert.deepEqual(cxpItemPaths, itemFiles, 'maps a widget\'s files to cxp paths');
  assert.end();
});
 
test('unit :: cxp-statics :: item :: feature file paths', (assert) => {
  const itemFiles = {
    '/path/to/item/scripts/my-feature.js': 'features/[BBHOST]/my-feature/scripts/my-feature.js',
  };
 
  const cxpItemPaths = cxp5ItemPaths(item, DEFAULT_CONTEXT);
  assert.deepEqual(cxpItemPaths, itemFiles, 'maps a feature\'s files to cxp paths');
  assert.end();
});
 
test('unit :: cxp-statics :: item :: container file paths', (assert) => {
  const itemFiles = {
    '/path/to/container/config.xml': 'containers/[BBHOST]/my-container/config.xml',
  };
 
  const cxpItemPaths = cxp5ItemPaths(container, DEFAULT_CONTEXT);
  assert.deepEqual(cxpItemPaths, itemFiles, 'maps a container\'s files to cxp paths');
  assert.end();
});
 
test('unit :: cxp-statics :: multiple items :: process all', (assert) => {
  const items = [
    widget,
    item,
  ];
  const itemFiles = {
    '/path/to/widget/index.html': 'widgets/[BBHOST]/my-widget/index.html',
    '/path/to/widget/assets/icon.png': 'widgets/[BBHOST]/my-widget/assets/icon.png',
    '/path/to/item/scripts/my-feature.js': 'features/[BBHOST]/my-feature/scripts/my-feature.js',
  };
 
  const cxpItemPaths = cxp5Statics(items, DEFAULT_CONTEXT);
  assert.deepEqual(cxpItemPaths, itemFiles, 'maps all files from all items to cxp paths');
  assert.end();
});
 
test('unit :: cxp-6-statics :: item :: widget file paths', (assert) => {
  const itemFiles = {
    '/path/to/widget/index.html': 'my-widget/index.html',
    '/path/to/widget/assets/icon.png': 'my-widget/assets/icon.png',
  };
 
  const cxpItemPaths = cxp6ItemPaths(widget);
  assert.deepEqual(cxpItemPaths, itemFiles, 'maps a widget\'s files to cxp paths');
  assert.end();
});
 
test('unit :: cxp-6-statics :: item :: feature file paths', (assert) => {
  const itemFiles = {
    '/path/to/item/scripts/my-feature.js': 'my-feature/scripts/my-feature.js',
  };
 
  const cxpItemPaths = cxp6ItemPaths(item);
  assert.deepEqual(cxpItemPaths, itemFiles, 'maps a feature\'s files to cxp paths');
  assert.end();
});
 
test('unit :: cxp-6-statics :: item :: container file paths', (assert) => {
  const itemFiles = {
    '/path/to/container/config.xml': 'my-container/config.xml',
  };
 
  const cxpItemPaths = cxp6ItemPaths(container, DEFAULT_CONTEXT);
  assert.deepEqual(cxpItemPaths, itemFiles, 'maps a container\'s files to cxp paths');
  assert.end();
});
 
test('unit :: cxp-6-statics :: multiple items :: process all', (assert) => {
  const items = [
    widget,
    item,
  ];
  const itemFiles = {
    '/path/to/widget/index.html': 'my-widget/index.html',
    '/path/to/widget/assets/icon.png': 'my-widget/assets/icon.png',
    '/path/to/item/scripts/my-feature.js': 'my-feature/scripts/my-feature.js',
  };
 
  const cxpItemPaths = cxp6Statics(items, DEFAULT_CONTEXT);
  assert.deepEqual(cxpItemPaths, itemFiles, 'maps all files from all items to cxp paths');
  assert.end();
});