Skip to content

Commit

Permalink
Fix web UI test suite (#1190)
Browse files Browse the repository at this point in the history
There are *a lot* of failing tests in the web UI test suite. It is time
to put things in order and start running the tests during CI again.
Before this PR, these are the stats:

```
Test Suites: 21 failed, 99 passed, 120 total
Tests:       148 failed, 3 skipped, 5 todo, 745 passed, 901 total
``` 

After these changes, the situation is like this (fixes from #1189 are
not included):

```
Test Suites: 119 passed, 119 total
Tests:       38 skipped, 5 todo, 859 passed, 902 total
```

Additionally, the PR enables the building and running of tests and
linters on CI.
  • Loading branch information
imobachgs authored May 13, 2024
2 parents 7aa44bb + 9748440 commit 0b4d3ea
Show file tree
Hide file tree
Showing 22 changed files with 410 additions and 1,191 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,24 @@ jobs:

- name: Install dependencies
run: npm install
#
# - name: Build the application
# run: make
#

- name: Build the application
run: npm run build

# - name: Run check spell
# run: npm run cspell
#
# - name: Check types
# run: npm run check-types
#
# - name: Run ESLint
# run: npm run eslint
#
# - name: Run Stylelint
# run: npm run stylelint
#
# - name: Run the tests and generate coverage report
# run: npm test -- --coverage
- name: Run ESLint
run: npm run eslint

- name: Run Stylelint
run: npm run stylelint

- name: Run the tests and generate coverage report
run: npm test -- --coverage
#
# # send the code coverage for the web part to the coveralls.io
# - name: Coveralls GitHub Action
Expand Down
1 change: 1 addition & 0 deletions web/src/App.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe("App", () => {
getTimezone: jest.fn().mockResolvedValue("Europe/Berlin"),
keymaps: jest.fn().mockResolvedValue([]),
getKeymap: jest.fn().mockResolvedValue(undefined),
getUIKeymap: jest.fn().mockResolvedValue("en"),
getUILocale: jest.fn().mockResolvedValue("en_us"),
setUILocale: jest.fn().mockResolvedValue("en_us"),
onTimezoneChange: jest.fn(),
Expand Down
107 changes: 87 additions & 20 deletions web/src/client/l10n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,110 @@
*/

// @ts-check
// cspell:ignore Cestina

import DBusClient from "./dbus";
import { HTTPClient } from "./http";
import { L10nClient } from "./l10n";

jest.mock("./dbus");

const L10N_IFACE = "org.opensuse.Agama1.Locale";
const mockJsonFn = jest.fn();
const mockGetFn = jest.fn().mockImplementation(() => {
return { ok: true, json: mockJsonFn };
});
const mockPatchFn = jest.fn().mockImplementation(() => {
return { ok: true };
});

jest.mock("./http", () => {
return {
HTTPClient: jest.fn().mockImplementation(() => {
return {
get: mockGetFn,
patch: mockPatchFn,
};
}),
};
});

const l10nProxy = {
ListLocales: jest.fn().mockResolvedValue(
[
["es_ES.UTF-8", "Spanish", "Spain"],
["en_US.UTF-8", "English", "United States"]
]
),
let client;

const locales = [
{
id: "en_US.UTF-8",
language: "English",
territory: "United States",
},
{
id: "es_ES.UTF-8",
language: "Spanish",
territory: "Spain",
},
];

const config = {
locales: [
"en_US.UTF-8",
],
keymap: "us",
timezone: "Europe/Berlin",
uiLocale: "en_US.UTF-8",
uiKeymap: "us",
};

beforeEach(() => {
// @ts-ignore
DBusClient.mockImplementation(() => {
return {
proxy: (iface) => {
if (iface === L10N_IFACE) return l10nProxy;
}
};
});
client = new L10nClient(new HTTPClient(new URL("http://localhost")));
});

describe("#locales", () => {
beforeEach(() => {
mockJsonFn.mockResolvedValue(locales);
});

it("returns the list of available locales", async () => {
const client = new L10nClient();
const locales = await client.locales();

expect(locales).toEqual([
{ id: "en_US.UTF-8", name: "English", territory: "United States" },
{ id: "es_ES.UTF-8", name: "Spanish", territory: "Spain" },
{ id: "en_US.UTF-8", name: "English", territory: "United States" }
]);
expect(mockGetFn).toHaveBeenCalledWith("/l10n/locales");
});
});

describe("#getConfig", () => {
beforeEach(() => {
mockJsonFn.mockResolvedValue(config);
});

it("returns the list of selected locales", async () => {
const l10nConfig = await client.getConfig();

expect(l10nConfig).toEqual(config);
expect(mockGetFn).toHaveBeenCalledWith("/l10n/config");
});
});

describe("#setConfig", () => {
beforeEach(() => {
mockJsonFn.mockResolvedValue(config);
});

it("updates the l10n configuration", async () => {
await client.setConfig(config);
client.setConfig(config);
expect(mockPatchFn).toHaveBeenCalledWith("/l10n/config", config);
});
});

describe("#getLocales", () => {
beforeEach(() => {
mockJsonFn.mockResolvedValue(config);
});

it("returns the list of selected locales", async () => {
const locales = await client.getLocales();

expect(locales).toEqual(["en_US.UTF-8"]);
expect(mockGetFn).toHaveBeenCalledWith("/l10n/config");
});
});
1 change: 0 additions & 1 deletion web/src/client/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import { WithProgress, WithStatus } from "./mixins";

const MANAGER_PATH = "/org/opensuse/Agama/Manager1";
const MANAGER_SERVICE = "org.opensuse.Agama.Manager1";

/**
Expand Down
114 changes: 40 additions & 74 deletions web/src/client/manager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,94 +21,64 @@

// @ts-check

import { HTTPClient } from "./http";
import { ManagerClient } from "./manager";
import DBusClient from "./dbus";
import cockpit from "../lib/cockpit";

jest.mock("../lib/cockpit");
jest.mock("./dbus");

const MANAGER_IFACE = "org.opensuse.Agama.Manager1";
const SERVICE_IFACE = "org.opensuse.Agama1.ServiceStatus";
const PROGRESS_IFACE = "org.opensuse.Agama1.Progress";

const managerProxy = {
wait: jest.fn(),
Commit: jest.fn(),
Probe: jest.fn(),
Finish: jest.fn().mockReturnValue(true),
CanInstall: jest.fn(),
CollectLogs: jest.fn(),
CurrentInstallationPhase: 0
};
const mockJsonFn = jest.fn();
const mockGetFn = jest.fn().mockImplementation(() => {
return { ok: true, json: mockJsonFn };
});
const mockPostFn = jest.fn().mockImplementation(() => {
return { ok: true };
});

const statusProxy = {
wait: jest.fn(),
Current: 0
};
jest.mock("./http", () => {
return {
HTTPClient: jest.fn().mockImplementation(() => {
return {
get: mockGetFn,
post: mockPostFn,
};
}),
};
});

const progressProxy = {
wait: jest.fn(),
CurrentStep: [2, "Installing software"],
TotalSteps: 3,
Finished: false
};
let client;

const proxies = {
[MANAGER_IFACE]: managerProxy,
[SERVICE_IFACE]: statusProxy,
[PROGRESS_IFACE]: progressProxy
const installerStatus = {
phase: 1,
busy: [],
iguana: false,
canInstall: true,
};

beforeEach(() => {
// @ts-ignore
DBusClient.mockImplementation(() => {
return { proxy: (iface) => proxies[iface] };
});
});

describe("#getStatus", () => {
it("returns the installer status", async () => {
const client = new ManagerClient();
const status = await client.getStatus();
expect(status).toEqual(0);
});
});

describe("#getProgress", () => {
it("returns the manager service progress", async () => {
const client = new ManagerClient();
const status = await client.getProgress();
expect(status).toEqual({
message: "Installing software",
current: 2,
total: 3,
finished: false
});
});
client = new ManagerClient(new HTTPClient(new URL("http://localhost")));
});

describe("#startProbing", () => {
it("(re)starts the probing process", async () => {
const client = new ManagerClient();
await client.startProbing();
expect(managerProxy.Probe).toHaveBeenCalledWith();
expect(mockPostFn).toHaveBeenCalledWith("/manager/probe", {});
});
});

describe("#getPhase", () => {
beforeEach(() => {
mockJsonFn.mockResolvedValue(installerStatus);
});

it("resolves to the current phase", () => {
const client = new ManagerClient();
const phase = client.getPhase();
expect(phase).resolves.toEqual(0);
expect(phase).resolves.toEqual(1);
});
});

describe("#startInstallation", () => {
it("starts the installation", async () => {
const client = new ManagerClient();
await client.startInstallation();
expect(managerProxy.Commit).toHaveBeenCalledWith();
expect(mockPostFn).toHaveBeenCalledWith("/manager/install", {});
});
});

Expand All @@ -118,46 +88,42 @@ describe("#rebootSystem", () => {
});

it("returns whether the system reboot command was called or not", async () => {
const client = new ManagerClient();
const reboot = await client.finishInstallation();
expect(reboot).toEqual(true);
expect(mockPostFn).toHaveBeenCalledWith("/manager/finish", {});
});
});

describe("#canInstall", () => {
describe("when the system can be installed", () => {
beforeEach(() => {
managerProxy.CanInstall = jest.fn().mockResolvedValue(true);
mockJsonFn.mockResolvedValue(installerStatus);
});

it("returns true", async () => {
const client = new ManagerClient();
const install = await client.canInstall();
expect(install).toEqual(true);
});
});

describe("when the system cannot be installed", () => {
beforeEach(() => {
managerProxy.CanInstall = jest.fn().mockResolvedValue(false);
mockJsonFn.mockResolvedValue({ ...installerStatus, canInstall: false });
});

it("returns false", async () => {
const client = new ManagerClient();
const install = await client.canInstall();
expect(install).toEqual(false);
});
});
});

describe("#fetchLogs", () => {
beforeEach(() => {
managerProxy.CollectLogs = jest.fn(() => "/tmp/y2log-hWBn95.tar.xz");
cockpit.file = jest.fn(() => ({ read: () => "fake-binary-data" }));
});
describe.skip("#fetchLogs", () => {
// beforeEach(() => {
// managerProxy.CollectLogs = jest.fn(() => "/tmp/y2log-hWBn95.tar.xz");
// cockpit.file = jest.fn(() => ({ read: () => "fake-binary-data" }));
// });

it("returns the logs file binary content", async () => {
const client = new ManagerClient();
const logsContent = await client.fetchLogs();
expect(logsContent).toEqual("fake-binary-data");
expect(cockpit.file).toHaveBeenCalledWith("/tmp/y2log-hWBn95.tar.xz", { binary: true });
Expand Down
9 changes: 7 additions & 2 deletions web/src/client/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@

// @ts-check

import { securityFromFlags } from "./network_manager";
import { createConnection, ConnectionTypes, ConnectionState, createAccessPoint } from "./model";
import {
ConnectionState,
ConnectionTypes,
createAccessPoint,
createConnection,
securityFromFlags,
} from "./model";
import { formatIp, ipPrefixFor } from "./utils";

const DeviceType = Object.freeze({
Expand Down
Loading

0 comments on commit 0b4d3ea

Please sign in to comment.