-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests to app/utils/permalink (#8141)
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import {Keyboard, Platform} from 'react-native'; | ||
import {OptionsModalPresentationStyle} from 'react-native-navigation'; | ||
|
||
import {dismissAllModals, showModalOverCurrentContext} from '@screens/navigation'; | ||
|
||
import {displayPermalink, closePermalink} from '.'; | ||
|
||
jest.mock('@screens/navigation', () => ({ | ||
dismissAllModals: jest.fn(), | ||
showModalOverCurrentContext: jest.fn(), | ||
})); | ||
|
||
describe('permalinkUtils', () => { | ||
const originalSelect = Platform.select; | ||
|
||
beforeAll(() => { | ||
Platform.select = ({android, ios, default: dft}: any) => { | ||
if (Platform.OS === 'android' && android) { | ||
return android; | ||
} else if (Platform.OS === 'ios' && ios) { | ||
return ios; | ||
} | ||
|
||
return dft; | ||
}; | ||
}); | ||
|
||
afterAll(() => { | ||
Platform.select = originalSelect; | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('displayPermalink', () => { | ||
it('should dismiss keyboard and show permalink modal', async () => { | ||
const dismiss = jest.spyOn(Keyboard, 'dismiss'); | ||
await displayPermalink('teamName', 'postId'); | ||
expect(dismiss).toHaveBeenCalled(); | ||
expect(showModalOverCurrentContext).toHaveBeenCalledWith( | ||
'Permalink', | ||
{isPermalink: true, teamName: 'teamName', postId: 'postId'}, | ||
{ | ||
modalPresentationStyle: OptionsModalPresentationStyle.overFullScreen, | ||
layout: { | ||
componentBackgroundColor: 'rgba(0,0,0,0.2)', | ||
}, | ||
}, | ||
); | ||
}); | ||
|
||
it('should dismiss all modals if showingPermalink is true', async () => { | ||
// Simulate showingPermalink being true | ||
await displayPermalink('teamName', 'postId'); | ||
await displayPermalink('teamName', 'postId'); | ||
expect(dismissAllModals).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should handle platform specific options correctly', async () => { | ||
await displayPermalink('teamName', 'postId'); | ||
expect(showModalOverCurrentContext).toHaveBeenCalledWith( | ||
'Permalink', | ||
{isPermalink: true, teamName: 'teamName', postId: 'postId'}, | ||
{ | ||
modalPresentationStyle: OptionsModalPresentationStyle.overFullScreen, | ||
layout: { | ||
componentBackgroundColor: 'rgba(0,0,0,0.2)', | ||
}, | ||
}, | ||
); | ||
}); | ||
}); | ||
|
||
describe('closePermalink', () => { | ||
it('should set showingPermalink to false', () => { | ||
const showingPermalink = closePermalink(); | ||
expect(showingPermalink).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters