Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getComboxBoxItems method to DefaultCommandHandler and app-connection.ts #264

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ option (FOCUSRITE_E2E_MAKE_TESTS "Build example app")
option (FOCUSRITE_E2E_FETCH_JUCE "Download JUCE")

set (CMAKE_DEBUG_POSTFIX d)
set (CXX_STANDARD_REQUIRED 17)

if (FOCUSRITE_E2E_FETCH_JUCE)
include (cmake/fetch-juce.cmake)
Expand Down
10 changes: 10 additions & 0 deletions example/tests/counter-app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,14 @@ describe('Count App tests', () => {
const value = await appConnection.getComboBoxSelectedItemIndex('combo-box');
expect(value).toBe(expectedValue);
});

it('checks that all values in combox box are present and in the correct order', async () => {
const expectedValues = ['First', 'Second', 'Third'];
const items = await appConnection.getComboBoxItems('combo-box');
let index = 0;
for (const value of expectedValues) {
expect(value).toEqual(items[index]);
index++;
}
});
});
28 changes: 28 additions & 0 deletions source/cpp/source/DefaultCommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,33 @@ Response getComboBoxNumItems (const Command & command)
return Response::fail (error);
}

Response getComboBoxItems (const Command & command)
{
auto comboBoxVariant = getComponent<juce::ComboBox> (command);
if (std::holds_alternative<juce::ComboBox *> (comboBoxVariant))
{
auto * comboBox = std::get<juce::ComboBox *> (comboBoxVariant);
const auto numItems = comboBox->getNumItems ();

if (numItems == 0)
{
return Response::fail (juce::String ("ComboBox is empty"));
}

juce::StringArray items;

for (auto i = 0; i < numItems; ++i)
{
items.add (comboBox->getItemText (i));
}

return Response::ok ().withParameter ("items", items);
source-streamer marked this conversation as resolved.
Show resolved Hide resolved
}

const auto error = std::get<juce::String> (comboBoxVariant);
return Response::fail (error);
}

Response setComboBoxSelectedItemIndex (const Command & command)
{
auto comboBoxVariant = getComponent<juce::ComboBox> (command);
Expand Down Expand Up @@ -610,6 +637,7 @@ std::optional<Response> DefaultCommandHandler::process (const Command & command)
[&] (auto && command) { return getComboBoxSelectedItemIndex (command); }},
{"get-combo-box-num-items",
[&] (auto && command) { return getComboBoxNumItems (command); }},
{"get-combo-box-items", [&] (auto && command) { return getComboBoxItems (command); }},
{"set-combo-box-selected-item-index",
[&] (auto && command) { return setComboBoxSelectedItemIndex (command); }},
{"get-accessibility-state",
Expand Down
12 changes: 12 additions & 0 deletions source/ts/app-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
AccessibilityParentResponse,
AccessibilityChildResponse,
GetFocusedComponentResponse,
GetComboBoxItemsResponse,
} from './responses';
import {Command} from './commands';
import minimatch from 'minimatch';
Expand Down Expand Up @@ -306,6 +307,17 @@ export class AppConnection extends EventEmitter {
return response.value;
}

async getComboBoxItems(comboBoxId: string): Promise<string[]> {
const response = (await this.sendCommand({
type: 'get-combo-box-items',
args: {
'component-id': comboBoxId,
},
})) as GetComboBoxItemsResponse;

return response.items;
}

async invokeMenu(menu: string): Promise<void> {
await this.sendCommand({
type: 'invoke-menu',
Expand Down
4 changes: 4 additions & 0 deletions source/ts/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export interface GetItemIndexResponse {
value: number;
}

export interface GetComboBoxItemsResponse {
items : string[];
}

export interface AccessibilityResponse {
title: string;
description: string;
Expand Down