<commit_before>/**
 * @copyright 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.
 *
 * @fileoverview Tests for SidebarTabService, holds state and data for the
 * explorer sidebar.
 *
 * @author <EMAIL> (<NAME>)
 */
'use strict'

goog.require('p3rf.perfkit.explorer.ext.bigquery.CurrentTimestampOptimizer');
goog.require('p3rf.perfkit.explorer.ext.BigQuery.CurrentTimestampGranularity');


goog.scope(function() {
  const explorer = p3rf.perfkit.explorer;
  const CurrentTimestampOptimizer = explorer.ext.bigquery.CurrentTimestampOptimizer;
  const CurrentTimestampGranularity = explorer.ext.bigquery.CurrentTimestampGranularity;

  describe('CurrentTimestampOptimizer', function() {
    let testOptimizer, dashboard, dashboardSetting, widget, widgetSetting;
    let PROVIDED_DASHBOARD, PROVIDED_WIDGET, PROVIDED_DATE;

    const PROVIDED_YEAR = 2006;
    const PROVIDED_MONTH = 1;
    const PROVIDED_DAY = 15;
    const PROVIDED_HOUR = 8;
    const PROVIDED_MINUTE = 14;
    const PROVIDED_SECOND = 23;

    beforeEach(function() {
      testOptimizer = new CurrentTimestampOptimizer();

      PROVIDED_DATE = new Date(
          PROVIDED_YEAR, PROVIDED_MONTH, PROVIDED_DAY,
          PROVIDED_HOUR, PROVIDED_MINUTE, PROVIDED_SECOND);
      
      PROVIDED_WIDGET = {
        datasource: {
          config: {
            bigQuery: {
              optimizeCurrentTimestamp: {
                enabled: null,
                granularity: null}}},
          query_exec: ''}};

      PROVIDED_DASHBOARD = {
        config: {
          bigQuery: {
            optimizeCurrentTimestamp: {
              enabled: false,
              granularity: 'HOUR'}}}};

      dashboardSetting = PROVIDED_DASHBOARD.config.bigQuery.optimizeCurrentTimestamp;
      widgetSetting = PROVIDED_WIDGET.datasource.config.bigQuery.optimizeCurrentTimestamp;

      spyOn(testOptimizer, 'getCurrentDate').and.returnValue(PROVIDED_DATE);
    });

    describe('getRoundedDate', function() {
      describe('should support restricting the date to the latest', function() {
        it('year', function() {
          let provided = new Date(Date.UTC(2015, 1, 15, 8, 23));
          let expected = new Date(Date.UTC(2015, 0, 1, 0, 0));
          let actual = testOptimizer.getRoundedDate(provided, CurrentTimestampGranularity.YEAR);

          expect(actual).toEqual(expected);
        });

        it('month', function() {
          let provided = new Date(Date.UTC(2015, 2, 15, 8, 23));
          let expected = new Date(Date.UTC(2015, 2, 1, 0, 0));
          let actual = testOptimizer.getRoundedDate(provided, CurrentTimestampGranularity.MONTH);<commit_msg>Remove unused constants.<commit_after>/**
 * @copyright 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.
 *
 * @fileoverview Tests for SidebarTabService, holds state and data for the
 * explorer sidebar.
 *
 * @author <EMAIL> (<NAME>)
 */
'use strict'

goog.require('p3rf.perfkit.explorer.ext.bigquery.CurrentTimestampOptimizer');
goog.require('p3rf.perfkit.explorer.ext.BigQuery.CurrentTimestampGranularity');


goog.scope(function() {
  const explorer = p3rf.perfkit.explorer;
  const CurrentTimestampOptimizer = explorer.ext.bigquery.CurrentTimestampOptimizer;
  const CurrentTimestampGranularity = explorer.ext.bigquery.CurrentTimestampGranularity;

  describe('CurrentTimestampOptimizer', function() {
    let testOptimizer, dashboard, dashboardSetting, widget, widgetSetting;
    let PROVIDED_DASHBOARD, PROVIDED_WIDGET;

    beforeEach(function() {
      testOptimizer = new CurrentTimestampOptimizer();
      
      PROVIDED_WIDGET = {
        datasource: {
          config: {
            bigQuery: {
              optimizeCurrentTimestamp: {
                enabled: null,
                granularity: null}}},
          query_exec: ''}};

      PROVIDED_DASHBOARD = {
        config: {
          bigQuery: {
            optimizeCurrentTimestamp: {
              enabled: false,
              granularity: 'HOUR'}}}};

      dashboardSetting = PROVIDED_DASHBOARD.config.bigQuery.optimizeCurrentTimestamp;
      widgetSetting = PROVIDED_WIDGET.datasource.config.bigQuery.optimizeCurrentTimestamp;
    });

    describe('getRoundedDate', function() {
      describe('should support restricting the date to the latest', function() {
        it('year', function() {
          let provided = new Date(Date.UTC(2015, 1, 15, 8, 23));
          let expected = new Date(Date.UTC(2015, 0, 1, 0, 0));
          let actual = testOptimizer.getRoundedDate(provided, CurrentTimestampGranularity.YEAR);

          expect(actual).toEqual(expected);
        });

        it('month', function() {
          let provided = new Date(Date.UTC(2015, 2, 15, 8, 23));
          let expected = new Date(Date.UTC(2015, 2, 1, 0, 0));
          let actual = testOptimizer.getRoundedDate(provided, CurrentTimestampGranularity.MONTH);
{'fraction_non_alphanumeric': 0.09890848026868178, 'fraction_numerical': 0.017800167926112512, 'mean_word_length': 3.212164073550212, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4819816', 'n_tokens_mistral': 1770, 'n_tokens_neox': 1648, 'n_words': 449}