<commit_before>/* global test, expect, beforeEach */
import { kea } from '../kea'
import { clearActionCache } from '../logic/actions'
import { keaSaga, keaReducer, clearStore } from '../scene/store'

import './helper/jsdom'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { mount } from 'enzyme'
import { createStore, applyMiddleware, combineReducers, compose } from 'redux'
import { Provider } from 'react-redux'
import createSagaMiddleware from 'redux-saga'

beforeEach(() => {
  clearActionCache()
  clearStore()
})

function getStore () {
  clearActionCache()
  clearStore()

  const reducers = combineReducers({
    scenes: keaReducer('scenes')
  })

  const sagaMiddleware = createSagaMiddleware()
  const finalCreateStore = compose(
    applyMiddleware(sagaMiddleware)
  )(createStore)

  const store = finalCreateStore(reducers)

  sagaMiddleware.run(keaSaga)

  return store
}

class BookDetail extends Component {
  render () {
    const { book, bookId } = this.props
    return <div id={`book-${bookId}`}>{book}</div>
  }
}

test('selectors have access to the component\'s props', () => {
  const store = getStore()

  const books = {
    1: 'book1',
    2: 'book2'
  }

  const booksLogic = kea({
    reducers: ({ actions }) => ({
      books: [books, PropTypes.object, {}]
    })
  })

  const bookDetailLogic = kea({
    selectors: ({ selectors }) => ({
      book: [
        () => [booksLogic.selectors.books, (_, props) => props.bookId],
        (books, bookId) => books[bookId],
        PropTypes.object
      ]
    })
  })

  // make sure booksLogic has been mounted to the store by dispatching some random action
  // TODO: this should not be necessary!
  store.dispatch({ type: 'bla' })

  const ConnectedBookDetail = bookDetailLogic(BookDetail)

  const wrapper = mount(
    <Provider store={store}>
      <div className='playground-scene'>
        <ConnectedBookDetail bookId={1} />
        <ConnectedBookDetail bookId={2} />
      </div><commit_msg>fix proptype in test<commit_after>/* global test, expect, beforeEach */
import { kea } from '../kea'
import { clearActionCache } from '../logic/actions'
import { keaSaga, keaReducer, clearStore } from '../scene/store'

import './helper/jsdom'
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { mount } from 'enzyme'
import { createStore, applyMiddleware, combineReducers, compose } from 'redux'
import { Provider } from 'react-redux'
import createSagaMiddleware from 'redux-saga'

beforeEach(() => {
  clearActionCache()
  clearStore()
})

function getStore () {
  clearActionCache()
  clearStore()

  const reducers = combineReducers({
    scenes: keaReducer('scenes')
  })

  const sagaMiddleware = createSagaMiddleware()
  const finalCreateStore = compose(
    applyMiddleware(sagaMiddleware)
  )(createStore)

  const store = finalCreateStore(reducers)

  sagaMiddleware.run(keaSaga)

  return store
}

class BookDetail extends Component {
  render () {
    const { book, bookId } = this.props
    return <div id={`book-${bookId}`}>{book}</div>
  }
}

test('selectors have access to the component\'s props', () => {
  const store = getStore()

  const books = {
    1: 'book1',
    2: 'book2'
  }

  const booksLogic = kea({
    reducers: ({ actions }) => ({
      books: [books, PropTypes.object, {}]
    })
  })

  const bookDetailLogic = kea({
    selectors: ({ selectors }) => ({
      book: [
        () => [booksLogic.selectors.books, (_, props) => props.bookId],
        (books, bookId) => books[bookId],
        PropTypes.string
      ]
    })
  })

  // make sure booksLogic has been mounted to the store by dispatching some random action
  // TODO: this should not be necessary!
  store.dispatch({ type: 'bla' })

  const ConnectedBookDetail = bookDetailLogic(BookDetail)

  const wrapper = mount(
    <Provider store={store}>
      <div className='playground-scene'>
        <ConnectedBookDetail bookId={1} />
        <ConnectedBookDetail bookId={2} />
      </div>
{'fraction_non_alphanumeric': 0.13727928376025864, 'fraction_numerical': 0.0029843322556577967, 'mean_word_length': 3.4392935982339954, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 31, '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': '1057884', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1256, 'n_words': 326}