- Old tests fixed
- Added a static Fixuture class for test mockups
This commit is contained in:
@@ -3,48 +3,11 @@ import { descriptor as cd } from "@core/commands/cd";
|
||||
import type { ResultError, ResultSuccess } from "@core/result";
|
||||
import type { UserInfo } from "@core/session_manager";
|
||||
import { getCurrentSession } from "@core/session_manager";
|
||||
import { createInitialShellState, withCwd, type ShellState } from "@core/shell_state";
|
||||
import { withCwd, type ShellState } from "@core/shell_state";
|
||||
import type { PathResolutionError } from "@core/util/errors";
|
||||
import { buildTestFS, type FixtureNode } from "@tests/helpers/filesystems_fixture";
|
||||
import { Fixture } from "@tests/helpers/state_fixture";
|
||||
import { 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 stdout: Uint8Array[] = [];
|
||||
const stderr: Uint8Array[] = [];
|
||||
|
||||
@@ -70,7 +33,7 @@ const user: UserInfo = {
|
||||
};
|
||||
users.set(0, user);
|
||||
|
||||
const state: ShellState = createInitialShellState(fs, users, user);
|
||||
const state: ShellState = Fixture.State;
|
||||
|
||||
test("changes cwd to home", async () => {
|
||||
let newState = withCwd(state, 2);
|
||||
@@ -80,7 +43,7 @@ test("changes cwd to home", async () => {
|
||||
const session = getCurrentSession(newState);
|
||||
|
||||
expect((result as ResultSuccess).exitCode).toBe(0);
|
||||
expect(session.cwd).toBe(0);
|
||||
expect(session.cwd).toBe(Fixture.user.home);
|
||||
expect(session.pwd).toBe(2);
|
||||
});
|
||||
test("changes cwd to pwd", async () => {
|
||||
@@ -96,7 +59,7 @@ test("changes cwd to pwd", async () => {
|
||||
expect(session.pwd).toBe(2);
|
||||
});
|
||||
test("changes cwd to 4", async () => {
|
||||
const output = await cd.fn(io, state, [], ["/sub/bye"]);
|
||||
const output = await cd.fn(io, state, [], ["/folder2/subdir2"]);
|
||||
const newState = output.state;
|
||||
const result = output.result;
|
||||
const session = getCurrentSession(newState);
|
||||
@@ -118,7 +81,7 @@ test("returns an error result (tried to enter a non existent location)", async (
|
||||
});
|
||||
|
||||
test("returns an error result (tried to enter a file)", async () => {
|
||||
const output = await cd.fn(io, state, [], ["/hello.txt"]);
|
||||
const output = await cd.fn(io, state, [], ["/some-file"]);
|
||||
const newState = output.state;
|
||||
const result = output.result;
|
||||
const session = getCurrentSession(newState);
|
||||
|
||||
Reference in New Issue
Block a user