|
| 1 | +import { mount } from 'enzyme'; |
| 2 | +import React from 'react'; |
| 3 | +import Card from '../Card'; |
| 4 | + |
| 5 | +describe('Card', () => { |
| 6 | + it('matches snapshot', () => { |
| 7 | + const wrapper = mount( |
| 8 | + <Card> |
| 9 | + <Card.Image src="imageSrc" alt="imageAlt" /> |
| 10 | + <Card.Content> |
| 11 | + <Card.Heading>If you need help now but it's not an emergency</Card.Heading> |
| 12 | + <Card.Description> |
| 13 | + Go to <a href="#">111.nhs.uk</a> or <a href="#">call 111</a> |
| 14 | + </Card.Description> |
| 15 | + </Card.Content> |
| 16 | + </Card>, |
| 17 | + ); |
| 18 | + |
| 19 | + expect(wrapper).toMatchSnapshot(); |
| 20 | + |
| 21 | + wrapper.unmount(); |
| 22 | + }); |
| 23 | + |
| 24 | + it('can render Card.Link as different elements', () => { |
| 25 | + const wrapper = mount( |
| 26 | + <Card clickable> |
| 27 | + <Card.Content> |
| 28 | + <Card.Heading> |
| 29 | + <Card.Link asElement="button" type="button"> |
| 30 | + Click me! |
| 31 | + </Card.Link> |
| 32 | + </Card.Heading> |
| 33 | + </Card.Content> |
| 34 | + </Card>, |
| 35 | + ); |
| 36 | + expect( |
| 37 | + wrapper.find(Card.Link).containsMatchingElement( |
| 38 | + <button type="button" className="nhsuk-card__link"> |
| 39 | + Click me! |
| 40 | + </button>, |
| 41 | + ), |
| 42 | + ).toBeTruthy(); |
| 43 | + }); |
| 44 | + |
| 45 | + it('adds clickable classes', () => { |
| 46 | + const wrapper = mount( |
| 47 | + <Card clickable> |
| 48 | + <Card.Content> |
| 49 | + <Card.Heading className="nhsuk-heading-m"> |
| 50 | + <Card.Link href="#">Introduction to care and support</Card.Link> |
| 51 | + </Card.Heading> |
| 52 | + <Card.Description> |
| 53 | + A quick guide for people who have care and support needs and their carers |
| 54 | + </Card.Description> |
| 55 | + </Card.Content> |
| 56 | + </Card>, |
| 57 | + ); |
| 58 | + |
| 59 | + expect(wrapper.find('div.nhsuk-card').props().className).toBe( |
| 60 | + 'nhsuk-card nhsuk-card--clickable', |
| 61 | + ); |
| 62 | + |
| 63 | + wrapper.unmount(); |
| 64 | + }); |
| 65 | + |
| 66 | + it('adds feature classes to all elements', () => { |
| 67 | + const wrapper = mount( |
| 68 | + <Card feature> |
| 69 | + <Card.Content> |
| 70 | + <Card.Heading>Feature card heading</Card.Heading> |
| 71 | + <Card.Description>Feature card description</Card.Description> |
| 72 | + </Card.Content> |
| 73 | + </Card>, |
| 74 | + ); |
| 75 | + |
| 76 | + expect(wrapper.find('div.nhsuk-card').props().className).toBe('nhsuk-card nhsuk-card--feature'); |
| 77 | + expect(wrapper.find('div.nhsuk-card__content').props().className).toBe( |
| 78 | + 'nhsuk-card__content nhsuk-card__content--feature', |
| 79 | + ); |
| 80 | + expect(wrapper.find('h2.nhsuk-card__heading').props().className).toBe( |
| 81 | + 'nhsuk-card__heading nhsuk-card__heading--feature', |
| 82 | + ); |
| 83 | + |
| 84 | + wrapper.unmount(); |
| 85 | + }); |
| 86 | + |
| 87 | + describe('Card.Group', () => { |
| 88 | + it('matches snapshot', () => { |
| 89 | + const wrapper = mount( |
| 90 | + <Card.Group> |
| 91 | + <Card.GroupItem width="one-half"> |
| 92 | + <Card> |
| 93 | + <Card.Content> |
| 94 | + <Card.Heading>Test Card 1</Card.Heading> |
| 95 | + <Card.Description>Test Card 1 Description</Card.Description> |
| 96 | + </Card.Content> |
| 97 | + </Card> |
| 98 | + </Card.GroupItem> |
| 99 | + <Card.GroupItem width="one-half"> |
| 100 | + <Card> |
| 101 | + <Card.Content> |
| 102 | + <Card.Heading>Test Card 2</Card.Heading> |
| 103 | + <Card.Description>Test Card 2 Description</Card.Description> |
| 104 | + </Card.Content> |
| 105 | + </Card> |
| 106 | + </Card.GroupItem> |
| 107 | + </Card.Group>, |
| 108 | + ); |
| 109 | + |
| 110 | + expect(wrapper).toMatchSnapshot(); |
| 111 | + |
| 112 | + wrapper.unmount(); |
| 113 | + }); |
| 114 | + }); |
| 115 | +}); |
0 commit comments