summaryrefslogtreecommitdiff
path: root/ambari-web/test/views/common/log_file_search_view_test.js
blob: a5f940e368fcac6b75e1deefc41d2859a723f0e6 (plain)
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
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 */

var App = require('app');

describe('App.LogFileSearchView', function() {
  describe('#serializeFilters', function() {
    var makeLevelItem = function(level, isChecked) {
      return Em.Object.create({
        name: level.toUpperCase(),
        checked: !!isChecked
      });
    };
    var makeSelectedKeyword = function(keyword, isIncluded) {
      return Em.Object.create({
        value: keyword,
        isIncluded: !!isIncluded
      });
    };

    [
      {
        viewContent: {
          keywordsFilterValue: 'some_keyword'
        },
        e: 'keywords=some_keyword'
      },
      {
        viewContent: {
          keywordsFilterValue: 'some_keyword',
          levelsContext: [
            makeLevelItem('debug', true),
            makeLevelItem('error', false),
            makeLevelItem('info', true)
          ]
        },
        e: 'levels=DEBUG,INFO&keywords=some_keyword'
      },
      {
        viewContent: {
          keywordsFilterValue: 'some_keyword',
          dateFromValue: '12/12/2015',
          dateToValue: '14/12/2015',
          levelsContext: [
            makeLevelItem('debug', true),
            makeLevelItem('error', true),
            makeLevelItem('info', true)
          ]
        },
        e: 'levels=DEBUG,ERROR,INFO&keywords=some_keyword&dateTo=12/12/2015&dateFrom=12/12/2015'
      },
      {
        viewContent: {
          keywordsFilterValue: 'some_keyword',
          dateFromValue: '12/12/2015',
          levelsContext: [
            makeLevelItem('debug', true),
            makeLevelItem('error', true),
            makeLevelItem('info', true)
          ]
        },
        e: 'levels=DEBUG,ERROR,INFO&keywords=some_keyword&dateFrom=12/12/2015'
      },
      {
        viewContent: {
          keywordsFilterValue: 'some_keyword',
          dateFromValue: '12/12/2015',
          levelsContext: [
            makeLevelItem('debug', true),
            makeLevelItem('error', true),
            makeLevelItem('info', true)
          ],
          selectedKeywords: [
            makeSelectedKeyword("keyword1", true),
            makeSelectedKeyword("keyword2", true),
            makeSelectedKeyword("keyword3", false)
          ]
        },
        e: 'levels=DEBUG,ERROR,INFO&keywords=some_keyword&dateFrom=12/12/2015&include=keyword1,keyword2&exclude=keyword3'
      }
    ].forEach(function(test) {
      it('validate result: ' + test.e, function() {
        var view = App.LogFileSearchView.extend(test.viewContent).create();
        expect(view.serializeFilters()).to.be.eql(test.e);
        view.destroy();
      })
    });
  });
});