mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Prevent re-downloading update that is already downloaded (#5781)
This commit is contained in:
parent
4d99a46dfe
commit
5ac33a6070
@ -1,5 +1,225 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`encourage user to update when sufficient time passed since update was downloaded when started given the update check when update downloaded given some time passes, when checking for updates again when checking for updates resolves with same version that was previously downloaded renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
class="ClusterManager"
|
||||
>
|
||||
<div
|
||||
class="topBar"
|
||||
>
|
||||
<div
|
||||
class="items"
|
||||
>
|
||||
<i
|
||||
class="Icon material interactive focusable"
|
||||
data-testid="home-button"
|
||||
tabindex="0"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="home"
|
||||
>
|
||||
home
|
||||
</span>
|
||||
</i>
|
||||
<i
|
||||
class="Icon material interactive disabled focusable"
|
||||
data-testid="history-back"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="arrow_back"
|
||||
>
|
||||
arrow_back
|
||||
</span>
|
||||
</i>
|
||||
<i
|
||||
class="Icon material interactive disabled focusable"
|
||||
data-testid="history-forward"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="arrow_forward"
|
||||
>
|
||||
arrow_forward
|
||||
</span>
|
||||
</i>
|
||||
<button
|
||||
class="updateButton"
|
||||
data-testid="update-button"
|
||||
data-warning-level="light"
|
||||
id="update-lens-button"
|
||||
>
|
||||
Update
|
||||
<i
|
||||
class="Icon icon material focusable"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="arrow_drop_down"
|
||||
>
|
||||
arrow_drop_down
|
||||
</span>
|
||||
</i>
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
class="items"
|
||||
/>
|
||||
</div>
|
||||
<main>
|
||||
<div
|
||||
id="lens-views"
|
||||
/>
|
||||
<div
|
||||
class="flex justify-center Welcome align-center"
|
||||
data-testid="welcome-page"
|
||||
>
|
||||
<div
|
||||
data-testid="welcome-banner-container"
|
||||
style="width: 320px;"
|
||||
>
|
||||
<i
|
||||
class="Icon logo svg focusable"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
/>
|
||||
</i>
|
||||
<div
|
||||
class="flex justify-center"
|
||||
>
|
||||
<div
|
||||
data-testid="welcome-text-container"
|
||||
style="width: 320px;"
|
||||
>
|
||||
<h2>
|
||||
Welcome to OpenLens 5!
|
||||
</h2>
|
||||
<p>
|
||||
To get you started we have auto-detected your clusters in your
|
||||
|
||||
kubeconfig file and added them to the catalog, your centralized
|
||||
|
||||
view for managing all your cloud-native resources.
|
||||
<br />
|
||||
<br />
|
||||
If you have any questions or feedback, please join our
|
||||
<a
|
||||
class="link"
|
||||
href="https://join.slack.com/t/k8slens/shared_invite/zt-wcl8jq3k-68R5Wcmk1o95MLBE5igUDQ"
|
||||
rel="noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
Lens Community slack channel
|
||||
</a>
|
||||
.
|
||||
</p>
|
||||
<ul
|
||||
class="block"
|
||||
data-testid="welcome-menu-container"
|
||||
style="width: 320px;"
|
||||
>
|
||||
<li
|
||||
class="flex grid-12"
|
||||
>
|
||||
<i
|
||||
class="Icon box col-1 material focusable"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="view_list"
|
||||
>
|
||||
view_list
|
||||
</span>
|
||||
</i>
|
||||
<a
|
||||
class="box col-10"
|
||||
>
|
||||
Browse Clusters in Catalog
|
||||
</a>
|
||||
<i
|
||||
class="Icon box col-1 material focusable"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="navigate_next"
|
||||
>
|
||||
navigate_next
|
||||
</span>
|
||||
</i>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<div
|
||||
class="HotbarMenu flex column"
|
||||
>
|
||||
<div
|
||||
class="HotbarItems flex column gaps"
|
||||
/>
|
||||
<div
|
||||
class="HotbarSelector"
|
||||
>
|
||||
<i
|
||||
class="Icon Icon previous material interactive focusable"
|
||||
tabindex="0"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="arrow_left"
|
||||
>
|
||||
arrow_left
|
||||
</span>
|
||||
</i>
|
||||
<div
|
||||
class="HotbarIndex"
|
||||
>
|
||||
<div
|
||||
class="badge Badge small clickable"
|
||||
id="hotbarIndex"
|
||||
>
|
||||
0
|
||||
</div>
|
||||
</div>
|
||||
<i
|
||||
class="Icon material interactive focusable"
|
||||
tabindex="0"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="arrow_right"
|
||||
>
|
||||
arrow_right
|
||||
</span>
|
||||
</i>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="StatusBar"
|
||||
>
|
||||
<div
|
||||
class="leftSide"
|
||||
data-testid="status-bar-left"
|
||||
/>
|
||||
<div
|
||||
class="rightSide"
|
||||
data-testid="status-bar-right"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="Notifications flex column align-flex-end"
|
||||
/>
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`encourage user to update when sufficient time passed since update was downloaded when started renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
|
||||
@ -194,6 +194,46 @@ describe("analytics for installing update", () => {
|
||||
await downloadPlatformUpdateMock.resolve({ downloadWasSuccessful: true });
|
||||
});
|
||||
|
||||
describe("given checking for updates again", () => {
|
||||
beforeEach(() => {
|
||||
const processCheckingForUpdates = mainDi.inject(processCheckingForUpdatesInjectable);
|
||||
|
||||
processCheckingForUpdates("irrelevant");
|
||||
|
||||
analyticsListenerMock.mockClear();
|
||||
});
|
||||
|
||||
it("when check resolves with same version that was previously downloaded, does not send event to analytics about update discovered", async () => {
|
||||
await checkForPlatformUpdatesMock.resolve({
|
||||
updateWasDiscovered: true,
|
||||
version: "43.0.0",
|
||||
});
|
||||
|
||||
expect(analyticsListenerMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("when check resolves with different version that was previously downloaded, sends event to analytics about update discovered", async () => {
|
||||
await checkForPlatformUpdatesMock.resolve({
|
||||
updateWasDiscovered: true,
|
||||
version: "44.0.0",
|
||||
});
|
||||
|
||||
expect(analyticsListenerMock.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
name: "app",
|
||||
action: "update-was-discovered",
|
||||
|
||||
params: {
|
||||
version: "44.0.0",
|
||||
currentDateTime: "2015-10-21T07:28:00Z",
|
||||
},
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it("does not send event to analytics about update downloaded being successful", () => {
|
||||
expect(analyticsListenerMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@ -18,6 +18,7 @@ import processCheckingForUpdatesInjectable from "../../main/application-update/c
|
||||
import quitAndInstallUpdateInjectable from "../../main/application-update/quit-and-install-update.injectable";
|
||||
import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time";
|
||||
|
||||
|
||||
function daysToMilliseconds(days: number) {
|
||||
return Math.round(days * 24 * 60 * 60 * 1000);
|
||||
}
|
||||
@ -73,10 +74,13 @@ describe("encourage user to update when sufficient time passed since update was
|
||||
});
|
||||
|
||||
describe("given the update check", () => {
|
||||
let processCheckingForUpdates: (source: string) => Promise<void>;
|
||||
let processCheckingForUpdatesPromise: Promise<void>;
|
||||
|
||||
beforeEach(async () => {
|
||||
const processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(processCheckingForUpdatesInjectable);
|
||||
processCheckingForUpdates = applicationBuilder.dis.mainDi.inject(
|
||||
processCheckingForUpdatesInjectable,
|
||||
);
|
||||
|
||||
processCheckingForUpdatesPromise = processCheckingForUpdates("irrelevant");
|
||||
});
|
||||
@ -104,6 +108,33 @@ describe("encourage user to update when sufficient time passed since update was
|
||||
expect(button).toHaveAttribute("data-warning-level", "light");
|
||||
});
|
||||
|
||||
describe("given some time passes, when checking for updates again", () => {
|
||||
beforeEach(() => {
|
||||
advanceFakeTime(daysToMilliseconds(2));
|
||||
|
||||
processCheckingForUpdates("irrelevant");
|
||||
});
|
||||
|
||||
describe("when checking for updates resolves with same version that was previously downloaded", () => {
|
||||
beforeEach(async () => {
|
||||
await checkForPlatformUpdatesMock.resolve({
|
||||
updateWasDiscovered: true,
|
||||
version: "some-version",
|
||||
});
|
||||
});
|
||||
|
||||
it("when enough time from download passes for medium update encouragement, has medium emotional indication in the button", () => {
|
||||
advanceFakeTime(daysToMilliseconds(20));
|
||||
|
||||
expect(button).toHaveAttribute("data-warning-level", "medium");
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
expect(rendered.baseElement).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when button is clicked", () => {
|
||||
beforeEach(() => {
|
||||
act(() => button.click());
|
||||
|
||||
@ -193,6 +193,59 @@ describe("installing update", () => {
|
||||
it("renders", () => {
|
||||
expect(rendered.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
describe("given checking for updates again", () => {
|
||||
beforeEach(() => {
|
||||
downloadPlatformUpdateMock.mockClear();
|
||||
|
||||
processCheckingForUpdates("irrelevant");
|
||||
});
|
||||
|
||||
it("shows tray icon for checking for updates", () => {
|
||||
expect(applicationBuilder.tray.getIconPath()).toBe(
|
||||
"/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png",
|
||||
);
|
||||
});
|
||||
|
||||
describe("when check resolves with same update that is already downloaded", () => {
|
||||
beforeEach(async () => {
|
||||
await checkForPlatformUpdatesMock.resolve({
|
||||
updateWasDiscovered: true,
|
||||
version: "some-version",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not re-download the update", () => {
|
||||
expect(downloadPlatformUpdateMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("shows tray icon for update being available", () => {
|
||||
expect(applicationBuilder.tray.getIconPath()).toBe(
|
||||
"/some-static-files-directory/icons/trayIconUpdateAvailableTemplate.png",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when check resolves with different update that was previously downloaded", () => {
|
||||
beforeEach(async () => {
|
||||
await checkForPlatformUpdatesMock.resolve({
|
||||
updateWasDiscovered: true,
|
||||
version: "some-other-version",
|
||||
});
|
||||
});
|
||||
|
||||
it("downloads the update", () => {
|
||||
expect(downloadPlatformUpdateMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("shows tray icon for downloading update", () => {
|
||||
expect(applicationBuilder.tray.getIconPath()).toBe(
|
||||
"/some-static-files-directory/icons/trayIconCheckingForUpdatesTemplate.png",
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -49,6 +49,16 @@ const processCheckingForUpdatesInjectable = getInjectable({
|
||||
|
||||
const { version, actualUpdateChannel } = result;
|
||||
|
||||
const previouslyDiscovered = discoveredVersionState.value.get();
|
||||
|
||||
if (version === previouslyDiscovered?.version) {
|
||||
runInAction(() => {
|
||||
checkingForUpdatesState.set(false);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
emitEvent({
|
||||
name: "app",
|
||||
action: "update-was-discovered",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user