Skip to content

Commit

Permalink
issue-861: Enable find items in settings editor by IDs
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Jelinek <[email protected]>
  • Loading branch information
djelinek committed Oct 3, 2023
1 parent 01ffaaf commit 3a154bc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 31 deletions.
53 changes: 42 additions & 11 deletions page-objects/src/components/editor/SettingsEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,46 @@ export class SettingsEditor extends Editor {
await searchBox.sendKeys(Key.chord(SettingsEditor.ctlKey, 'a'));
await searchBox.sendKeys(`${category}: ${title}`);

let setting!: Setting;
const items = await this._getSettingItems();

for (const item of items) {
try {
return await (await this.createSetting(item, title, category)).wait();
} catch (err) {
}
}
return setting;
}

/**
* Search for a setting with a precise ID.
* Returns an appropriate Setting object if it exists,
* undefined otherwise.
*
* @param id of the setting
* @returns Promise resolving to a Setting object if found, undefined otherwise
*/
async findSettingByID(id: string): Promise<Setting> {
const searchBox = await this.findElement(SettingsEditor.locators.Editor.inputArea);
await searchBox.sendKeys(Key.chord(SettingsEditor.ctlKey, 'a'));
await searchBox.sendKeys(id);

let setting!: Setting;
const items = await this._getSettingItems();

for (const item of items) {
try {
const category = (await (await item.findElement(SettingsEditor.locators.SettingsEditor.settingCategory)).getText()).replace(':', '');
const title = await (await item.findElement(SettingsEditor.locators.SettingsEditor.settingLabel)).getText();
return await (await this.createSetting(item, title, category)).wait();
} catch (err) {
}
}
return setting;
}

private async _getSettingItems(): Promise<WebElement[]> {
const count = await this.findElement(SettingsEditor.locators.SettingsEditor.itemCount);
let textCount = await count.getText();

Expand All @@ -44,18 +84,9 @@ export class SettingsEditor extends Editor {
return true;
});

let setting!: Setting;
const items = await this.findElements(SettingsEditor.locators.SettingsEditor.itemRow);

for (const item of items) {
try {
return (await this.createSetting(item, title, category)).wait();
} catch (err) {
}
}
return setting;
return await this.findElements(SettingsEditor.locators.SettingsEditor.itemRow);
}

/**
* Switch between settings perspectives
* Works only if your vscode instance has both user and workspace settings available
Expand Down
46 changes: 26 additions & 20 deletions test/test-project/src/test/editor/settingsEditor-test.ts
Original file line number Diff line number Diff line change
@@ -1,98 +1,104 @@
import { expect } from 'chai';
import { SettingsEditor, Workbench, EditorView, ComboSetting, TextSetting, CheckboxSetting } from 'vscode-extension-tester';

describe('SettingsEditor', () => {
describe('Settings Editor', function () {
let editor: SettingsEditor;

before(async function() {
before(async function () {
this.timeout(10000);
editor = await new Workbench().openSettings();
});

after(async () => {
after(async function () {
await new EditorView().closeAllEditors();
});

it('findSetting works', async function() {
it('findSetting works', async function () {
this.timeout(15000);
const setting = await editor.findSetting('Title Bar Style', 'Window');
expect(setting).not.undefined;
});

it('findSetting works for nested configurations', async function() {
it('findSetting by ID works', async function () {
this.timeout(15000);
const setting = await editor.findSettingByID('testProject.general.helloWorld');
expect(setting).not.undefined;
});

it('findSetting works for nested configurations', async function () {
this.timeout(15000);
const setting = await editor.findSetting('Hello World', 'Test Project', 'General');
expect(setting).not.undefined;
});

describe('combo setting', () => {
describe('combo setting', function () {
let setting: ComboSetting;

before(async function() {
before(async function () {
this.timeout(15000);
setting = await editor.findSetting('Title Bar Style', 'Window') as ComboSetting;
});

it('getTitle works', async () => {
it('getTitle works', async function () {
const title = await setting.getTitle();
expect(title).equals('Title Bar Style');
});

it('getCategory works', async () => {
it('getCategory works', async function () {
const cat = await setting.getCategory();
expect(cat).equals('Window:');
});

it('getValue works', async () => {
it('getValue works', async function () {
const value = await setting.getValue();
expect(value).equals('custom');
});

it('getValues works', async () => {
it('getValues works', async function () {
const values = await setting.getValues();
expect(values).contains.members(['native', 'custom']);
});

it('getDescription works', async () => {
it('getDescription works', async function () {
const desc = await setting.getDescription();
expect(desc).not.empty;
});
});

describe('text setting', () => {
describe('text setting', function () {
let setting: TextSetting;

before(async function() {
before(async function () {
this.timeout(15000);
setting = await editor.findSetting('Auto Save Delay', 'Files') as TextSetting;
});

it('getValue works', async () => {
it('getValue works', async function () {
const value = await setting.getValue();
expect(+value).greaterThan(0);
});

it('setValue works', async () => {
it('setValue works', async function () {
const newVal = '1001';
await setting.setValue(newVal);
expect(await setting.getValue()).equals(newVal);
});
});

describe('checkbox setting', () => {
describe('checkbox setting', function () {
let setting: CheckboxSetting;

before(async function() {
before(async function () {
this.timeout(15000);
setting = await editor.findSetting('Code Lens', 'Editor') as CheckboxSetting;
});

it('getValue works', async () => {
it('getValue works', async function () {
const value = await setting.getValue();
expect(value).is.true;
});

it('setValue works', async () => {
it('setValue works', async function () {
await setting.setValue(false);
expect(await setting.getValue()).is.false;
await setting.setValue(true);
Expand Down

0 comments on commit 3a154bc

Please sign in to comment.