| <!DOCTYPE html> |
| <!-- |
| Copyright 2016 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| |
| <link rel="import" href="/dashboard/elements/quick-log.html"> |
| <link rel="import" href="/dashboard/static/testing_common.html"> |
| |
| <link rel="import" href="/tracing/core/test_utils.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| |
| var testOptions = { |
| tearDown: function() { |
| testing_common.clearXhrMock(); |
| } |
| }; |
| |
| test('instantiate basic', function() { |
| var quickLog = document.createElement('quick-log'); |
| this.addHTMLOutput(quickLog); |
| |
| var params = { |
| 'namespace': 'test_namespace', |
| 'name': 'test_name', |
| 'size': 100, |
| 'xsrf_token': 'undefined' |
| }; |
| var mockResponse = [ |
| { |
| 'message': 'Second sample message.', |
| 'id': 'abc-124', |
| 'timestamp': 1454030606, |
| }, |
| { |
| 'message': 'First sample message.', |
| 'id': 'abc-123', |
| 'timestamp': 1454030605, |
| } |
| ]; |
| var query = ('/get_logs?' + testing_common.paramString(params)); |
| testing_common.addXhrMock(query, JSON.stringify(mockResponse)); |
| quickLog.initialize('A label', 'test_namespace', 'test_name'); |
| }, testOptions); |
| |
| test('logs added on initializing.', function() { |
| var quickLog = document.createElement('quick-log'); |
| testing_common.addToFixture(quickLog); |
| var params = { |
| 'namespace': 'test_namespace', |
| 'name': 'test_name', |
| 'size': 100, |
| 'xsrf_token': 'undefined' |
| }; |
| var mockResponse = [ |
| { |
| 'message': 'Second sample message.', |
| 'id': 'abc-124', |
| 'timestamp': 1454030606, |
| }, |
| { |
| 'message': 'First sample message.', |
| 'id': 'abc-123', |
| 'timestamp': 1454030605, |
| } |
| ]; |
| var query = ('/get_logs?' + testing_common.paramString(params)); |
| testing_common.addXhrMock(query, JSON.stringify(mockResponse)); |
| quickLog.initialize('A label', 'test_namespace', 'test_name'); |
| |
| return new Promise(function(resolve) { |
| function check() { |
| assert.equal(2, quickLog.logList.length); |
| resolve(); |
| } |
| setTimeout(check, 10); |
| }); |
| }, testOptions); |
| |
| test('new logs are added and duplicates are removed.', function() { |
| var quickLog = document.createElement('quick-log'); |
| testing_common.addToFixture(quickLog); |
| quickLog.initialize('A label', 'test_namespace', 'test_name'); |
| |
| var params = { |
| 'namespace': 'test_namespace', |
| 'name': 'test_name', |
| 'size': 100, |
| 'xsrf_token': 'undefined', |
| 'after_timestamp': '1454030606' |
| }; |
| var sampleLogs = [ |
| { |
| 'message': 'Second message.', |
| 'id': 'abc-124', |
| 'timestamp': 1454030606, |
| }, |
| { |
| 'message': 'First message.', |
| 'id': 'abc-123', |
| 'timestamp': 1454030605, |
| } |
| ]; |
| quickLog.updateLogs(sampleLogs); |
| |
| var newSampleLogs = [ |
| { |
| 'message': 'Updated first message.', |
| 'id': 'abc-123', |
| 'timestamp': 1454030608, |
| }, |
| { |
| 'message': 'Third message.', |
| 'id': 'abc-125', |
| 'timestamp': 1454030607, |
| }, |
| ]; |
| var query = ('/get_logs?' + testing_common.paramString(params)); |
| testing_common.addXhrMock(query, JSON.stringify(newSampleLogs)); |
| quickLog.getLogs(); |
| |
| return new Promise(function(resolve) { |
| function check() { |
| assert.equal(3, quickLog.logList.length); |
| assert.equal('Updated first message.', quickLog.logList[0].message); |
| assert.equal('Third message.', quickLog.logList[1].message); |
| assert.equal('Second message.', quickLog.logList[2].message); |
| resolve(); |
| } |
| setTimeout(check, 10); |
| }); |
| }, testOptions); |
| }); |
| </script> |