- Old tests fixed
- Added a static Fixuture class for test mockups
This commit is contained in:
@@ -1,57 +1,9 @@
|
||||
import { getCurrentSession, type UserInfo } from "@core/session_manager";
|
||||
import { createInitialShellState, type ShellState } from "@core/shell_state";
|
||||
import { getCurrentSession } from "@core/session_manager";
|
||||
import { Shell } from "@shell/shell";
|
||||
import { buildTestFS, type FixtureNode } from "@tests/helpers/filesystems_fixture";
|
||||
import { Fixture } from "@tests/helpers/state_fixture";
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
const testTree: FixtureNode = {
|
||||
inode: 0,
|
||||
name: "root",
|
||||
type: "Dir",
|
||||
children: [
|
||||
{
|
||||
inode: 1,
|
||||
name: "hello.txt",
|
||||
type: "File",
|
||||
content: "Goodbye World!",
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
inode: 2,
|
||||
name: "sub",
|
||||
type: "Dir",
|
||||
children: [
|
||||
{
|
||||
inode: 3,
|
||||
name: "world.txt",
|
||||
type: "File",
|
||||
content: "Goodbye!",
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
inode: 4,
|
||||
name: "bye",
|
||||
type: "Dir",
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const fs = buildTestFS(testTree);
|
||||
|
||||
const users: Map<number, UserInfo> = new Map();
|
||||
const user: UserInfo = {
|
||||
username: "root",
|
||||
uid: 0,
|
||||
gid: 0,
|
||||
group: [0],
|
||||
home: 0,
|
||||
};
|
||||
users.set(0, user);
|
||||
|
||||
const state: ShellState = createInitialShellState(fs, users, user);
|
||||
const state = Fixture.State;
|
||||
|
||||
describe("Shell tests", () => {
|
||||
test("Successfully executes the cd command", async () => {
|
||||
@@ -64,13 +16,13 @@ describe("Shell tests", () => {
|
||||
result = payload.result;
|
||||
});
|
||||
|
||||
await Shell.Instance?.execute("cd /sub");
|
||||
await Shell.Instance?.execute("cd /folder1");
|
||||
const statee = Shell.Instance?.State;
|
||||
|
||||
expect(result!.type).toEqual("success");
|
||||
expect(getCurrentSession(statee!).history.length).toBe(1);
|
||||
expect(getCurrentSession(statee!).history[0]).toEqual("cd /sub");
|
||||
expect(getCurrentSession(statee!).cwd).toBe(2);
|
||||
expect(getCurrentSession(statee!).history[0]).toEqual("cd /folder1");
|
||||
expect(getCurrentSession(statee!).cwd).toBe(1);
|
||||
expect(getCurrentSession(statee!).exitCode).toBe(0);
|
||||
});
|
||||
test("Returns a proper command error from cd", () => {});
|
||||
|
||||
Reference in New Issue
Block a user