diff --git a/.github/workflows/golang.yml b/.github/workflows/golang.yml index f4c4f0a..4ff5afe 100644 --- a/.github/workflows/golang.yml +++ b/.github/workflows/golang.yml @@ -2,6 +2,9 @@ name: Go on: push: + branches: [ main ] + pull_request: + branches: [ main ] jobs: test: diff --git a/.github/workflows/scenarios.yml b/.github/workflows/scenarios.yml index 8df4d80..598c165 100644 --- a/.github/workflows/scenarios.yml +++ b/.github/workflows/scenarios.yml @@ -2,6 +2,9 @@ name: Scenarios on: push: + branches: [ main ] + pull_request: + branches: [ main ] concurrency: scenario diff --git a/scenarioTests/features/keyboard.feature b/scenarioTests/features/keyboard.feature new file mode 100644 index 0000000..50f744a --- /dev/null +++ b/scenarioTests/features/keyboard.feature @@ -0,0 +1,31 @@ +Feature: Bot suggestions keyboard + + Scenario: Suggest last used values + Given I have a bot + When I send the message "/suggestions rm accFrom" + And I wait 0.2 seconds + And I send the message "/suggestions add accFrom fromAccount" + And I wait 0.2 seconds + When I send the message "1.00" + Then 2 messages should be sent back + And the response should include the message "Automatically created a new transaction for you" + And the response should have a keyboard with the first entry being "fromAccount" + When I send the message "/cancel" + + Scenario: Last used suggestion appears on top + Given I have a bot + When I send the message "/deleteAll yes" + And I wait 0.2 seconds + And I send the message "/suggestions rm accFrom" + And I wait 0.2 seconds + And I send the message "/suggestions add accFrom fromAccount" + And I wait 0.2 seconds + And I create a simple tx with amount 1.23 and accFrom someFromAccount and accTo someToAccount and desc Test Tx + And I send the message "/list" + Then 1 messages should be sent back + And the response should include the message " someFromAccount -1.23 EUR" + When I send the message "1.00" + Then 2 messages should be sent back + And the response should include the message "Automatically created a new transaction for you" + And the response should have a keyboard with the first entry being "someFromAccount" + When I send the message "/cancel" diff --git a/scenarioTests/steps/bot.py b/scenarioTests/steps/bot.py index 5598a4b..fea2f14 100644 --- a/scenarioTests/steps/bot.py +++ b/scenarioTests/steps/bot.py @@ -25,6 +25,7 @@ async def getBotSingletonLazy(): async def step_impl(context): context.chat = await getBotSingletonLazy() context.testChatId = context.chat.testChatId + await wait_seconds(0.1) async def bot_send_message(bot: TestBot, chat, message): message = await bot.client.send_message(chat, message) @@ -74,6 +75,22 @@ async def step_impl(context, message): print("substring", message, "could not be found in", response.text) assert False +@then('the response should have a keyboard with {position} entry being "{keyboardEntry}"') +@async_run_until_complete +async def step_impl(context, position, keyboardEntry): + positionMapping = { + 'the first': 0, + 'the second': 1, + 'any': -1 + } + assert position in positionMapping + assert len(context.responses) > 0 + response = context.responses[-1] + replyKeyboard = response.reply_markup + # TODO: Add column support if needed + print("Asserting", replyKeyboard.rows[positionMapping[position]].buttons[0].text, "equals", keyboardEntry) + assert replyKeyboard.rows[positionMapping[position]].buttons[0].text == keyboardEntry + @when('I get the server endpoint "{endpoint}"') @async_run_until_complete async def step_impl(context, endpoint): @@ -126,3 +143,10 @@ async def step_impl(context, shouldShouldNot): except AssertionError: print("expected response", expectedResponse, "did not match actual response", response) assert False + +@when('I create a simple tx with amount {amount} and accFrom {accFrom} and accTo {accTo} and desc {desc}') +@async_run_until_complete +async def step_impl(context, amount, accFrom, accTo, desc): + for command in ["/cancel", amount, accFrom, accTo, desc]: + context.offsetId = (await bot_send_message(context.chat, context.testChatId, command)).id + await wait_seconds(0.1)