replicationcontrollercard_controller_test.js 3.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

15 16
import ReplicationControllerCardController from 'replicationcontrollerlist/replicationcontrollercard_controller';
import replicationControllerListModule from 'replicationcontrollerlist/replicationcontrollerlist_module';
17

18
describe('Replication controller card controller', () => {
19
  /**
20
   * @type {!ReplicationControllerCardController}
21 22 23 24
   */
  let ctrl;

  beforeEach(() => {
25
    angular.mock.module(replicationControllerListModule.name);
26

27 28
    angular.mock.inject(
        ($controller) => { ctrl = $controller(ReplicationControllerCardController); });
29 30 31 32
  });

  it('should construct details href', () => {
    // given
33
    ctrl.replicationController = {
34 35 36 37 38
      name: 'foo-name',
      namespace: 'foo-namespace',
    };

    // then
39 40
    expect(ctrl.getReplicationControllerDetailHref())
        .toEqual('#/replicationcontrollers/foo-namespace/foo-name');
41
  });
B
bryk 已提交
42 43 44 45 46 47 48

  it('should truncate image name', () => {
    expect(ctrl.shouldTruncate('x')).toBe(false);
    expect(ctrl.shouldTruncate('x'.repeat(32))).toBe(false);
    expect(ctrl.shouldTruncate('x'.repeat(33))).toBe(true);
    expect(ctrl.shouldTruncate('x'.repeat(100))).toBe(true);
  });
49 50 51

  it('should return true when all desired pods are running', () => {
    // given
52
    ctrl.replicationController = {
53 54 55 56 57 58 59 60 61 62 63 64
      pods: {
        running: 0,
        desired: 0,
      },
    };

    // then
    expect(ctrl.areDesiredPodsRunning()).toBeTruthy();
  });

  it('should return false when not all desired pods are running', () => {
    // given
65
    ctrl.replicationController = {
66 67 68 69 70 71 72 73 74
      pods: {
        running: 0,
        desired: 1,
      },
    };

    // then
    expect(ctrl.areDesiredPodsRunning()).toBeFalsy();
  });
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

  it('should return true when at least one replication controller pod has warning', () => {
    // given
    ctrl.replicationController = {
      pods: {
        warnings: [{
          message: "test-error",
          reason: "test-reason",
        }],
      },
    };

    // then
    expect(ctrl.hasWarnings()).toBeTruthy();
  });

  it('should return false when there are no errors related to replication controller pods', () => {
    // given
    ctrl.replicationController = {
      pods: {
        warnings: [],
      },
    };

    // then
    expect(ctrl.hasWarnings()).toBeFalsy();
  });

  it('should return true when there are no warnings and at least one pod is in pending state',
     () => {
       // given
       ctrl.replicationController = {
         pods: {
           warnings: [],
           pending: 1,
         },
       };

       // then
       expect(ctrl.isPending()).toBeTruthy();
     });

  it('should return false when there is warning related to replication controller pods', () => {
    // given
    ctrl.replicationController = {
      pods: {
        warnings: [{
          message: "test-error",
          reason: "test-reason",
        }],
      },
    };

    // then
    expect(ctrl.isPending()).toBeFalsy();
  });

  it('should return false when there are no warnings and there is no pod in pending state', () => {
    // given
    ctrl.replicationController = {
      pods: {
        warnings: [],
        pending: 0,
      },
    };

    // then
    expect(ctrl.isPending()).toBeFalsy();
  });
144
});