|
1 | 1 | import { getClient, logger, setCurrentClient } from '@sentry/core';
|
2 | 2 | import { render } from '@testing-library/react-native';
|
3 | 3 | import * as React from 'react';
|
4 |
| -import { Text } from 'react-native'; |
5 |
| -import { Appearance } from 'react-native'; |
| 4 | +import { Appearance,Text } from 'react-native'; |
| 5 | + |
6 | 6 | import { defaultConfiguration } from '../../src/js/feedback/defaults';
|
7 | 7 | import { FeedbackWidgetProvider, hideFeedbackButton,resetFeedbackButtonManager, resetFeedbackWidgetManager, showFeedbackButton, showFeedbackWidget } from '../../src/js/feedback/FeedbackWidgetManager';
|
8 | 8 | import { feedbackIntegration } from '../../src/js/feedback/integration';
|
@@ -141,13 +141,23 @@ describe('FeedbackWidgetManager', () => {
|
141 | 141 | });
|
142 | 142 |
|
143 | 143 | describe('FeedbackButtonManager', () => {
|
| 144 | + let listener: (preferences: Appearance.AppearancePreferences) => void; |
| 145 | + |
| 146 | + afterEach(() => { |
| 147 | + jest.resetAllMocks(); |
| 148 | + }); |
144 | 149 |
|
145 | 150 | beforeEach(() => {
|
146 | 151 | const client = new TestClient(getDefaultTestClientOptions());
|
147 | 152 | setCurrentClient(client);
|
148 | 153 | client.init();
|
149 | 154 | consoleWarnSpy.mockReset();
|
150 | 155 | resetFeedbackButtonManager();
|
| 156 | + |
| 157 | + jest.spyOn(Appearance, 'addChangeListener').mockImplementation((cb) => { |
| 158 | + listener = cb; |
| 159 | + return { remove: jest.fn() }; |
| 160 | + }); |
151 | 161 | });
|
152 | 162 |
|
153 | 163 | it('showFeedbackButton displays the button when FeedbackWidgetProvider is used', () => {
|
@@ -235,6 +245,26 @@ describe('FeedbackButtonManager', () => {
|
235 | 245 | expect(toJSON()).toMatchSnapshot();
|
236 | 246 | });
|
237 | 247 |
|
| 248 | + it('the Feedback Widget matches the snapshot with default configuration and dynamically changed theme', () => { |
| 249 | + const component = ( |
| 250 | + <FeedbackWidgetProvider> |
| 251 | + <Text>App Components</Text> |
| 252 | + </FeedbackWidgetProvider> |
| 253 | + ); |
| 254 | + |
| 255 | + mockedIsModalSupported.mockReturnValue(true); |
| 256 | + const { toJSON } = render(component); |
| 257 | + |
| 258 | + jest.spyOn(Appearance, 'getColorScheme').mockReturnValue('light'); |
| 259 | + |
| 260 | + showFeedbackWidget(); |
| 261 | + |
| 262 | + jest.spyOn(Appearance, 'getColorScheme').mockReturnValue('dark'); |
| 263 | + listener({ colorScheme: 'dark' }); |
| 264 | + |
| 265 | + expect(toJSON()).toMatchSnapshot(); |
| 266 | + }); |
| 267 | + |
238 | 268 | it('the Feedback Widget matches the snapshot with custom light theme', () => {
|
239 | 269 | mockedIsModalSupported.mockReturnValue(true);
|
240 | 270 | const { toJSON } = render(
|
@@ -357,6 +387,26 @@ describe('FeedbackButtonManager', () => {
|
357 | 387 | expect(toJSON()).toMatchSnapshot();
|
358 | 388 | });
|
359 | 389 |
|
| 390 | + it('the Feedback Button matches the snapshot with default configuration and dynamically changed theme', () => { |
| 391 | + const component = ( |
| 392 | + <FeedbackWidgetProvider> |
| 393 | + <Text>App Components</Text> |
| 394 | + </FeedbackWidgetProvider> |
| 395 | + ); |
| 396 | + |
| 397 | + mockedIsModalSupported.mockReturnValue(true); |
| 398 | + const { toJSON } = render(component); |
| 399 | + |
| 400 | + jest.spyOn(Appearance, 'getColorScheme').mockReturnValue('light'); |
| 401 | + |
| 402 | + showFeedbackButton(); |
| 403 | + |
| 404 | + jest.spyOn(Appearance, 'getColorScheme').mockReturnValue('dark'); |
| 405 | + listener({ colorScheme: 'dark' }); |
| 406 | + |
| 407 | + expect(toJSON()).toMatchSnapshot(); |
| 408 | + }); |
| 409 | + |
360 | 410 | it('the Feedback Button matches the snapshot with custom light theme', () => {
|
361 | 411 | mockedIsModalSupported.mockReturnValue(true);
|
362 | 412 | const { toJSON } = render(
|
|
0 commit comments