{"size": 2223, "ext": "js", "max_stars_repo_path": "app/test/src/objectWithComponentComparator.spec.js", "max_stars_repo_name": "simondean/component-catalog", "max_stars_repo_stars_event_min_datetime": "2021-09-05T20:06:06.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-22T22:06:59.000Z", "max_issues_repo_path": "app/test/src/objectWithComponentComparator.spec.js", "max_issues_repo_name": "kronicle-tech/kronicle", "max_issues_repo_issues_event_min_datetime": "2021-09-11T15:29:59.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T00:24:42.000Z", "max_forks_repo_path": "app/test/src/objectWithComponentComparator.spec.js", "max_forks_repo_name": "simondean/component-catalog", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 158, "max_forks_count": null, "avg_line_length": 23.6489361702, "max_line_length": 96, "alphanum_fraction": 0.5569050832}
import { compareObjectsWithComponents } from '~/src/objectWithComponentComparator'

describe('Object With Component Comparator', () => {
  test('two objects with no components should be equal', () => {
    const a = {
      test: 'test',
    }
    const b = {
      test: 'test',
    }
    const returnValue = compareObjectsWithComponents(a, b)
    expect(returnValue).toEqual(0)
  })

  test('object `a` with a component and object `b` without a component should be equal', () => {
    const a = {
      test: 'test',
      component: {
        name: 'Test Name A',
      },
    }
    const b = {
      test: 'test',
    }
    const returnValue = compareObjectsWithComponents(a, b)
    expect(returnValue).toEqual(0)
  })

  test('object `a` without a component and object `b` with a component should be equal', () => {
    const a = {
      test: 'test',
    }
    const b = {
      test: 'test',
      component: {
        name: 'Test Name B',
      },
    }
    const returnValue = compareObjectsWithComponents(a, b)
    expect(returnValue).toEqual(0)
  })

  test('two objects with the same component name should be equal', () => {
    const a = {
      test: 'test',
      component: {
        name: 'Test Name',
      },
    }
    const b = {
      test: 'test',
      component: {
        name: 'Test Name',
      },
    }
    const returnValue = compareObjectsWithComponents(a, b)
    expect(returnValue).toEqual(0)
  })

  test('component name that is alphabetically before other component name should be -1', () => {
    const a = {
      test: 'test',
      component: {
        name: 'Test Name 1',
      },
    }
    const b = {
      test: 'test',
      component: {
        name: 'Test Name 2',
      },
    }
    const returnValue = compareObjectsWithComponents(a, b)
    expect(returnValue).toEqual(-1)
  })

  test('component name that is alphabetically after other component name should be +1', () => {
    const a = {
      test: 'test',
      component: {
        name: 'Test Name 2',
      },
    }
    const b = {
      test: 'test',
      component: {
        name: 'Test Name 1',
      },
    }
    const returnValue = compareObjectsWithComponents(a, b)
    expect(returnValue).toEqual(1)
  })
})
