Skip to content
This repository has been archived by the owner on Jul 18, 2022. It is now read-only.

Commit

Permalink
splitting the test files up a bunch
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpowell committed Jul 3, 2019
1 parent 6c47eed commit c09bdd7
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 239 deletions.
83 changes: 83 additions & 0 deletions src/test/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* eslint @typescript-eslint/no-explicit-any: "off" */
import { assert } from "chai";
import * as vscode from "vscode";
import Config from "../services/config";
import SettingsHelper from "../settingsHelper";

class MockMemento implements vscode.Memento {
public get<T>(key: string): T | undefined;
public get<T>(key: string, defaultValue: T): T;
public get(key: any, defaultValue?: any) {
console.log(`${key}:${defaultValue}`);
throw new Error("Method not implemented.");
}
public update(key: string, value: any): Thenable<void> {
console.log(`${key}:${value}`);
throw new Error("Method not implemented.");
}
}

class MockContext implements vscode.ExtensionContext {
public subscriptions: { dispose(): any }[];
public workspaceState: vscode.Memento;
public globalState: vscode.Memento;
public extensionPath: string;
public asAbsolutePath(relativePath: string): string {
console.log(relativePath);
return process.execPath;
}
public storagePath: string | undefined;
public globalStoragePath: string;
public logPath: string;

public constructor() {
this.subscriptions = [];
this.extensionPath = "";
this.globalStoragePath = "";
this.logPath = "";

this.workspaceState = new MockMemento();
this.globalState = new MockMemento();
}
}

suite("end to end testing", () => {
const profileName = "end-to-end-test";
const profileSettings = {
"editor.fontSize": 24,
"workbench.colorTheme": "Default Light+"
};

let mockContext = new MockContext();

setup(async function() {
this.settingsHelper = new SettingsHelper(mockContext);
this.defaultSettings = await this.settingsHelper.getUserSettings();
this.config = new Config();
});

teardown(async function() {
await this.settingsHelper.updateUserSettings(this.defaultSettings);
await this.config.removeProfile(profileName);
await this.config.removeProfileSettings(profileName);
});

test("can change the vscode layout based on profile", async function() {
await this.config.addProfile(profileName);
await this.config.addProfileSettings(profileName, profileSettings);

let updateSettings = this.config.getProfileSettings(profileName);

await this.settingsHelper.updateUserSettings(updateSettings);

let currentSettings = await this.settingsHelper.getUserSettings();

assert.equal(
currentSettings["editor.fontSize"],
profileSettings["editor.fontSize"]
);

// uncomment for local testing if you want to view the changes applied to vscode
// await new Promise(resolve => setTimeout(resolve, 1000));
});
});
240 changes: 1 addition & 239 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
/* eslint @typescript-eslint/no-explicit-any: "off" */
import { assert } from "chai";
import * as vscode from "vscode";
import {
ExtensionId,
ConfigKey,
ConfigProfilesKey,
ConfigStorageKey
} from "../constants";
import Config from "../services/config";
import SettingsHelper from "../settingsHelper";
import { ExtensionId } from "../constants";

suite("basic extension tests", () => {
test("extension is registered", () => {
Expand All @@ -27,234 +20,3 @@ suite("basic extension tests", () => {
}, 200);
});
});

suite("select profile", () => {
const expectedProfileName = "test1";
const expectedProfileSettings = { foo: "bar" };

setup(async () => {
let config = vscode.workspace.getConfiguration(ConfigKey);

await config.update(
ConfigProfilesKey,
[expectedProfileName],
vscode.ConfigurationTarget.Global
);
await config.update(
ConfigStorageKey,
{
[expectedProfileName]: expectedProfileSettings
},
vscode.ConfigurationTarget.Global
);
});

teardown(async () => {
let config = vscode.workspace.getConfiguration(ConfigKey);

await config.update(
ConfigProfilesKey,
undefined,
vscode.ConfigurationTarget.Global
);
await config.update(
ConfigStorageKey,
undefined,
vscode.ConfigurationTarget.Global
);
});

test("list of profiles will contain the expected one", () => {
let config = new Config();

let profiles = config.getProfiles();

assert.include(profiles, expectedProfileName);
});

test("storage contains the expected profile", () => {
let config = new Config();

let settings = config.getProfileSettings(expectedProfileName);

assert.deepEqual(settings, expectedProfileSettings);
});
});

