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

postmarketos: use pretty_name for display labels #3324

Merged
merged 1 commit into from
May 11, 2024
Merged
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
11 changes: 3 additions & 8 deletions src/core/plugins/postmarketos/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,8 @@ const getInterfaces = device =>
const devices = data.releases.find(c => c.name === "edge").devices;
const interfaces = devices
.find(d => d.name.includes(device))
.interfaces.map(i => i.name);
return interfaces.map(i => {
if (i === "phosh") return { value: i, label: "Phosh" };
if (i === "plasma-mobile") return { value: i, label: "Plasma Mobile" };
if (i === "sxmo-de-sway") return { value: i, label: "SXMO Sway" };
return { value: i, label: i };
});
.interfaces.map(i => ({ value: i.name, label: i.pretty_name }));
return interfaces;
})
.catch(error => {
if (error?.response?.status === 404) throw new Error("404");
Expand Down Expand Up @@ -97,7 +92,7 @@ const getReleases = device =>
const releases = data.releases;
return releases
.filter(release => release.devices.find(d => d.name.includes(device)))
.map(release => release.name);
.map(i => ({ value: i.name, label: i.pretty_name }));
})
.catch(error => {
if (error?.response?.status === 404) throw new Error("404");
Expand Down
24 changes: 18 additions & 6 deletions src/core/plugins/postmarketos/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ const MOCK_DATA = {
releases: [
{
name: "edge",
pretty_name: "edge (unsupported)",
devices: [
{
name: "somedevice",
pretty_name: "Some Device",
interfaces: [
{ name: "phosh" },
{
name: "phosh",
pretty_name: "Phosh"
},
{
name: "plasma-mobile",
pretty_name: "Plasma Mobile",
images: [
{
timestamp: 0,
Expand All @@ -27,8 +33,14 @@ const MOCK_DATA = {
}
]
},
{ name: "sxmo-de-sway" },
{ name: "other" }
{
name: "sxmo-de-sway",
pretty_name: "Sxmo (Sway)"
},
{
name: "other",
pretty_name: "Other"
}
]
}
]
Expand Down Expand Up @@ -56,11 +68,11 @@ describe("postmarketos api", () => {
});
expect(result).toContainEqual({
value: "sxmo-de-sway",
label: "SXMO Sway"
label: "Sxmo (Sway)"
});
expect(result).toContainEqual({
value: "other",
label: "other"
label: "Other"
});
});

Expand Down Expand Up @@ -111,7 +123,7 @@ describe("postmarketos api", () => {
describe("getReleases()", () => {
it("should resolve releases", async () => {
const result = await api.getReleases("somedevice");
expect(result).toEqual(["edge"]);
expect(result).toEqual([{"label": "edge (unsupported)", "value": "edge"}]);
});

it("should throw on 404", async () => {
Expand Down
8 changes: 1 addition & 7 deletions src/core/plugins/postmarketos/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,7 @@ class PostmarketOSPlugin extends Plugin {
*/
remote_values__releases() {
return api
.getReleases(this.props.os.codename ?? this.props.config.codename)
.then(releases =>
releases.map(release => ({
value: release,
label: release
}))
);
.getReleases(this.props.os.codename ?? this.props.config.codename);
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/core/plugins/postmarketos/plugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,16 @@ describe("postmarketos plugin", () => {

describe("remote_values__releases()", () => {
it("should get releases", async () => {
api.getReleases.mockResolvedValueOnce(["a", "b"]);
api.getReleases.mockResolvedValueOnce([{value: "a", label: "aA"},
{value: "b", label: "bB"}]);
const result = await pmosPlugin.remote_values__releases();
expect(api.getReleases).toHaveBeenCalledWith("os_codename");
expect(result).toContainEqual({
label: "a",
label: "aA",
value: "a"
});
expect(result).toContainEqual({
label: "b",
label: "bB",
value: "b"
});
});
Expand Down
Loading