<commit_before>import React from 'react';
import {shallow} from 'enzyme';

import {pullRequestBuilder} from '../builder/pr';
import ReviewsView from '../../lib/views/reviews-view';

describe('ReviewsView', function() {
  let atomEnv;

  beforeEach(function() {
    atomEnv = global.buildAtomEnvironment();
  });

  afterEach(function() {
    atomEnv.destroy();
  });

  // TODO: probably need to either refactor or fix this after the pullRequestBuilder implementation has settled
  function aggregatePullRequest(pullRequest, override = {}) {
    const reviewThreads = pullRequest.reviewThreads.edges.map(e => e.node);
    const summaries = pullRequest.reviews.edges.map(e => e.node);
    const commentThreads = reviewThreads.map(thread => {
      return {
        thread,
        comments: thread.comments.edges.map(e => e.node),
      };
    });
    return {summaries, commentThreads, errors: [], loading: false, ...override};
  }

  function buildApp(override = {}) {
    const props = {
      repository: {pullRequest: {}},
      checkoutOp: {
        isEnabled: () => true,
      },
      ...override,
    };

    return <ReviewsView {...props} />;
  }

  it('renders a BareAggregatedReviewsContainer', function() {
    const wrapper = shallow(buildApp());
    assert.lengthOf(wrapper.find('ForwardRef(Relay(BareAggregatedReviewsContainer))'), 1);
  });

  it('registers atom commands');

  it('renders empty state if there is no review', function() {
    const pr = pullRequestBuilder().build();
    const {errors, summaries, commentThreads} = aggregatePullRequest(pr);
    const wrapper = shallow(buildApp())
      .find('ForwardRef(Relay(BareAggregatedReviewsContainer))')
      .renderProp('children')({errors, summaries, commentThreads});
    assert.lengthOf(wrapper.find('.github-Reviews-section.summaries'), 0);
    assert.lengthOf(wrapper.find('.github-Reviews-section.comments'), 0);
    assert.lengthOf(wrapper.find('.github-Reviews-emptyState'), 1);
  });

  it('renders summary and comment sections', function() {
    const pr = pullRequestBuilder()
      .addReview(r => r.id(0))
      .addReviewThread(t => t.addComment(c => c.id(1)))
      .addReviewThread(t => t.addComment(c => c.id(2)))
      .build();
    const {errors, summaries, commentThreads} = aggregatePullRequest(pr);
    const wrapper = shallow(buildApp())
      .find('ForwardRef(Relay(BareAggregatedReviewsContainer))')
      .renderProp('children')({errors, summaries, commentThreads});
    assert.lengthOf(wrapper.find('.github-Reviews-section.summaries'), 1);<commit_msg>Use aggregatedReviewsBuilder in ReviewsView tests<commit_after>import React from 'react';
import {shallow} from 'enzyme';

import ReviewsView from '../../lib/views/reviews-view';
import {aggregatedReviewsBuilder} from '../builder/graphql/aggregated-reviews-builder';

describe('ReviewsView', function() {
  let atomEnv;

  beforeEach(function() {
    atomEnv = global.buildAtomEnvironment();
  });

  afterEach(function() {
    atomEnv.destroy();
  });

  function buildApp(override = {}) {
    const props = {
      repository: {pullRequest: {}},
      checkoutOp: {
        isEnabled: () => true,
      },
      ...override,
    };

    return <ReviewsView {...props} />;
  }

  it('renders a BareAggregatedReviewsContainer', function() {
    const wrapper = shallow(buildApp());
    assert.lengthOf(wrapper.find('ForwardRef(Relay(BareAggregatedReviewsContainer))'), 1);
  });

  it('registers atom commands');

  it('renders empty state if there is no review', function() {
    const {errors, summaries, commentThreads} = aggregatedReviewsBuilder().build();
    const wrapper = shallow(buildApp())
      .find('ForwardRef(Relay(BareAggregatedReviewsContainer))')
      .renderProp('children')({errors, summaries, commentThreads});
    assert.lengthOf(wrapper.find('.github-Reviews-section.summaries'), 0);
    assert.lengthOf(wrapper.find('.github-Reviews-section.comments'), 0);
    assert.lengthOf(wrapper.find('.github-Reviews-emptyState'), 1);
  });

  it('renders summary and comment sections', function() {
    const {errors, summaries, commentThreads} = aggregatedReviewsBuilder()
      .addReviewSummary(r => r.id(0))
      .addReviewThread(t => t.addComment(c => c.id(1)))
      .addReviewThread(t => t.addComment(c => c.id(2)))
      .build();

    const wrapper = shallow(buildApp())
      .find('ForwardRef(Relay(BareAggregatedReviewsContainer))')
      .renderProp('children')({errors, summaries, commentThreads});
    assert.lengthOf(wrapper.find('.github-Reviews-section.summaries'), 1);
{'fraction_non_alphanumeric': 0.1571334648257725, 'fraction_numerical': 0.0035064650449265836, 'mean_word_length': 4.026431718061674, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '645543', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1356, 'n_words': 262}