suite("save profile", () => {
const expectedProfileName = "test1";
const expectedProfileSettings = { foo: "bar" };
const expectedUpdatedProfileSettings = { foo: "baz", a: "b" };

teardown(async () => {
let config = vscode.workspace.getConfiguration(ConfigKey);

await config.update(
ConfigProfilesKey,
undefined,
vscode.ConfigurationTarget.Global
);
await config.update(
ConfigStorageKey,
undefined,
vscode.ConfigurationTarget.Global
);
});

test("can save a profile name", async () => {
var config = new Config();

await config.addProfile(expectedProfileName);

let profiles = config.getProfiles();
assert.include(profiles, expectedProfileName);
});

test("can save profile settings", async () => {
var config = new Config();

await config.addProfileSettings(
expectedProfileName,
expectedProfileSettings
);

let settings = config.getProfileSettings(expectedProfileName);
assert.deepEqual(settings, expectedProfileSettings);
});

test("can update existing profile", async () => {
var config = new Config();

await config.addProfileSettings(
expectedProfileName,
expectedProfileSettings
);
await config.addProfileSettings(
expectedProfileName,
expectedUpdatedProfileSettings
);

let settings = config.getProfileSettings(expectedProfileName);
assert.deepEqual(settings, expectedUpdatedProfileSettings);
});
});

suite("remove profile", () => {
const expectedProfileName = "test1";
const expectedProfileSettings = { foo: "bar" };

setup(async () => {
let config = vscode.workspace.getConfiguration(ConfigKey);

await config.update(
ConfigProfilesKey,
[expectedProfileName],
vscode.ConfigurationTarget.Global
);
await config.update(
ConfigStorageKey,
{
[expectedProfileName]: expectedProfileSettings
},
vscode.ConfigurationTarget.Global
);
});

test("can remove profile name", async () => {
let config = new Config();

await config.removeProfile(expectedProfileName);

let profiles = config.getProfiles();

assert.notInclude(profiles, expectedProfileName);
});

test("can remove profile settings", async () => {
let config = new Config();

await config.removeProfileSettings(expectedProfileName);

let settings = config.getProfileSettings(expectedProfileName);

assert.isUndefined(settings);
});
});

suite("end to end testing", () => {
const profileName = "end-to-end-test";
const profileSettings = {
"editor.fontSize": 24,
"workbench.colorTheme": "Default Light+"
};

class MockMemento implements vscode.Memento {
public get<T>(key: string): T | undefined;
public get<T>(key: string, defaultValue: T): T;
public get(key: any, defaultValue?: any) {
console.log(`${key}:${defaultValue}`);
throw new Error("Method not implemented.");
}
public update(key: string, value: any): Thenable<void> {
console.log(`${key}:${value}`);
throw new Error("Method not implemented.");
}
}

class MockContext implements vscode.ExtensionContext {
public subscriptions: { dispose(): any }[];
public workspaceState: vscode.Memento;
public globalState: vscode.Memento;
public extensionPath: string;
public asAbsolutePath(relativePath: string): string {
console.log(relativePath);
return process.execPath;
}
public storagePath: string | undefined;
public globalStoragePath: string;
public logPath: string;

public constructor() {
this.subscriptions = [];
this.extensionPath = "";
this.globalStoragePath = "";
this.logPath = "";

this.workspaceState = new MockMemento();
this.globalState = new MockMemento();
}
}

let mockContext = new MockContext();

setup(async function() {
this.settingsHelper = new SettingsHelper(mockContext);
this.defaultSettings = await this.settingsHelper.getUserSettings();
this.config = new Config();
});

teardown(async function() {
await this.settingsHelper.updateUserSettings(this.defaultSettings);
await this.config.removeProfile(profileName);
await this.config.removeProfileSettings(profileName);
});

test("can change the vscode layout based on profile", async function() {
await this.config.addProfile(profileName);
await this.config.addProfileSettings(profileName, profileSettings);

let updateSettings = this.config.getProfileSettings(profileName);

await this.settingsHelper.updateUserSettings(updateSettings);

let currentSettings = await this.settingsHelper.getUserSettings();

assert.equal(
currentSettings["editor.fontSize"],
profileSettings["editor.fontSize"]
);

// uncomment for local testing if you want to view the changes applied to vscode
// await new Promise(resolve => setTimeout(resolve, 1000));
});
});
47 changes: 47 additions & 0 deletions src/test/removeProfile.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint @typescript-eslint/no-explicit-any: "off" */
import { assert } from "chai";
import * as vscode from "vscode";
import { ConfigKey, ConfigProfilesKey, ConfigStorageKey } from "../constants";
import Config from "../services/config";

suite("remove profile", () => {
const expectedProfileName = "test1";
const expectedProfileSettings = { foo: "bar" };

setup(async () => {
let config = vscode.workspace.getConfiguration(ConfigKey);

await config.update(
ConfigProfilesKey,
[expectedProfileName],
vscode.ConfigurationTarget.Global
);
await config.update(
ConfigStorageKey,
{
[expectedProfileName]: expectedProfileSettings
},
vscode.ConfigurationTarget.Global
);
});

test("can remove profile name", async () => {
let config = new Config();

await config.removeProfile(expectedProfileName);

let profiles = config.getProfiles();

assert.notInclude(profiles, expectedProfileName);
});

test("can remove profile settings", async () => {
let config = new Config();

await config.removeProfileSettings(expectedProfileName);

let settings = config.getProfileSettings(expectedProfileName);

assert.isUndefined(settings);
});
});
Loading

0 comments on commit c09bdd7

Please # to comment.