deployfromsettings_controller_test.js 2.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// 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.

import DeployFromSettingController from 'deploy/deployfromsettings_controller';
import deployModule from 'deploy/deploy_module';
17
import DeployLabel from 'deploy/deploylabel';
18 19 20 21 22 23 24

describe('DeployFromSettings controller', () => {
  let ctrl;

  beforeEach(() => {
    angular.mock.module(deployModule.name);

25 26
    angular.mock.inject(($controller) => {
      ctrl = $controller(DeployFromSettingController, {}, {namespaces: []});
27 28 29 30
    });
  });

  it('should return empty string when containerImage is undefined', () => {
31
    // given
32
    ctrl.containerImage = undefined;
33 34 35 36 37 38

    // when
    let result = ctrl.getContainerImageVersion_();

    // then
    expect(result).toEqual('');
39 40 41
  });

  it('should return empty string when containerImage is empty', () => {
42
    // given
43
    ctrl.containerImage = '';
44 45 46 47 48 49

    // when
    let result = ctrl.getContainerImageVersion_();

    // then
    expect(result).toEqual('');
50 51 52 53 54
  });

  it('should return empty string when containerImage is not empty and does not contain `:`' +
         ' delimiter',
     () => {
55
       // given
56
       ctrl.containerImage = 'test';
57 58 59 60 61 62

       // when
       let result = ctrl.getContainerImageVersion_();

       // then
       expect(result).toEqual('');
63 64 65
     });

  it('should return part of the string after `:` delimiter', () => {
66
    // given
67
    ctrl.containerImage = 'test:1';
68 69 70 71 72 73

    // when
    let result = ctrl.getContainerImageVersion_();

    // then
    expect(result).toEqual('1');
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
  it('should return empty array when labels array is empty', () => {
    // given
    let labels = [];

    // when
    let result = ctrl.toBackendApiLabels_(labels);

    // then
    expect(result).toEqual([]);
  });

  it('should return filtered backend api labels array without empty key/values', () => {
    // given
    let labels = [
      new DeployLabel('', 'val'),
      new DeployLabel('key1', 'val1'),
    ];

    // when
    let result = ctrl.toBackendApiLabels_(labels);

    // then
    let expected = [
      {
        key: 'key1',
        value: 'val1',
      },
    ];

    expect(result).toEqual(expected);
  });
107
});