<commit_before>// @flow

'use strict'
import 'react-native'
import React from 'react'
import renderer from 'react-test-renderer'

import Home from '../home'

jest.mock('../../components/home/artist_rails/artist_rail', () => 'ArtistRail')
jest.mock('../../components/spinner.js', () => 'ARSpinner')
jest.mock('../../components/opaque_image_view.js', () => 'AROpaqueImageView')

it('renders', () => {
  const home = {
    hero_units: [],
    artist_modules: [],
    artwork_modules: [],
  }
  const homeComponent = renderer.create(<Home home={home}/>).toJSON()
  expect(homeComponent).toMatchSnapshot()
})<commit_msg>[Testing] Added logic tests for Home<commit_after>// @flow

'use strict'
import { ListViewDataSource } from 'react-native'
import React from 'react'
import renderer from 'react-test-renderer'

import Home from '../home'

jest.mock('../../components/home/artist_rails/artist_rail', () => 'ArtistRail')
jest.mock('../../components/spinner.js', () => 'ARSpinner')
jest.mock('../../components/opaque_image_view.js', () => 'AROpaqueImageView')

it('renders', () => {
  const home = {
    hero_units: [],
    artist_modules: [],
    artwork_modules: [],
  }
  const homeComponent = renderer.create(<Home home={home}/>).toJSON()
  expect(homeComponent).toMatchSnapshot()
})

describe('upon initialization', () => {
  it('starts with isRefreshing set to false', () => {
    const homeComponent = new Home(homeProps())
    expect(homeComponent.state.isRefreshing).toBeFalsy()
  })

  it('creates a data source with a search bar and hero unit', () => {
    const homeComponent = new Home(homeProps())
    const dataSourceBlob = extractListViewDataBlob(homeComponent)
    const searchBar = { type: 'search_bar', data: null }
    const heroUnits = { type: 'hero_units', data: [] }
    expect(dataSourceBlob).toContainEqual(searchBar)
    expect(dataSourceBlob).toContainEqual(heroUnits)
  })

  it('always places the first artwork module after search and hero units', () => {
    const homeComponent = new Home(homeProps(1, 1, 1))
    const dataSourceBlob = extractListViewDataBlob(homeComponent)
    expect(dataSourceBlob[2].type).toBe('artwork')
  })
})

var homeProps = (nHeroUnits?: number, nArtistModules?: number, nArtworkModules?: number) => {
  return {
      home: {
        hero_units: modulesOfType('hero_units', nHeroUnits),
        artist_modules: modulesOfType('artist', nArtistModules),
        artwork_modules: modulesOfType('artwork', nArtworkModules),
        }
    }
}

var modulesOfType = (type: string, count: number) => {
  const modules = []
  for (let i = 0; i < count; i++) {
    modules.push({ title: 'Title', type: type })
  }
  return modules
}

var extractListViewDataBlob = (home: Home) => {
  return home.state.dataSource._dataBlob.s1
}
{'fraction_non_alphanumeric': 0.16462093862815885, 'fraction_numerical': 0.0021660649819494585, 'mean_word_length': 4.179439252336449, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 20, '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': '3732402', 'n_tokens_mistral': 891, 'n_tokens_neox': 878, 'n_words': 189}