Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add integration tests for dashboard data
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Sep 19, 2022
commit f2482bcae4291ad03826f02455f80808cec0661a
73 changes: 73 additions & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,79 @@ protected function preparePollExpectedData(array $expected): array {
return $expected;
}

/**
* @Then /^user "([^"]*)" sees the following entry when loading the list of dashboard widgets(?: \((v1)\))$/
*
* @param string $user
* @param string $apiVersion
* @param ?TableNode $formData
*/
public function userGetsDashboardWidgets($user, $apiVersion = 'v1', TableNode $formData = null): void {
$this->setCurrentUser($user);
$this->sendRequest('GET', '/apps/dashboard/api/' . $apiVersion . '/widgets');
$this->assertStatusCode($this->response, 200);

$data = $this->getDataFromResponse($this->response);
$expectedWidgets = $formData->getColumnsHash();

foreach ($expectedWidgets as $widget) {
$id = $widget['id'];
Assert::assertArrayHasKey($widget['id'], $data);

$widgetIconUrl = $widget['icon_url'];
$dataIconUrl = $data[$id]['icon_url'];

unset($widget['icon_url'], $data[$id]['icon_url']);

$widget['item_icons_round'] = (bool) $widget['item_icons_round'];
$widget['order'] = (int) $widget['order'];
$widget['buttons'] = json_decode($widget['buttons'], true);

Assert::assertEquals($widget, $data[$id], 'Mismatch of data for widget ' . $id);
Assert::assertStringEndsWith($widgetIconUrl, $dataIconUrl, 'Mismatch of icon URL for widget ' . $id);
}
}

/**
* @Then /^user "([^"]*)" sees the following entries for dashboard widgets "([^"]*)"(?: \((v1)\))$/
*
* @param string $user
* @param string $widgetId
* @param string $apiVersion
* @param ?TableNode $formData
*/
public function userGetsDashboardWidgetItems($user, $widgetId, $apiVersion = 'v1', TableNode $formData = null): void {
$this->setCurrentUser($user);
$this->sendRequest('GET', '/apps/dashboard/api/' . $apiVersion . '/widget-items?widgets[]=' . $widgetId);
$this->assertStatusCode($this->response, 200);

$data = $this->getDataFromResponse($this->response);

Assert::assertArrayHasKey($widgetId, $data);
$expectedItems = $formData->getColumnsHash();

if (empty($expectedItems)) {
Assert::assertEmpty($data[$widgetId]);
return;
}

Assert::assertCount(count($expectedItems), $data[$widgetId]);

foreach ($expectedItems as $key => $widget) {
$widget['link'] = $this->baseUrl . 'index.php/call/' . self::$identifierToToken[$widget['link']];

Assert::assertEquals($widget, $data[$widgetId][$key], 'Wrong details for item #' . $key);
}
}

/**
* @Then /^sleep 1 second$/
*
*/
public function sleepOneSecond(): void {
sleep(1);
}

/**
* @Then /^user "([^"]*)" deletes message "([^"]*)" from room "([^"]*)" with (\d+)(?: \((v1)\))?$/
*
Expand Down
35 changes: 35 additions & 0 deletions tests/integration/features/integration/dashboard.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Feature: integration/dashboard
Background:
Given user "participant1" exists
Given user "participant2" exists

Scenario: User gets the available dashboard widgets
When user "participant1" sees the following entry when loading the list of dashboard widgets (v1)
| id | title | icon_class | icon_url | widget_url | item_icons_round | order | buttons |
| spreed | Talk mentions | dashboard-talk-icon | img/app-dark.svg | http://localhost:8080/index.php/apps/spreed/ | true | 10 | [{"type":"more","text":"More unread mentions","link":"http://localhost:8080/index.php/apps/spreed/"}] |

Scenario: User gets the dashboard widget content
When user "participant1" sees the following entries for dashboard widgets "spreed" (v1)
| title | subtitle | link | iconUrl |
Given user "participant2" creates room "one-to-one room" (v4)
| roomType | 1 |
| invite | participant1 |
And user "participant2" sends message "Hello" to room "one-to-one room" with 201
And sleep 1 second
Given user "participant2" creates room "group room" (v4)
| roomType | 2 |
| roomName | group room |
And user "participant2" adds user "participant1" to room "group room" with 200 (v4)
And user "participant2" sends message "Hello @all" to room "group room" with 201
And sleep 1 second
Given user "participant2" creates room "call room" (v4)
| roomType | 3 |
| roomName | call room |
And user "participant2" adds user "participant1" to room "call room" with 200 (v4)
And user "participant2" joins room "call room" with 200 (v4)
And user "participant2" joins call "call room" with 200 (v4)
When user "participant1" sees the following entries for dashboard widgets "spreed" (v1)
| title | subtitle | link | iconUrl | sinceId |
| participant2-displayname | Hello | one-to-one room | http://localhost:8080/index.php/avatar/participant2/64 | |
| group room | Hello group room | group room | http://localhost:8080/core/img/actions/group.svg | |
| call room | @participant2-displayname started a call | call room | http://localhost:8080/core/img/actions/public.svg | |