Skip to content

Commit

Permalink
Add reply keyboard feature to scenarios (#181)
Browse files Browse the repository at this point in the history
* Add reply keyboard feature to scenarios

* Only run tests on PRs and on main merge

* Always wait in scenarios
  • Loading branch information
LucaBernstein authored Aug 11, 2022
1 parent 28a55ce commit d9b3fa5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Go

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/scenarios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Scenarios

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

concurrency: scenario

Expand Down
31 changes: 31 additions & 0 deletions scenarioTests/features/keyboard.feature
Original file line number Diff line number Diff line change
@@ -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"
24 changes: 24 additions & 0 deletions scenarioTests/steps/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit d9b3fa5

Please sign in to comment.