|
24 | 24 |
|
25 | 25 | */ |
26 | 26 |
|
27 | | -import { assertSnapshot } from '@looker/components-test-utils' |
| 27 | +import { assertSnapshot, renderWithTheme } from '@looker/components-test-utils' |
| 28 | +import { screen, fireEvent } from '@testing-library/react' |
28 | 29 | import React from 'react' |
29 | 30 | import { AvatarCombo } from './AvatarCombo' |
30 | 31 | import { AvatarIcon } from './AvatarIcon' |
31 | 32 | import { AvatarUser } from './AvatarUser' |
32 | 33 |
|
33 | 34 | /* eslint-disable @typescript-eslint/camelcase */ |
34 | 35 |
|
35 | | -test('AvatarCombo renders Avatar and its secondary avatar', () => { |
36 | | - const data = { |
37 | | - avatar_url: |
38 | | - 'https://gravatar.lookercdn.com/avatar/e8ebbdf1a64411721503995731?s=156&d=blank', |
39 | | - first_name: 'John', |
40 | | - last_name: 'Smith', |
41 | | - } |
42 | | - assertSnapshot(<AvatarCombo secondaryIcon="Code" user={data} />) |
43 | | -}) |
44 | | - |
45 | | -test('AvatarCombo renders Avatar initials and secondary with Code icon', () => { |
46 | | - const data = { |
47 | | - avatar_url: |
48 | | - 'https://gravatar.lookercdn.com/avatar/e8ebbdf1a64411721503995731?s=156&d=blank', |
49 | | - first_name: 'John', |
50 | | - last_name: 'Smith', |
51 | | - } |
52 | | - assertSnapshot(<AvatarCombo secondaryIcon="Code" user={data} />) |
53 | | -}) |
54 | | - |
55 | | -test('AvatarCombo renders AvatarIcon and secondary avatar if user is not available and updates icon if passed.', () => { |
56 | | - assertSnapshot(<AvatarCombo secondaryIcon="LogoRings" />) |
57 | | -}) |
58 | | - |
59 | | -test('AvatarIcon renders ', () => { |
60 | | - assertSnapshot(<AvatarIcon />) |
61 | | -}) |
62 | | - |
63 | | -test('AvatarIcon renders different icon if specified', () => { |
64 | | - assertSnapshot(<AvatarIcon icon="Code" />) |
65 | | -}) |
66 | | - |
67 | | -test('AvatarUser shows user profile picture if it has good avatar_url ', () => { |
68 | | - const data = { |
69 | | - avatar_url: |
70 | | - 'https://gravatar.lookercdn.com/avatar/e8ebbdf1a64411721503995731?s=156&d=blank', |
71 | | - first_name: 'John', |
72 | | - last_name: 'Smith', |
73 | | - } |
74 | | - |
75 | | - assertSnapshot(<AvatarUser user={data} />) |
76 | | -}) |
77 | | - |
78 | | -test('AvatarUser shows initials if has broken url as avatar_url', () => { |
79 | | - const data = { |
80 | | - avatar_url: |
81 | | - 'https://gravatar.lookercdn.com/avatar/e8ebbdf1a64411721503995731?s=156&d=blank', |
82 | | - first_name: 'John', |
83 | | - last_name: 'Smith', |
84 | | - } |
85 | | - |
86 | | - assertSnapshot(<AvatarUser user={data} />) |
87 | | -}) |
88 | | - |
89 | | -test('AvatarUser shows initials if it has null as avatar_url ', () => { |
90 | | - const data = { |
91 | | - avatar_url: null, |
92 | | - first_name: 'John', |
93 | | - last_name: 'Smith', |
94 | | - } |
95 | | - |
96 | | - assertSnapshot(<AvatarUser user={data} />) |
| 36 | +describe('Avatar', () => { |
| 37 | + describe('AvatarCombo', () => { |
| 38 | + test('renders Avatar and its secondary avatar', () => { |
| 39 | + const data = { |
| 40 | + avatar_url: |
| 41 | + 'https://gravatar.lookercdn.com/avatar/e8ebbdf1a64411721503995731?s=156&d=blank', |
| 42 | + first_name: 'John', |
| 43 | + last_name: 'Smith', |
| 44 | + } |
| 45 | + assertSnapshot(<AvatarCombo secondaryIcon="Code" user={data} />) |
| 46 | + }) |
| 47 | + |
| 48 | + test('renders Avatar initials and secondary with Code icon', () => { |
| 49 | + const data = { |
| 50 | + avatar_url: |
| 51 | + 'https://gravatar.lookercdn.com/avatar/e8ebbdf1a64411721503995731?s=156&d=blank', |
| 52 | + first_name: 'John', |
| 53 | + last_name: 'Smith', |
| 54 | + } |
| 55 | + assertSnapshot(<AvatarCombo secondaryIcon="Code" user={data} />) |
| 56 | + }) |
| 57 | + |
| 58 | + test('renders AvatarIcon and secondary avatar if user is not available and updates icon if passed.', () => { |
| 59 | + assertSnapshot(<AvatarCombo secondaryIcon="LogoRings" />) |
| 60 | + }) |
| 61 | + |
| 62 | + test('supports role as button & onClick event', () => { |
| 63 | + const fauxOnClick = jest.fn() |
| 64 | + renderWithTheme(<AvatarCombo onClick={fauxOnClick} role="button" />) |
| 65 | + |
| 66 | + const button = screen.getByRole('button') |
| 67 | + |
| 68 | + expect(button).toBeInTheDocument() |
| 69 | + fireEvent.click(button) |
| 70 | + expect(fauxOnClick.mock.calls.length).toBe(1) |
| 71 | + }) |
| 72 | + }) |
| 73 | + |
| 74 | + describe('AvatarIcon', () => { |
| 75 | + test('renders ', () => { |
| 76 | + assertSnapshot(<AvatarIcon />) |
| 77 | + }) |
| 78 | + |
| 79 | + test('supports role as button & onClick event', () => { |
| 80 | + const fauxOnClick = jest.fn() |
| 81 | + renderWithTheme(<AvatarIcon onClick={fauxOnClick} role="button" />) |
| 82 | + |
| 83 | + const button = screen.getByRole('button') |
| 84 | + |
| 85 | + expect(button).toBeInTheDocument() |
| 86 | + fireEvent.click(button) |
| 87 | + expect(fauxOnClick.mock.calls.length).toBe(1) |
| 88 | + }) |
| 89 | + |
| 90 | + test('renders different icon if specified', () => { |
| 91 | + assertSnapshot(<AvatarIcon icon="Code" />) |
| 92 | + }) |
| 93 | + }) |
| 94 | + |
| 95 | + describe('AvatarUser', () => { |
| 96 | + test('shows user profile picture if it has good avatar_url ', () => { |
| 97 | + const data = { |
| 98 | + avatar_url: |
| 99 | + 'https://gravatar.lookercdn.com/avatar/e8ebbdf1a64411721503995731?s=156&d=blank', |
| 100 | + first_name: 'John', |
| 101 | + last_name: 'Smith', |
| 102 | + } |
| 103 | + |
| 104 | + assertSnapshot(<AvatarUser user={data} />) |
| 105 | + }) |
| 106 | + |
| 107 | + test('shows initials if has broken url as avatar_url', () => { |
| 108 | + const data = { |
| 109 | + avatar_url: |
| 110 | + 'https://gravatar.lookercdn.com/avatar/e8ebbdf1a64411721503995731?s=156&d=blank', |
| 111 | + first_name: 'John', |
| 112 | + last_name: 'Smith', |
| 113 | + } |
| 114 | + |
| 115 | + assertSnapshot(<AvatarUser user={data} />) |
| 116 | + }) |
| 117 | + |
| 118 | + test('shows initials if it has null as avatar_url ', () => { |
| 119 | + const data = { |
| 120 | + avatar_url: null, |
| 121 | + first_name: 'John', |
| 122 | + last_name: 'Smith', |
| 123 | + } |
| 124 | + |
| 125 | + assertSnapshot(<AvatarUser user={data} />) |
| 126 | + }) |
| 127 | + }) |
| 128 | + |
| 129 | + test('supports role as button & onClick event', () => { |
| 130 | + const fauxOnClick = jest.fn() |
| 131 | + renderWithTheme(<AvatarUser onClick={fauxOnClick} role="button" />) |
| 132 | + |
| 133 | + const button = screen.getByRole('button') |
| 134 | + |
| 135 | + expect(button).toBeInTheDocument() |
| 136 | + fireEvent.click(button) |
| 137 | + expect(fauxOnClick.mock.calls.length).toBe(1) |
| 138 | + }) |
97 | 139 | }) |
0 commit comments