Skip to content
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

feat: Remove cordova stuff from AppLinker #2728

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions react/AppLinker/__snapshots__/index.deprecated.spec.jsx.snap
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`app icon should not crash if no href 1`] = `
<div>
<div>
<a>
Open
Cozy Drive
</a>
</div>
</div>
`;

exports[`app icon should render correctly 1`] = `
<div>
<div>
<a
href="https://fake.link"
>
Open
Cozy Drive
</a>
</div>
</div>
Expand Down
12 changes: 0 additions & 12 deletions react/AppLinker/__snapshots__/index.spec.jsx.snap
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`app icon should not crash if no href 1`] = `
<div>
<div>
<a>
Open
Cozy Drive
</a>
</div>
</div>
`;

exports[`app icon should render correctly 1`] = `
<div>
<div>
<a
href="https://fake.link"
>
Open
Cozy Drive
</a>
</div>
</div>
Expand Down
13 changes: 0 additions & 13 deletions react/AppLinker/expiringMemoize.js

This file was deleted.

93 changes: 1 addition & 92 deletions react/AppLinker/index.deprecated.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,8 @@ import { render } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import React from 'react'

import {
isMobileApp,
isMobile,
openDeeplinkOrRedirect,
startApp,
isAndroid,
checkApp
} from 'cozy-device-helper'

import AppLinker from '.'
import { generateUniversalLink } from './native'

jest.useFakeTimers()

const setup = ({ app, onAppSwitch }) => {
Expand All @@ -44,21 +35,6 @@ const setup = ({ app, onAppSwitch }) => {
}
}

jest.mock('./native', () => ({
...jest.requireActual('./native'),
generateUniversalLink: jest.fn()
}))

jest.mock('cozy-device-helper', () => ({
...jest.requireActual('cozy-device-helper'),
isMobileApp: jest.fn(),
isMobile: jest.fn(),
openDeeplinkOrRedirect: jest.fn(),
startApp: jest.fn().mockResolvedValue(),
isAndroid: jest.fn(),
checkApp: jest.fn()
}))

const app = {
slug: 'drive',
name: 'Drive'
Expand All @@ -68,14 +44,10 @@ describe('app icon', () => {
let spyConsoleError, spyConsoleWarn, appSwitchMock

beforeEach(() => {
isMobileApp.mockReturnValue(false)
spyConsoleError = jest.spyOn(console, 'error')
spyConsoleError.mockImplementation(() => {})
spyConsoleWarn = jest.spyOn(console, 'warn')
spyConsoleWarn.mockImplementation(() => {})
isMobileApp.mockReturnValue(false)
isMobile.mockReturnValue(false)
isAndroid.mockReturnValue(false)
appSwitchMock = jest.fn()
})

Expand All @@ -91,72 +63,9 @@ describe('app icon', () => {
})

it('should work for web -> web', async () => {
isMobileApp.mockReturnValue(false)
const { container, user } = setup({ app, onAppSwitch: appSwitchMock })
const link = container.querySelector('a')
await user.click(link)
expect(appSwitchMock).not.toHaveBeenCalled()
expect(startApp).not.toHaveBeenCalled()
})

it('should work for native -> native', async () => {
isMobileApp.mockReturnValue(true)
checkApp.mockResolvedValue(true)
const { container, user } = setup({ app, onAppSwitch: appSwitchMock })
const link = container.querySelector('a')
await user.click(link)

expect(startApp).toHaveBeenCalledWith({
appId: 'io.cozy.drive.mobile',
name: 'Cozy Drive',
uri: 'cozydrive://'
})
expect(appSwitchMock).toHaveBeenCalled()
})

it('should work for web -> native for Android (custom schema)', async () => {
isMobile.mockReturnValue(true)
isAndroid.mockResolvedValue(true)
const { container, user } = setup({ app, onAppSwitch: appSwitchMock })
const link = container.querySelector('a')
await user.click(link)
expect(openDeeplinkOrRedirect).toHaveBeenCalledWith(
'cozydrive://',
expect.any(Function)
)
expect(appSwitchMock).toHaveBeenCalled()
})

it('should work for web -> native for iOS (universal link)', async () => {
isMobile.mockReturnValue(true)
const { container, user } = setup({ app, onAppSwitch: appSwitchMock })
const link = container.querySelector('a')
await user.click(link)

expect(generateUniversalLink).toHaveBeenCalled()
})

it('should work for native -> web', async () => {
isMobileApp.mockReturnValue(true)
const { container, user } = setup({ app, onAppSwitch: appSwitchMock })
const link = container.querySelector('a')
await user.click(link)
expect(appSwitchMock).toHaveBeenCalled()
})

it('should not crash if no href', () => {
isMobileApp.mockReturnValue(true)
const { container } = render(
<AppLinker onAppSwitch={appSwitchMock} slug={app.slug}>
{({ onClick, href, name }) => (
<div>
<a href={href} onClick={onClick}>
Open {name}
</a>
</div>
)}
</AppLinker>
)
expect(container).toMatchSnapshot()
})
})
Loading
Loading