-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Login on web #7360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: Login on web #7360
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e72946e
hide login buttons and login on web
yash-rajpal 44057ae
add translations
yash-rajpal 7d0313c
fix review and stories
yash-rajpal 711fc5f
remove unused import
yash-rajpal 1ebaf61
fix typo
yash-rajpal d7ff592
add comment
yash-rajpal fbd0b64
fix story
yash-rajpal 37201f3
update snapshots
yash-rajpal 82262b4
add unit tests
yash-rajpal fd89bb0
move login_on_web on top and fix logic
yash-rajpal 4a19f1a
fix unit tests
yash-rajpal 0f72881
fix tests and snapshots
yash-rajpal 4eab065
fix translations on tests
yash-rajpal a10d52c
fix lint
yash-rajpal 54311f4
fix missing import
yash-rajpal 0885a24
fix props order
yash-rajpal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,144 @@ | ||
| import { Linking } from 'react-native'; | ||
| import { fireEvent, render, screen } from '@testing-library/react-native'; | ||
| import { Provider } from 'react-redux'; | ||
| import type { ReactNode } from 'react'; | ||
|
|
||
| import { generateSnapshots } from '../../../.rnstorybook/generateSnapshots'; | ||
| import * as stories from './LoginServices.stories'; | ||
| import LoginServices from './index'; | ||
| import { createMockedStore } from '../../reducers/mockedStore'; | ||
| import { setLoginServices } from '../../actions/login'; | ||
| import { selectServerRequest } from '../../actions/server'; | ||
| import { type IServices } from '../../selectors/login'; | ||
| import { type IItemService } from './interfaces'; | ||
|
|
||
| jest.mock('../../lib/services/connect', () => ({})); | ||
|
|
||
| generateSnapshots(stories); | ||
|
|
||
| jest.mock('./serviceLogin', () => ({})); | ||
|
|
||
| jest.mock('react-native/Libraries/Linking/Linking', () => ({ | ||
| openURL: jest.fn() | ||
| })); | ||
|
|
||
| const SERVER = 'https://demo.rocket.chat'; | ||
|
|
||
| const makeService = (overrides: Partial<IItemService> = {}): IItemService => | ||
| ({ | ||
| _id: 'github', | ||
|
|
||
| name: 'github', | ||
| service: '', | ||
| authType: 'oauth', | ||
| buttonColor: '', | ||
| buttonLabelColor: '', | ||
| clientConfig: { provider: '' }, | ||
| serverURL: '', | ||
| authorizePath: '', | ||
| clientId: 'client-123', | ||
| scope: '', | ||
| ...overrides | ||
| } as IItemService); | ||
|
|
||
| const buildServices = (count: number, extra: Partial<IItemService> = {}): IServices => { | ||
| const names = ['github', 'gitlab', 'google', 'facebook', 'linkedin', 'twitter', 'wordpress'] as const; | ||
| return Object.fromEntries( | ||
| names.slice(0, count).map(name => [name, makeService({ _id: name, name: name as any, ...extra })]) | ||
| ) as unknown as IServices; | ||
| }; | ||
|
|
||
| const Wrapper = ({ children, store }: { children: ReactNode; store: ReturnType<typeof createMockedStore> }) => ( | ||
| <Provider store={store}>{children}</Provider> | ||
| ); | ||
|
|
||
| describe('LoginServices', () => { | ||
| it('does not show expand/collapse button when services <= 3', () => { | ||
| const store = createMockedStore(); | ||
| store.dispatch(setLoginServices(buildServices(2))); | ||
| render( | ||
| <Wrapper store={store}> | ||
| <LoginServices separator /> | ||
| </Wrapper> | ||
| ); | ||
| expect(screen.queryByText('More options')).toBeNull(); | ||
| }); | ||
|
|
||
| it('shows expand/collapse button when separator=true and > 3 services, does not show all services', () => { | ||
| const store = createMockedStore(); | ||
| store.dispatch(setLoginServices(buildServices(5))); | ||
| render( | ||
| <Wrapper store={store}> | ||
| <LoginServices separator /> | ||
| </Wrapper> | ||
| ); | ||
| expect(screen.queryByText('Continue with Facebook')).toBeNull(); | ||
| expect(screen.queryByText('Continue with Linkedin')).toBeNull(); | ||
| expect(screen.getByText('More options')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('uncollapses and shows all services', () => { | ||
| const store = createMockedStore(); | ||
| store.dispatch(setLoginServices(buildServices(5))); | ||
| render( | ||
| <Wrapper store={store}> | ||
| <LoginServices separator /> | ||
| </Wrapper> | ||
| ); | ||
| expect(screen.queryByText('Continue with Facebook')).toBeNull(); | ||
| expect(screen.queryByText('Continue with Linkedin')).toBeNull(); | ||
| expect(screen.getByText('More options')).toBeTruthy(); | ||
|
|
||
| fireEvent.press(screen.getByText('More options')); | ||
|
|
||
| expect(screen.getByText('Continue with Facebook')).toBeTruthy(); | ||
| expect(screen.getByText('Continue with Linkedin')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('filters out services with hideButtonOnMobile=true and shows Login on web button', () => { | ||
| const store = createMockedStore(); | ||
| const services = { | ||
| ...buildServices(2), | ||
| hidden: makeService({ _id: 'hidden', name: 'facebook' as any, hideButtonOnMobile: true }) | ||
| } as unknown as IServices; | ||
| store.dispatch(setLoginServices(services)); | ||
| render( | ||
| <Wrapper store={store}> | ||
| <LoginServices separator /> | ||
| </Wrapper> | ||
| ); | ||
|
|
||
| expect(screen.queryByText('Continue with Facebook')).toBeNull(); | ||
| expect(screen.queryByText('More options')).toBeNull(); | ||
| expect(screen.getByText('Login on web')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('does not show Login_on_web button when no services are hidden', () => { | ||
| const store = createMockedStore(); | ||
| store.dispatch(setLoginServices(buildServices(2))); | ||
| render( | ||
| <Wrapper store={store}> | ||
| <LoginServices separator={false} /> | ||
| </Wrapper> | ||
| ); | ||
| expect(screen.queryByText('Login on web')).toBeNull(); | ||
| }); | ||
|
|
||
| it('opens Login on web URL when button is pressed', () => { | ||
| const store = createMockedStore(); | ||
| const services = { | ||
| ...buildServices(2), | ||
| hidden: makeService({ _id: 'hidden', name: 'facebook' as any, hideButtonOnMobile: true }) | ||
| } as unknown as IServices; | ||
| store.dispatch(setLoginServices(services)); | ||
| store.dispatch(selectServerRequest(SERVER, '6.0.0')); | ||
| render( | ||
| <Wrapper store={store}> | ||
| <LoginServices separator /> | ||
| </Wrapper> | ||
| ); | ||
|
|
||
| fireEvent.press(screen.getByText('Login on web')); | ||
| expect(Linking.openURL).toHaveBeenCalledWith(`${SERVER}/home?loginClient=mobile`); | ||
| }); | ||
| }); | ||
This file contains hidden or 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,43 @@ | ||
| import { Linking } from 'react-native'; | ||
|
|
||
| import Service from './Service'; | ||
| import Button from '../Button'; | ||
| import { type IServiceList, type IItemService } from './interfaces'; | ||
| import I18n from '../../i18n'; | ||
|
|
||
| const ServiceList = ({ | ||
| services, | ||
| CAS_enabled, | ||
| CAS_login_url, | ||
| Gitlab_URL, | ||
| server, | ||
| collapsed, | ||
| showLoginOnWebButton | ||
| }: IServiceList & { showLoginOnWebButton: boolean }) => ( | ||
| <> | ||
| {showLoginOnWebButton && ( | ||
| <Button | ||
| title={I18n.t('Login_on_web')} | ||
| onPress={() => { | ||
| Linking.openURL(`${server}/home?loginClient=mobile`); | ||
| }} | ||
| /> | ||
| )} | ||
| {Object.values(services).map((service: IItemService, index: number) => { | ||
| if (index > 2 && collapsed) return null; | ||
|
|
||
| return ( | ||
| <Service | ||
| key={service._id} | ||
| CAS_enabled={CAS_enabled} | ||
| CAS_login_url={CAS_login_url} | ||
| Gitlab_URL={Gitlab_URL} | ||
| server={server} | ||
| service={service} | ||
| /> | ||
| ); | ||
| })} | ||
| </> | ||
| ); | ||
|
|
||
| export default ServiceList; |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.