Skip to content

Commit

Permalink
remove defocus support
Browse files Browse the repository at this point in the history
  • Loading branch information
michalziolkowski committed Nov 28, 2024
1 parent fc2efc2 commit 7225f2e
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,4 @@ export default {
decorators: [StoryDecorator({ placement: 'center' })],
} as Meta<typeof FocusedInput>;

export const Basic = {
parameters: {
sherlo: {
/**
* This will prevent the input from being focused and displaying
* the caret blinking which would cause differences in Sherlo screenshot tests
*/
defocus: true,
},
},
};
export const Basic = {};
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,4 @@ export default {
decorators: [StoryDecorator({ placement: 'center' })],
} as Meta<typeof FocusedInput>;

export const Basic = {
parameters: {
sherlo: {
/**
* This will prevent the input from being focused and displaying
* the caret blinking which would cause differences in Sherlo screenshot tests
*/
defocus: true,
},
},
};
export const Basic = {};
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,4 @@ export default {
decorators: [StoryDecorator({ placement: 'center' })],
} as Meta<typeof FocusedInput>;

export const Basic = {
parameters: {
sherlo: {
/**
* This will prevent the input from being focused and displaying
* the caret blinking which would cause differences in Sherlo screenshot tests
*/
defocus: true,
},
},
};
export const Basic = {};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useRef, useState, ReactElement } from 'react';
import { Keyboard, Platform, StyleSheet, Text, View } from 'react-native';
import { StyleSheet, Text, View } from 'react-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { RunnerBridge, SherloModule } from '../helpers';
import { Snapshot, StorybookParams, StorybookView } from '../types';
Expand Down Expand Up @@ -37,25 +37,6 @@ function getStorybook(view: StorybookView, params?: StorybookParams): () => Reac
},
});

const prepareSnapshotForTesting = async (snapshot: Snapshot): Promise<void> => {
RunnerBridge.log('prepareSnapshotForTesting', { viewId: snapshot.viewId });

if (snapshot.sherloParameters?.defocus) {
RunnerBridge.log('defocusing focused input');

await waitForKeyboardStatus('shown');

if (Platform.OS === 'ios') {
await waitForKeyboardStatus('hidden');
} else {
// We call Keyboard.dismiss() multiple times because for some reason it sometimes doesn't work on the first try
for (let i = 0; i < 7; i++) {
Keyboard.dismiss();
}
}
}
};

// Testing mode
useTestingMode(view, mode, setSnapshots, setTestedIndex, RunnerBridge);

Expand Down Expand Up @@ -97,8 +78,6 @@ function getStorybook(view: StorybookView, params?: StorybookParams): () => Reac
});

const testStory = async (): Promise<void> => {
await prepareSnapshotForTesting(renderedSnapshot);

setTimeout(async () => {
try {
let inspectorData;
Expand Down
8 changes: 0 additions & 8 deletions packages/react-native-storybook/src/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { start } from '@storybook/react-native';
export interface SherloParameters {
/**
* Setting defocus to true hides the keyboard and defocuses any focused input
* before taking the screenshot. This is useful because focused inputs have
* animated elements that will make screenshots unpredictable when compared
* to the baseline.
*/
defocus?: boolean;

/**
* Setting exclude to true skips the story during testing. This might be
* useful if the story has animations that cannot be stabilized for testing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,4 @@ export default {
decorators: [StoryDecorator({ placement: 'center' })],
} as Meta<typeof FocusedInput>;

export const Basic = {
parameters: {
sherlo: {
/**
* This will prevent the input from being focused and displaying
* the caret blinking which would cause differences in Sherlo screenshot tests
*/
defocus: true,
},
},
};
export const Basic = {};
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,4 @@ export default {
decorators: [StoryDecorator({ placement: 'center' })],
} as Meta<typeof FocusedInput>;

export const Basic = {
parameters: {
sherlo: {
/**
* This will prevent the input from being focused and displaying
* the caret blinking which would cause differences in Sherlo screenshot tests
*/
defocus: true,
},
},
};

export const Focused = {};
export const Basic = {};

0 comments on commit 7225f2e

Please sign in to comment.