|
| 1 | +import React from 'react'; |
| 2 | +import { measureRenders } from 'reassure'; |
| 3 | +import { waitFor } from '@testing-library/react-native'; |
| 4 | +import ConfirmHcaptcha from '../index'; |
| 5 | + |
| 6 | +describe('ConfirmHcaptcha Performance Tests', () => { |
| 7 | + test('ConfirmHcaptcha initial render performance', async () => { |
| 8 | + await measureRenders( |
| 9 | + <ConfirmHcaptcha |
| 10 | + siteKey="00000000-0000-0000-0000-000000000000" |
| 11 | + baseUrl="https://hcaptcha.com" |
| 12 | + languageCode="en" |
| 13 | + onMessage={() => {}} |
| 14 | + /> |
| 15 | + ); |
| 16 | + }); |
| 17 | + |
| 18 | + test('ConfirmHcaptcha render with all props', async () => { |
| 19 | + await measureRenders( |
| 20 | + <ConfirmHcaptcha |
| 21 | + size="compact" |
| 22 | + siteKey="00000000-0000-0000-0000-000000000000" |
| 23 | + passiveSiteKey={false} |
| 24 | + baseUrl="https://hcaptcha.com" |
| 25 | + languageCode="en" |
| 26 | + orientation="portrait" |
| 27 | + showLoading={false} |
| 28 | + closableLoading={false} |
| 29 | + backgroundColor="rgba(0, 0, 0, 0.3)" |
| 30 | + loadingIndicatorColor="#999999" |
| 31 | + theme="light" |
| 32 | + rqdata='{"some": "data"}' |
| 33 | + sentry={true} |
| 34 | + jsSrc="https://js.hcaptcha.com/1/api.js" |
| 35 | + endpoint="https://api.hcaptcha.com" |
| 36 | + reportapi="https://accounts.hcaptcha.com" |
| 37 | + assethost="https://newassets.hcaptcha.com" |
| 38 | + imghost="https://imgs.hcaptcha.com" |
| 39 | + host="test-host" |
| 40 | + hasBackdrop={true} |
| 41 | + useSafeAreaView={true} |
| 42 | + debug={{ test: true }} |
| 43 | + onMessage={() => {}} |
| 44 | + /> |
| 45 | + ); |
| 46 | + }); |
| 47 | + |
| 48 | + test('ConfirmHcaptcha modal show/hide performance', async () => { |
| 49 | + const TestComponent = () => { |
| 50 | + const [show, setShow] = React.useState(false); |
| 51 | + |
| 52 | + return ( |
| 53 | + <> |
| 54 | + <ConfirmHcaptcha |
| 55 | + siteKey="00000000-0000-0000-0000-000000000000" |
| 56 | + baseUrl="https://hcaptcha.com" |
| 57 | + languageCode="en" |
| 58 | + onMessage={() => {}} |
| 59 | + /> |
| 60 | + <button onPress={() => setShow(!show)}> |
| 61 | + Toggle Modal |
| 62 | + </button> |
| 63 | + </> |
| 64 | + ); |
| 65 | + }; |
| 66 | + |
| 67 | + await measureRenders(<TestComponent />, { |
| 68 | + scenario: async () => { |
| 69 | + // Simulate showing and hiding the modal |
| 70 | + await waitFor(() => {}, { timeout: 100 }); |
| 71 | + }, |
| 72 | + }); |
| 73 | + }); |
| 74 | + |
| 75 | + test('ConfirmHcaptcha render count stability - multiple renders', async () => { |
| 76 | + // This test ensures render count doesn't increase with multiple renders |
| 77 | + const Component = () => ( |
| 78 | + <ConfirmHcaptcha |
| 79 | + siteKey="00000000-0000-0000-0000-000000000000" |
| 80 | + baseUrl="https://hcaptcha.com" |
| 81 | + languageCode="en" |
| 82 | + onMessage={() => {}} |
| 83 | + /> |
| 84 | + ); |
| 85 | + |
| 86 | + await measureRenders(<Component />, { |
| 87 | + runs: 20, // More runs to detect render count issues |
| 88 | + warmupRuns: 3, |
| 89 | + }); |
| 90 | + }); |
| 91 | + |
| 92 | + test('ConfirmHcaptcha minimal configuration', async () => { |
| 93 | + await measureRenders( |
| 94 | + <ConfirmHcaptcha |
| 95 | + siteKey="00000000-0000-0000-0000-000000000000" |
| 96 | + baseUrl="https://hcaptcha.com" |
| 97 | + languageCode="en" |
| 98 | + onMessage={() => {}} |
| 99 | + />, |
| 100 | + { |
| 101 | + scenario: async () => { |
| 102 | + await waitFor(() => {}, { timeout: 100 }); |
| 103 | + }, |
| 104 | + } |
| 105 | + ); |
| 106 | + }); |
| 107 | + |
| 108 | + test('ConfirmHcaptcha with safe area view', async () => { |
| 109 | + await measureRenders( |
| 110 | + <ConfirmHcaptcha |
| 111 | + siteKey="00000000-0000-0000-0000-000000000000" |
| 112 | + baseUrl="https://hcaptcha.com" |
| 113 | + languageCode="en" |
| 114 | + useSafeAreaView={true} |
| 115 | + onMessage={() => {}} |
| 116 | + />, |
| 117 | + { |
| 118 | + scenario: async () => { |
| 119 | + await waitFor(() => {}, { timeout: 100 }); |
| 120 | + }, |
| 121 | + } |
| 122 | + ); |
| 123 | + }); |
| 124 | + |
| 125 | + test('ConfirmHcaptcha without safe area view', async () => { |
| 126 | + await measureRenders( |
| 127 | + <ConfirmHcaptcha |
| 128 | + siteKey="00000000-0000-0000-0000-000000000000" |
| 129 | + baseUrl="https://hcaptcha.com" |
| 130 | + languageCode="en" |
| 131 | + useSafeAreaView={false} |
| 132 | + onMessage={() => {}} |
| 133 | + />, |
| 134 | + { |
| 135 | + scenario: async () => { |
| 136 | + await waitFor(() => {}, { timeout: 100 }); |
| 137 | + }, |
| 138 | + } |
| 139 | + ); |
| 140 | + }); |
| 141 | + |
| 142 | + test('ConfirmHcaptcha passive mode', async () => { |
| 143 | + await measureRenders( |
| 144 | + <ConfirmHcaptcha |
| 145 | + siteKey="00000000-0000-0000-0000-000000000000" |
| 146 | + baseUrl="https://hcaptcha.com" |
| 147 | + languageCode="en" |
| 148 | + passiveSiteKey={true} |
| 149 | + onMessage={() => {}} |
| 150 | + />, |
| 151 | + { |
| 152 | + scenario: async () => { |
| 153 | + await waitFor(() => {}, { timeout: 100 }); |
| 154 | + }, |
| 155 | + } |
| 156 | + ); |
| 157 | + }); |
| 158 | + |
| 159 | + test('ConfirmHcaptcha light theme performance', async () => { |
| 160 | + await measureRenders( |
| 161 | + <ConfirmHcaptcha |
| 162 | + siteKey="00000000-0000-0000-0000-000000000000" |
| 163 | + baseUrl="https://hcaptcha.com" |
| 164 | + languageCode="en" |
| 165 | + theme="light" |
| 166 | + onMessage={() => {}} |
| 167 | + />, |
| 168 | + { |
| 169 | + scenario: async () => { |
| 170 | + await waitFor(() => {}, { timeout: 100 }); |
| 171 | + }, |
| 172 | + } |
| 173 | + ); |
| 174 | + }); |
| 175 | + |
| 176 | + test('ConfirmHcaptcha dark theme performance', async () => { |
| 177 | + await measureRenders( |
| 178 | + <ConfirmHcaptcha |
| 179 | + siteKey="00000000-0000-0000-0000-000000000000" |
| 180 | + baseUrl="https://hcaptcha.com" |
| 181 | + languageCode="en" |
| 182 | + theme="dark" |
| 183 | + onMessage={() => {}} |
| 184 | + />, |
| 185 | + { |
| 186 | + scenario: async () => { |
| 187 | + await waitFor(() => {}, { timeout: 100 }); |
| 188 | + }, |
| 189 | + } |
| 190 | + ); |
| 191 | + }); |
| 192 | + |
| 193 | + test('ConfirmHcaptcha contrast theme performance', async () => { |
| 194 | + await measureRenders( |
| 195 | + <ConfirmHcaptcha |
| 196 | + siteKey="00000000-0000-0000-0000-000000000000" |
| 197 | + baseUrl="https://hcaptcha.com" |
| 198 | + languageCode="en" |
| 199 | + theme="contrast" |
| 200 | + onMessage={() => {}} |
| 201 | + />, |
| 202 | + { |
| 203 | + scenario: async () => { |
| 204 | + await waitFor(() => {}, { timeout: 100 }); |
| 205 | + }, |
| 206 | + } |
| 207 | + ); |
| 208 | + }); |
| 209 | +}); |
0 commit comments