This repository has been archived by the owner on Jul 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c47eed
commit c09bdd7
Showing
5 changed files
with
252 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
Oops, something went wrong.