Code coverage report for src\components\factory\selectFactory.js

# all files / src/components/factory/ selectFactory.js

28.57% Statements 6/21
0% Branches 0/4
20% Functions 1/5
28.57% Lines 6/21

    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
    441×
    1×

    1×

    1×

    1×

    1×

     (function component(ng) {
      ng.module('components').factory('selectFactory', selectFactory);

      selectFactory.$inject = ['checkedButton'];

      function selectFactory(checkedButton) {
        var selectedVoyages = [];

        return {
            selectVoyager: selectVoyager,
            selectAllVoyager: selectAllVoyager
        };

        function selectVoyager(voyage, check) {
            var index;

            if (check) {
              this.selectedVoyages.push(voyage);
            } else {
              index = this.selectedVoyages.indexOf(voyage);

              this.selectedVoyages.splice(index, 1);
            }

            checkedButton.setCheck(this.selectedVoyages.length);
          }

          function selectAllVoyager(check) {
            var index;

            if (check) {
              this.selectedVoyages = [];

              this.testData.data.forEach(function(element) {
                this.selectedVoyages.push(element);
              }, this);
            } else {
              this.selectedVoyages = [];
            }

            checkedButton.setCheck(this.selectedVoyages.length);
          }
      }
    })(angular);