|
| 1 | +import React from 'react'; |
| 2 | +import { shallow } from 'enzyme'; |
| 3 | + |
| 4 | +import GifGridItem from '../../components/GifGridItem'; |
| 5 | + |
| 6 | +describe('Tests GifGridItem component', () => { |
| 7 | + const url = 'https://localhost:8080/something.gif'; |
| 8 | + const title = 'something'; |
| 9 | + |
| 10 | + let wrapper = shallow(<GifGridItem url={url} title={title} />); |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + wrapper = shallow(<GifGridItem url={url} title={title} />); |
| 14 | + }); |
| 15 | + |
| 16 | + test('Should display correctly', () => { |
| 17 | + expect(wrapper).toMatchSnapshot(); |
| 18 | + }); |
| 19 | + |
| 20 | + describe('Tests className attribute', () => { |
| 21 | + test('Should have card in className', () => { |
| 22 | + const text = wrapper.find('div').prop('className'); |
| 23 | + expect(text.includes('card')).toBe(true); |
| 24 | + }); |
| 25 | + |
| 26 | + test('Should have animate__animated and animate__fadeIn in className', () => { |
| 27 | + const text = wrapper.find('.card').prop('className'); |
| 28 | + expect(text.includes('animate__animated')).toBe(true); |
| 29 | + expect(text.includes('animate__fadeIn')).toBe(true); |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + describe('Tests url attribute', () => { |
| 34 | + const text = wrapper.find('.card img').prop('src'); |
| 35 | + |
| 36 | + test('Should have a sub-string with https:// text', () => { |
| 37 | + expect(text.includes('https://')).toBe(true); |
| 38 | + }); |
| 39 | + |
| 40 | + test('Should have a something with .gif', () => { |
| 41 | + expect(text.includes('.gif')).toBe(true); |
| 42 | + }); |
| 43 | + |
| 44 | + test('Should have a alt with something text', () => { |
| 45 | + const text = wrapper.find('.card img').prop('alt'); |
| 46 | + expect(text).toBe(title); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + test('Should have a title with something text', () => { |
| 51 | + const text = wrapper.find('.card p').text(); |
| 52 | + expect(text).toBe(title); |
| 53 | + }); |
| 54 | +}); |
| 55 | + |
| 56 | + |
0 commit comments