function pickSentence(movie) { let movieQuotes = data.filter((obj) => { return obj.movieName === movie; })[0].sentences; return movieQuotes[getRandom(0, movieQuotes.length - 1)]; }
describe('SentenceView', () => { let renderedComponent let mockSentences let mockId beforeEach(() => { mockSentences = mockCleaned.sentences mockId = 1 renderedComponent = shallow(<SentenceView sentences={mockSentences} sentence_id={mockId} />) }) it('should match snapshot', () => { expect(renderedComponent).toMatchSnapshot() }) })
describe('cleanSentences', () => { it('should return the expected array of cleaned sentence objects', () => { const result = cleanSentences(mockUncleaned) const expected = mockCleaned.sentences expect(result).toEqual(expected) }) })
describe('sentencesReducer', () => { it('should return the default state', () => { expect(sentencesReducer(undefined, {})).toEqual([]) }) it('ADD_SENTENCES return the array of sentence objects', () => { const action = actions.addSentences(mockCleaned.sentences) const expected = mockCleaned.sentences expect(sentencesReducer(undefined, action)).toEqual(expected) }) it('CLEAR_SENTENCES should return the empty sentences array', () => { const action = actions.clearSentences() const state = mockCleaned.sentences const expected = [] expect(sentencesReducer(state, action)).toEqual(expected) }) })
describe('cleanTone', () => { it('should return the expected array of tone objects', () => { const result = cleanTone(mockUncleaned.sentences_tone[0], 0.2) const expected = mockCleaned.sentences[0].tones expect(result).toEqual(expected) }) })
mockHistory = { push: jest.fn() } mockDocumentTone = mockCleaned.documentTone mockSentences = mockCleaned.sentences renderedComponent = shallow( <Example expect(await mockAddSentences).toHaveBeenCalledWith(mockCleaned.sentences) }) expect(mockAddSentences).toHaveBeenCalledWith(mockCleaned.sentences) })
describe('DisplayResults', () => { let renderedComponent beforeEach(() => { renderedComponent = shallow(<DisplayResults sentences={ mockCleaned.sentences } />) }) it('should match snapshot', () => { expect(renderedComponent).toMatchSnapshot() }) it('shuold match snapshot when passed different results', () => { renderedComponent = shallow(<DisplayResults sentences={ mockCleaned2 } />) expect(renderedComponent).toMatchSnapshot() }) })
describe('cleanSentencesTone',() => { it('should return the expected object with primary and secondary sentence tones', () => { const expected = { "primary": [ "Analytical", "Positive" ], "secondary": [ "Tentative", "Analytical" ] } const result = cleanSentencesTone(mockCleaned.sentences) expect(result).toEqual(expected) }) })
describe('withoutDupes', () => { it('should return the expected array of tones without duplicates', () => { const expected = [ "Analytical", "Positive" ] const result = withoutDupes(mockCleaned.sentences, 0) expect(result).toEqual(expected) }) })