Skip to content

Commit 3b4a1de

Browse files
committed
Test dynamically changed theme
1 parent ba98685 commit 3b4a1de

File tree

2 files changed

+488
-2
lines changed

2 files changed

+488
-2
lines changed

packages/core/test/feedback/FeedbackWidgetManager.test.tsx

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { getClient, logger, setCurrentClient } from '@sentry/core';
22
import { render } from '@testing-library/react-native';
33
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+
66
import { defaultConfiguration } from '../../src/js/feedback/defaults';
77
import { FeedbackWidgetProvider, hideFeedbackButton,resetFeedbackButtonManager, resetFeedbackWidgetManager, showFeedbackButton, showFeedbackWidget } from '../../src/js/feedback/FeedbackWidgetManager';
88
import { feedbackIntegration } from '../../src/js/feedback/integration';
@@ -141,13 +141,23 @@ describe('FeedbackWidgetManager', () => {
141141
});
142142

143143
describe('FeedbackButtonManager', () => {
144+
let listener: (preferences: Appearance.AppearancePreferences) => void;
145+
146+
afterEach(() => {
147+
jest.resetAllMocks();
148+
});
144149

145150
beforeEach(() => {
146151
const client = new TestClient(getDefaultTestClientOptions());
147152
setCurrentClient(client);
148153
client.init();
149154
consoleWarnSpy.mockReset();
150155
resetFeedbackButtonManager();
156+
157+
jest.spyOn(Appearance, 'addChangeListener').mockImplementation((cb) => {
158+
listener = cb;
159+
return { remove: jest.fn() };
160+
});
151161
});
152162

153163
it('showFeedbackButton displays the button when FeedbackWidgetProvider is used', () => {
@@ -235,6 +245,26 @@ describe('FeedbackButtonManager', () => {
235245
expect(toJSON()).toMatchSnapshot();
236246
});
237247

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+
238268
it('the Feedback Widget matches the snapshot with custom light theme', () => {
239269
mockedIsModalSupported.mockReturnValue(true);
240270
const { toJSON } = render(
@@ -357,6 +387,26 @@ describe('FeedbackButtonManager', () => {
357387
expect(toJSON()).toMatchSnapshot();
358388
});
359389

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+
360410
it('the Feedback Button matches the snapshot with custom light theme', () => {
361411
mockedIsModalSupported.mockReturnValue(true);
362412
const { toJSON } = render(

0 commit comments

Comments
 (0)