-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1524 from vasily-pozdnyakov/check_for_new_release
Added functionality to check for newer release
- Loading branch information
Showing
11 changed files
with
251 additions
and
2 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
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
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
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
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
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
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,78 @@ | ||
// SPDX-FileCopyrightText: Meta Platforms, Inc. and its affiliates | ||
// SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React, { ReactElement } from 'react'; | ||
import { NotificationPopup } from '../NotificationPopup/NotificationPopup'; | ||
import { useAppDispatch } from '../../state/hooks'; | ||
import { closePopup } from '../../state/actions/view-actions/view-actions'; | ||
import { ButtonText } from '../../enums/enums'; | ||
import commitInfo from '../../../commitInfo.json'; | ||
import MuiLink from '@mui/material/Link'; | ||
import { openUrl } from '../../util/open-url'; | ||
import MuiTypography from '@mui/material/Typography'; | ||
import { searchLatestReleaseNameAndUrl } from './update-app-popup-helpers'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { Alert } from '../Alert/Alert'; | ||
import { Spinner } from '../Spinner/Spinner'; | ||
|
||
export function UpdateAppPopup(): ReactElement { | ||
const dispatch = useAppDispatch(); | ||
|
||
function close(): void { | ||
dispatch(closePopup()); | ||
} | ||
|
||
const { isLoading, data, isError, error } = useQuery( | ||
['latestReleaseNameSearch'], | ||
() => searchLatestReleaseNameAndUrl(), | ||
{ | ||
refetchOnWindowFocus: false, | ||
} | ||
); | ||
|
||
const content = !isError ? ( | ||
isLoading ? ( | ||
<Spinner /> | ||
) : data ? ( | ||
data.name === commitInfo.commitInfo ? ( | ||
'You have the latest version of the app.' | ||
) : ( | ||
<> | ||
<MuiTypography> | ||
There is a new release! You can download it using the following | ||
link: | ||
<br /> | ||
<MuiLink component="button" onClick={(): void => openUrl(data.url)}> | ||
{data.name} | ||
</MuiLink> | ||
</MuiTypography> | ||
</> | ||
) | ||
) : ( | ||
'No information found.' | ||
) | ||
) : ( | ||
<Alert | ||
errorMessage={`Failed while fetching release data${ | ||
error instanceof Error ? `: ${error.message}` : '' | ||
}`} | ||
/> | ||
); | ||
|
||
return ( | ||
<NotificationPopup | ||
content={content} | ||
header={'Check for updates'} | ||
isOpen={true} | ||
fullWidth={false} | ||
rightButtonConfig={{ | ||
onClick: close, | ||
buttonText: ButtonText.Close, | ||
}} | ||
onBackdropClick={close} | ||
onEscapeKeyDown={close} | ||
/> | ||
); | ||
} |
101 changes: 101 additions & 0 deletions
101
src/Frontend/Components/UpdateAppPopup/__tests__/UpdateAppPopup.test.tsx
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,101 @@ | ||
// SPDX-FileCopyrightText: Meta Platforms, Inc. and its affiliates | ||
// SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
import { renderComponentWithStore } from '../../../test-helpers/render-component-with-store'; | ||
import { UpdateAppPopup } from '../UpdateAppPopup'; | ||
import { screen } from '@testing-library/react'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import axios from 'axios'; | ||
import commitInfo from '../../../../commitInfo.json'; | ||
|
||
describe('UpdateAppPopup', () => { | ||
const okStatus = 200; | ||
const notFoundStatus = 404; | ||
const axiosMock = new MockAdapter(axios); | ||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
retry: false, | ||
}, | ||
}, | ||
}); | ||
|
||
it('shows the popup with a link to a new release', async () => { | ||
axiosMock | ||
.onGet( | ||
'https://api.github.com/repos/opossum-tool/OpossumUI/releases/latest' | ||
) | ||
.replyOnce(okStatus, { | ||
name: 'Latest release', | ||
html_url: 'some url', | ||
}); | ||
renderComponentWithStore( | ||
<QueryClientProvider client={queryClient}> | ||
<UpdateAppPopup /> | ||
</QueryClientProvider> | ||
); | ||
expect(screen.getByText('Check for updates')); | ||
expect( | ||
await screen.findByText( | ||
'There is a new release! You can download it using the following link:' | ||
) | ||
); | ||
expect(await screen.findByText('Latest release')); | ||
}); | ||
|
||
it('shows the popup with no newer release', async () => { | ||
axiosMock | ||
.onGet( | ||
'https://api.github.com/repos/opossum-tool/OpossumUI/releases/latest' | ||
) | ||
.replyOnce(okStatus, { | ||
name: commitInfo.commitInfo, | ||
html_url: 'some url', | ||
}); | ||
renderComponentWithStore( | ||
<QueryClientProvider client={queryClient}> | ||
<UpdateAppPopup /> | ||
</QueryClientProvider> | ||
); | ||
expect(screen.getByText('Check for updates')); | ||
expect(await screen.findByText('You have the latest version of the app.')); | ||
}); | ||
|
||
it('shows the popup with no info found', async () => { | ||
axiosMock | ||
.onGet( | ||
'https://api.github.com/repos/opossum-tool/OpossumUI/releases/latest' | ||
) | ||
.replyOnce(okStatus, null); | ||
renderComponentWithStore( | ||
<QueryClientProvider client={queryClient}> | ||
<UpdateAppPopup /> | ||
</QueryClientProvider> | ||
); | ||
expect(screen.getByText('Check for updates')); | ||
expect(await screen.findByText('No information found.')); | ||
}); | ||
|
||
it('shows the popup with error', async () => { | ||
axiosMock | ||
.onGet( | ||
'https://api.github.com/repos/opossum-tool/OpossumUI/releases/latest' | ||
) | ||
.replyOnce(notFoundStatus); | ||
renderComponentWithStore( | ||
<QueryClientProvider client={queryClient}> | ||
<UpdateAppPopup /> | ||
</QueryClientProvider> | ||
); | ||
expect(screen.getByText('Check for updates')); | ||
expect( | ||
await screen.findByText( | ||
'Failed while fetching release data: Request failed with status code 404' | ||
) | ||
); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
src/Frontend/Components/UpdateAppPopup/update-app-popup-helpers.ts
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,21 @@ | ||
// SPDX-FileCopyrightText: Meta Platforms, Inc. and its affiliates | ||
// SPDX-FileCopyrightText: TNG Technology Consulting GmbH <https://www.tngtech.com> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import axios from 'axios'; | ||
|
||
export async function searchLatestReleaseNameAndUrl(): Promise<{ | ||
name: string; | ||
url: string; | ||
} | null> { | ||
const response = await axios.get( | ||
'https://api.github.com/repos/opossum-tool/OpossumUI/releases/latest' | ||
); | ||
if (!response.data) { | ||
return null; | ||
} | ||
const name = response.data.name as string; | ||
const url = response.data.html_url as string; | ||
return { name, url }; | ||
} |
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
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