Skip to content

Commit

Permalink
Merge pull request #482 from wyne/share-navigation
Browse files Browse the repository at this point in the history
Fix share navigation
  • Loading branch information
wyne authored Aug 3, 2024
2 parents c0e4cd2 + dbbdcaf commit ec53d17
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
21 changes: 19 additions & 2 deletions src/components/Buttons/CheckButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const mockStore = () => {
describe('CheckButton', () => {
const navigation = useNavigationMock();

it('should navigate to Game screen when pressed', async () => {
it('should navigate to Game screen when pressed from new game', async () => {
const store = mockStore();

const { getByRole } = render(
Expand All @@ -58,7 +58,7 @@ describe('CheckButton', () => {
});
}, 10000);

it('should navigate back a screen when pressed', async () => {
it('should navigate back to list screen screen when pressed from list screen menu', async () => {
const store = mockStore();

const { getByRole } = render(
Expand All @@ -75,6 +75,23 @@ describe('CheckButton', () => {
});
}, 10000);

it('should navigate back to share screen screen when pressed from share screen', async () => {
const store = mockStore();

const { getByRole } = render(
<Provider store={store}>
<CheckButton navigation={navigation} route={{ key: 'Settings', name: 'Settings', params: { source: 'share_screen' } }} />
</Provider>
);

const button = getByRole('button');
fireEvent.press(button);

await waitFor(() => {
expect(navigation.navigate).toHaveBeenCalledWith('Share');
});
}, 10000);

it('should log an analytics event when pressed', async () => {
const store = mockStore();

Expand Down
6 changes: 5 additions & 1 deletion src/components/Buttons/CheckButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ const CheckButton: React.FunctionComponent<Props> = ({ navigation, route }) => {

if (route?.params?.source === 'list_screen') {
navigation.navigate('List');
} else {
} else if (route?.params?.source === 'share_screen') {
navigation.navigate('Share');
} else if (route?.params?.source === 'new_game') {
navigation.navigate('Game');
} else {
navigation.goBack();
}
}}>
<Text style={{ color: systemBlue, fontSize: 20 }}>Done</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/ShareScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const ShareScreen: React.FunctionComponent<Props> = ({ navigation }) => {
icon={<Icon name='edit' color={systemBlue} />}
style={{ padding: 10 }}
onPress={async () => {
navigation.navigate('Settings');
navigation.navigate('Settings', { source: 'share_screen' });
}} />

<View style={{
Expand Down

0 comments on commit ec53d17

Please sign in to comment.