Skip to content

Commit 56fbd39

Browse files
author
Akos Kitta
committed
fix: merged modules
Signed-off-by: Akos Kitta <[email protected]>
1 parent 8ca1b94 commit 56fbd39

File tree

5 files changed

+129
-139
lines changed

5 files changed

+129
-139
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,33 +0,0 @@
1-
import { Installable } from '../../../common/protocol';
2-
3-
export const ItemActionLiterals = [
4-
'installLatest',
5-
'installSelected',
6-
'update',
7-
'remove',
8-
'unknown',
9-
] as const;
10-
export type ItemActionType = typeof ItemActionLiterals[number];
11-
12-
export function itemAction(params: {
13-
installed?: Installable.Version | undefined;
14-
available: Installable.Version[];
15-
selected?: Installable.Version;
16-
}): ItemActionType {
17-
const { installed, available } = params;
18-
const latest = Installable.latest(available);
19-
if (!latest || (installed && !available.includes(installed))) {
20-
return 'unknown';
21-
}
22-
const selected = params.selected ?? latest;
23-
if (installed === selected) {
24-
return 'remove';
25-
}
26-
if (installed) {
27-
return selected === latest && installed !== latest
28-
? 'update'
29-
: 'installSelected';
30-
} else {
31-
return selected === latest ? 'installLatest' : 'installSelected';
32-
}
33-
}

Diff for: arduino-ide-extension/src/browser/widgets/component-list/list-item-renderer.tsx

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import * as React from '@theia/core/shared/react';
2-
import { inject, injectable } from '@theia/core/shared/inversify';
31
import { WindowService } from '@theia/core/lib/browser/window/window-service';
4-
import { Installable } from '../../../common/protocol/installable';
5-
import { ArduinoComponent } from '../../../common/protocol/arduino-component';
6-
import { ComponentListItem } from './component-list-item';
7-
import { nls } from '@theia/core/lib/common';
2+
import { nls } from '@theia/core/lib/common/nls';
3+
import { inject, injectable } from '@theia/core/shared/inversify';
4+
import * as React from '@theia/core/shared/react';
85
import { Unknown } from '../../../common/nls';
9-
import { itemAction } from './item-action';
6+
import type { ArduinoComponent } from '../../../common/protocol/arduino-component';
7+
import { Installable } from '../../../common/protocol/installable';
8+
import type { ComponentListItem } from './component-list-item';
109

1110
@injectable()
1211
export class ListItemRenderer<T extends ArduinoComponent> {
@@ -62,7 +61,7 @@ export class ListItemRenderer<T extends ArduinoComponent> {
6261
}
6362
};
6463

65-
const actionType = itemAction({
64+
const actionType = Installable.action({
6665
installed: installedVersion,
6766
available: availableVersions,
6867
selected: selectedVersion,

Diff for: arduino-ide-extension/src/common/protocol/installable.ts

+32
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,38 @@ export namespace Installable {
5151
};
5252
}
5353

54+
export const ActionLiterals = [
55+
'installLatest',
56+
'installSelected',
57+
'update',
58+
'remove',
59+
'unknown',
60+
] as const;
61+
export type Action = typeof ActionLiterals[number];
62+
63+
export function action(params: {
64+
installed?: Version | undefined;
65+
available: Version[];
66+
selected?: Version;
67+
}): Action {
68+
const { installed, available } = params;
69+
const latest = Installable.latest(available);
70+
if (!latest || (installed && !available.includes(installed))) {
71+
return 'unknown';
72+
}
73+
const selected = params.selected ?? latest;
74+
if (installed === selected) {
75+
return 'remove';
76+
}
77+
if (installed) {
78+
return selected === latest && installed !== latest
79+
? 'update'
80+
: 'installSelected';
81+
} else {
82+
return selected === latest ? 'installLatest' : 'installSelected';
83+
}
84+
}
85+
5486
export function latest(versions: Version[]): Version | undefined {
5587
if (!versions.length) {
5688
return undefined;

Diff for: arduino-ide-extension/src/test/browser/item-action.test.ts

-98
This file was deleted.

Diff for: arduino-ide-extension/src/test/common/installable.test.ts

+90
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,94 @@ describe('installable', () => {
3939
});
4040
});
4141
});
42+
43+
describe('action', () => {
44+
const installLatest: Installable.Action = 'installLatest';
45+
const installSelected: Installable.Action = 'installSelected';
46+
const update: Installable.Action = 'update';
47+
const remove: Installable.Action = 'remove';
48+
const unknown: Installable.Action = 'unknown';
49+
const notAvailable = '0.0.0';
50+
const latest = '2.0.0';
51+
// shuffled versions
52+
const available: Installable.Version[] = [
53+
'1.4.1',
54+
'1.0.0',
55+
latest,
56+
'2.0.0-beta.1',
57+
'1.5',
58+
];
59+
60+
it("should result 'unknown' if available is empty", () => {
61+
expect(Installable.action({ available: [] })).to.be.equal(unknown);
62+
});
63+
it("should result 'unknown' if installed is not in available", () => {
64+
expect(
65+
Installable.action({ available, installed: notAvailable })
66+
).to.be.equal(unknown);
67+
});
68+
69+
it("should result 'installLatest' if not installed and not selected", () => {
70+
expect(Installable.action({ available })).to.be.equal(installLatest);
71+
});
72+
it("should result 'installLatest' if not installed and latest is selected", () => {
73+
expect(Installable.action({ available, selected: latest })).to.be.equal(
74+
installLatest
75+
);
76+
});
77+
78+
it("should result 'installSelected' if not installed and not latest is selected", () => {
79+
available
80+
.filter((version) => version !== latest)
81+
.forEach((selected) =>
82+
expect(
83+
Installable.action({
84+
available,
85+
selected,
86+
})
87+
).to.be.equal(installSelected)
88+
);
89+
});
90+
it("should result 'installSelected' if installed and the selected is neither the latest nor the installed", () => {
91+
available.forEach((installed) =>
92+
available
93+
.filter((selected) => selected !== latest && selected !== installed)
94+
.forEach((selected) =>
95+
expect(
96+
Installable.action({
97+
installed,
98+
available,
99+
selected,
100+
})
101+
).to.be.equal(installSelected)
102+
)
103+
);
104+
});
105+
106+
it("should result 'update' if the installed version is not the latest and the latest is selected", () => {
107+
available
108+
.filter((installed) => installed !== latest)
109+
.forEach((installed) =>
110+
expect(
111+
Installable.action({
112+
installed,
113+
available,
114+
selected: latest,
115+
})
116+
).to.be.equal(update)
117+
);
118+
});
119+
120+
it("should result 'remove' if the selected version equals the installed version", () => {
121+
available.forEach((version) =>
122+
expect(
123+
Installable.action({
124+
installed: version,
125+
available,
126+
selected: version,
127+
})
128+
).to.be.equal(remove)
129+
);
130+
});
131+
});
42132
});

0 commit comments

Comments
 (0)