# all files / unit/ DemoFolderTest.js

89.09% Statements 147/165
52.94% Branches 18/34
75% Functions 33/44
90.15% Lines 119/132

    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
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    2792×

    2×

    1×

    8×
    2×

    6×

    6×

    6×

    6×

    2×

    2×

    2×

    2×

    2×

    2×

    2×

    6×

    20×

    2×
    1×
    20×

    20×
    20×

    20×

    2×

    18×

    2×

    2×

    2×
    2×
    2×

    2×
    2×
    2×
    2×
    2×
    2×

    2×
    2×
    2×
    2×
    2×
    2×

    2×
    2×
    2×
    2×
    2×
    2×
    2×

    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×

    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×

    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×
    2×

    2×
    14×

    38×

    2×
    1×
    38×

    38×
    38×
    38×
    38×

    38×

    2×

    50×
    30×
    30×
    30×
    30×

    20×

    8×
    8×

    14×
    24×

    6×

    34×
    20×

    34×
    14×

    20×
    20×
    20×

    18×
    18×

    2×

    2×

     /******/ (function(modules) { // webpackBootstrap
    /******/ 	// The module cache
    /******/ 	var installedModules = {};
    /******/
    /******/ 	// The require function
    /******/ 	function __webpack_require__(moduleId) {
    /******/
    /******/ 		// Check if module is in cache
    /******/ 		if(installedModules[moduleId]) {
    /******/ 			return installedModules[moduleId].exports;
    /******/ 		}
    /******/ 		// Create a new module (and put it into the cache)
    /******/ 		var module = installedModules[moduleId] = {
    /******/ 			i: moduleId,
    /******/ 			l: false,
    /******/ 			exports: {}
    /******/ 		};
    /******/
    /******/ 		// Execute the module function
    /******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
    /******/
    /******/ 		// Flag the module as loaded
    /******/ 		module.l = true;
    /******/
    /******/ 		// Return the exports of the module
    /******/ 		return module.exports;
    /******/ 	}
    /******/
    /******/
    /******/ 	// expose the modules object (__webpack_modules__)
    /******/ 	__webpack_require__.m = modules;
    /******/
    /******/ 	// expose the module cache
    /******/ 	__webpack_require__.c = installedModules;
    /******/
    /******/ 	// define getter function for harmony exports
    /******/ 	__webpack_require__.d = function(exports, name, getter) {
    /******/ 		if(!__webpack_require__.o(exports, name)) {
    /******/ 			Object.defineProperty(exports, name, {
    /******/ 				configurable: false,
    /******/ 				enumerable: true,
    /******/ 				get: getter
    /******/ 			});
    /******/ 		}
    /******/ 	};
    /******/
    /******/ 	// getDefaultExport function for compatibility with non-harmony modules
    /******/ 	__webpack_require__.n = function(module) {
    /******/ 		var getter = module && module.__esModule ?
    /******/ 			function getDefault() { return module['default']; } :
    /******/ 			function getModuleExports() { return module; };
    /******/ 		__webpack_require__.d(getter, 'a', getter);
    /******/ 		return getter;
    /******/ 	};
    /******/
    /******/ 	// Object.prototype.hasOwnProperty.call
    /******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
    /******/
    /******/ 	// __webpack_public_path__
    /******/ 	__webpack_require__.p = "/_karma_webpack_/";
    /******/
    /******/ 	// Load entry module and return exports
    /******/ 	return __webpack_require__(__webpack_require__.s = 1);
    /******/ })
    /************************************************************************/
    /******/ ([
    /* 0 */
    /***/ (function(module, __webpack_exports__, __webpack_require__) {

    "use strict";
    var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Eif ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

    function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

    var DemoFile = function () {
      function DemoFile(data) {
        _classCallCheck(this, DemoFile);

        this.path = '';
        this.component = {};

        Object.assign(this, data);
      }

      _createClass(DemoFile, [{
        key: 'getFilename',
        value: function getFilename() {
          return this.path.split('/').pop();
        }
      }, {
        key: 'getParentFolderPath',
        value: function getParentFolderPath() {
          return this.path.split('/').slice(0, -1).join('/');
        }
      }, {
        key: 'toJson',
        value: function toJson() {
          return this.path;
        }
      }]);

      return DemoFile;
    }();

    /* harmony default export */ __webpack_exports__["a"] = (DemoFile);

    /***/ }),
    /* 1 */
    /***/ (function(module, __webpack_exports__, __webpack_require__) {

    "use strict";
    Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
    /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__src_classes_Main_DemoFolder_js__ = __webpack_require__(2);
    /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__src_classes_Main_DemoFile_js__ = __webpack_require__(0);

    describe('DemoFolder', function () {
      it('is initialized', function () {
        var folder = new __WEBPACK_IMPORTED_MODULE_0__src_classes_Main_DemoFolder_js__["a" /* default */]();
        expect(folder.name).toBe('');
        expect(folder.folders).toEqual([]);
        expect(folder.files).toEqual([]);
      });
      it('findOrCreateFolder', function () {
        var folder = new __WEBPACK_IMPORTED_MODULE_0__src_classes_Main_DemoFolder_js__["a" /* default */]();
        var newFolder = folder.findOrCreateFolder('name');
        expect(newFolder.name).toBe('name');
        var oldFolder = folder.findOrCreateFolder('name');
        expect(oldFolder).toBe(newFolder);
      });
      it('addFile', function () {
        var folder = new __WEBPACK_IMPORTED_MODULE_0__src_classes_Main_DemoFolder_js__["a" /* default */]();
        folder.addFile(new __WEBPACK_IMPORTED_MODULE_1__src_classes_Main_DemoFile_js__["a" /* default */](), 'one/two');
        var folderOne = folder.folders[0];
        expect(folderOne.name).toBe('one');
        var folderTwo = folderOne.folders[0];
        expect(folderTwo.name).toBe('two');
      });
      it('addDemoFile', function () {
        var folder = new __WEBPACK_IMPORTED_MODULE_0__src_classes_Main_DemoFolder_js__["a" /* default */]();
        folder.addDemoFile(new __WEBPACK_IMPORTED_MODULE_1__src_classes_Main_DemoFile_js__["a" /* default */]({ path: '/one/two/file.js' }));
        folder.addDemoFile(new __WEBPACK_IMPORTED_MODULE_1__src_classes_Main_DemoFile_js__["a" /* default */]({ path: '/one/two/file1.js' }));
        folder.addDemoFile(new __WEBPACK_IMPORTED_MODULE_1__src_classes_Main_DemoFile_js__["a" /* default */]({ path: '/one/file2.js' }));
        var folderOne = folder.folders[0];
        expect(folderOne.name).toBe('one');
        expect(folderOne.files.length).toBe(1);
        var folderTwo = folderOne.folders[0];
        expect(folderTwo.name).toBe('two');
        expect(folderTwo.files.length).toBe(2);
      });
      it('addDemoFile', function () {
        var folder = new __WEBPACK_IMPORTED_MODULE_0__src_classes_Main_DemoFolder_js__["a" /* default */]();
        folder.addDemoFile(new __WEBPACK_IMPORTED_MODULE_1__src_classes_Main_DemoFile_js__["a" /* default */]({ path: '/one/two/file.js' }));
        folder.addDemoFile(new __WEBPACK_IMPORTED_MODULE_1__src_classes_Main_DemoFile_js__["a" /* default */]({ path: '/one/two/file1.js' }));
        folder.addDemoFile(new __WEBPACK_IMPORTED_MODULE_1__src_classes_Main_DemoFile_js__["a" /* default */]({ path: '/one/file2.js' }));
        var folderOne = folder.folders[0];
        expect(folderOne.name).toBe('one');
        expect(folderOne.files.length).toBe(1);
        var folderTwo = folderOne.folders[0];
        expect(folderTwo.name).toBe('two');
        expect(folderTwo.files.length).toBe(2);
      });
      it('getOpenFolders', function () {
        var folder = new __WEBPACK_IMPORTED_MODULE_0__src_classes_Main_DemoFolder_js__["a" /* default */]();
        folder.addDemoFile(new __WEBPACK_IMPORTED_MODULE_1__src_classes_Main_DemoFile_js__["a" /* default */]({ path: '/one/file1.js' }));
        folder.addDemoFile(new __WEBPACK_IMPORTED_MODULE_1__src_classes_Main_DemoFile_js__["a" /* default */]({ path: '/two/file2.js' }));
        folder.addDemoFile(new __WEBPACK_IMPORTED_MODULE_1__src_classes_Main_DemoFile_js__["a" /* default */]({ path: '/three/file3.js' }));
        expect(folder.getOpenFolders().length).toBe(0);
        folder.folders[0].toggle();
        expect(folder.getOpenFolders().length).toBe(1);
        folder.folders[0].toggle();
        expect(folder.getOpenFolders().length).toBe(0);
        folder.folders[1].toggle();
        folder.folders[2].toggle();
        expect(folder.getOpenFolders().length).toBe(2);
      });
    });

    /***/ }),
    /* 2 */
    /***/ (function(module, __webpack_exports__, __webpack_require__) {

    "use strict";
    /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__DemoFile__ = __webpack_require__(0);
    var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Eif ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

    function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

    var DemoFolder = function () {
      function DemoFolder(data) {
        _classCallCheck(this, DemoFolder);

        this.folders = [];
        this.files = [];
        this.name = '';
        this.isOpen = false;

        Object.assign(this, data);
      }

      _createClass(DemoFolder, [{
        key: 'addFile',
        value: function addFile(node, relativePath) {
          if (relativePath) {
            var folderNameArray = relativePath.split('/');
            var folderName = folderNameArray.shift();
            this.findOrCreateFolder(folderName).addFile(node, folderNameArray.join('/'));
            return;
          }

          this.files.push(node);
        }
      }, {
        key: 'toggle',
        value: function toggle() {
          this.isOpen = !this.isOpen;
          return this.isOpen;
        }
      }, {
        key: 'getOpenFolders',
        value: function getOpenFolders() {
          return this.folders.filter(function (folder) {
            return folder.isOpen;
          }).map(function (folder) {
            return new DemoFolder({
              name: folder.name,
              folders: folder.getOpenFolders()
            });
          });
        }
      }, {
        key: 'findOrCreateFolder',
        value: function findOrCreateFolder(name) {
          var foundFolder = this.folders.find(function (folder) {
            return folder.name === name;
          });
          if (foundFolder) {
            return foundFolder;
          }
          var folder = new DemoFolder({ name: name });
          this.folders.push(folder);
          return folder;
        }
      }, {
        key: 'addDemoFile',
        value: function addDemoFile(node) {
          var relativePath = node.getParentFolderPath().split('/').slice(1).join('/');
          this.addFile(node, relativePath);
        }
      }, {
        key: 'isEmpty',
        value: function isEmpty() {
          return !(this.folders.length || this.files.length);
        }
      }, {
        key: 'toJson',
        value: function toJson() {
          return {
            name: this.name,
            folders: this.folders.map(function (folder) {
              return folder.toJson();
            }),
            files: this.files.map(function (file) {
              return file.toJson();
            })
          };
        }
      }]);

      return DemoFolder;
    }();

    /* harmony default export */ __webpack_exports__["a"] = (DemoFolder);

    /***/ })
    /******/ ]);