Skip to content

Commit

Permalink
feat: Remove cordova stuff from AppLinker
Browse files Browse the repository at this point in the history
  • Loading branch information
zatteo committed Dec 13, 2024
1 parent 3ddba0d commit db63679
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 363 deletions.
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

0 comments on commit db63679

Please sign in to comment.