{"size": 1473, "ext": "js", "max_stars_repo_path": "testplan/web_ui/testing/src/Common/__tests__/utils.test.js", "max_stars_repo_name": "dobragab/testplan", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "testplan/web_ui/testing/src/Common/__tests__/utils.test.js", "max_issues_repo_name": "dobragab/testplan", "max_issues_repo_issues_event_min_datetime": "2019-04-15T20:56:40.000Z", "max_issues_repo_issues_event_max_datetime": "2021-03-23T01:00:30.000Z", "max_forks_repo_path": "testplan/web_ui/testing/src/Common/__tests__/utils.test.js", "max_forks_repo_name": "dobragab/testplan", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 64, "max_forks_count": null, "avg_line_length": 28.3269230769, "max_line_length": 90, "alphanum_fraction": 0.6042090971}
import React from 'react';

import {NAV_ENTRY_DISPLAY_DATA} from "../defaults";
import {getNavEntryType, getNavEntryDisplayData} from '../utils';

describe('Common/utils', () => {

  describe('getNavEntryType', () => {

    [
      [{}, 'testplan'],
      [{type: 'TestGroupReport', category: 'multitest'}, 'multitest'],
      [{type: 'TestGroupReport', category: 'suite'}, 'suite'],
      [{type: 'TestCaseReport'}, 'testcase'],
      [{type: 'unknown'}, undefined],
    ].forEach(([entry, expectedType]) => {
      it(`handles ${expectedType} type`, () => {
        const type = getNavEntryType(entry);
        expect(type).toEqual(expectedType);
      });
    });

  });

  describe('getNavEntryDisplayData', () => {

    it('returns an empty object when given an empty object.', () => {
      const displayData = getNavEntryDisplayData({});

      for (const attribute of NAV_ENTRY_DISPLAY_DATA) {
        expect(displayData.hasOwnProperty(attribute)).toBeFalsy();
      }
    });

    it('returns an object with the expected keys when given an object with them.', () => {
      let index = 0;
      let entry = {};
      for (const attribute of NAV_ENTRY_DISPLAY_DATA) {
        entry[attribute] = index;
        index++;
      }
      entry['unknown'] = index;

      const displayData = getNavEntryDisplayData(entry);
      for (const attribute of NAV_ENTRY_DISPLAY_DATA) {
        expect(displayData[attribute]).toEqual(entry[attribute]);
      }
    })

  });

});