Skip to content

Commit

Permalink
Merge pull request #143 from Progi1984/fixImportPlayrwright
Browse files Browse the repository at this point in the history
Endpoint `reports/{id}` : Fixed import Playwright
  • Loading branch information
Progi1984 committed Feb 22, 2024
2 parents c3662ad + 20ccd7b commit 8eea88d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
23 changes: 2 additions & 21 deletions src/Service/ReportSuiteBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,32 +71,13 @@ public function filterSuite(?int $suiteId = null): self

public function build(Execution $execution): self
{
// Fetch suites
$this->suites = $execution->getSuitesCollection()->toArray();

// Find if there is main suite id
$hasOnlyOneMainSuite = false;
$mainSuiteId = null;
foreach ($this->suites as $suite) {
if ($suite->getParentId()) {
continue;
}

if ($hasOnlyOneMainSuite) {
// There is another suite with null, so not only one is used
// Used for legacy purpose
$hasOnlyOneMainSuite = false;
$mainSuiteId = null;
break;
}

$hasOnlyOneMainSuite = true;
$mainSuiteId = $suite->getId();
}
// Extract tests
$this->tests = $this->getTests();

// Build the recursive tree
$this->suites = $this->buildTree($mainSuiteId, true);
$this->suites = $this->buildTree(null, true);
$this->suites = $this->filterTree($this->suites);

return $this;
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/ImportPlaywrightCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testImportBlockwislist(): void
$command = $application->find('nightly:import:playwright');
$commandTester = new CommandTester($command);
$commandTester->execute([
'--platform' => 'cli',
'--platform' => 'chromium',
'--campaign' => 'blockwishlist',
'filename' => 'blockwishlist_2024-01-25-develop.json',
]);
Expand Down
31 changes: 26 additions & 5 deletions tests/Controller/ReportControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ public static function dataProviderReportFilters(): array
return [
[[], 6],
[['filter_campaign[0]' => 'functional'], 2],
[['filter_platform' => 'chromium'], 3],
[['filter_browser' => 'chromium'], 3],
[['filter_platform' => 'chromium'], 4],
[['filter_browser' => 'chromium'], 4],
[['filter_version' => 'develop'], 6],
];
}
Expand Down Expand Up @@ -149,10 +149,15 @@ public function testCorsReportID(): void
$this->assertEquals($response->headers->get('access-control-allow-origin'), '*');
}

public function testReportID(): void
/**
* @dataProvider dataProviderReportID
*
* @param array<string> $campaigns
*/
public function testReportID(int $reportId, array $campaigns): void
{
$client = static::createClient();
$client->request('GET', '/reports/2');
$client->request('GET', '/reports/' . $reportId);
$response = $client->getResponse();

$this->assertEquals(200, $response->getStatusCode());
Expand All @@ -167,7 +172,7 @@ public function testReportID(): void
$this->assertArrayHasKey('date', $content);
$this->assertArrayHasKey('version', $content);
$this->assertArrayHasKey('campaign', $content);
$this->assertContains($content['campaign'], ReportMochaImporter::FILTER_CAMPAIGNS);
$this->assertContains($content['campaign'], $campaigns);
$this->assertArrayHasKey('browser', $content);
$this->assertContains($content['browser'], ReportMochaImporter::FILTER_PLATFORMS);
$this->assertArrayHasKey('platform', $content);
Expand Down Expand Up @@ -195,11 +200,27 @@ public function testReportID(): void

$this->assertArrayHasKey('suites_data', $content);
$this->assertIsArray($content['suites_data']);
$this->assertNotEmpty($content['suites_data']);
foreach ($content['suites_data'] as $suiteId => $suiteItem) {
$this->partialTestSuite($content['id'], $suiteId, $suiteItem, null, true);
}
}

/**
* @return array<array<int>>
*/
public static function dataProviderReportID(): array
{
return [
// autoupgrade
[1, ReportMochaImporter::FILTER_CAMPAIGNS],
// functional
[2, ReportMochaImporter::FILTER_CAMPAIGNS],
// blockwishlist
[3, ReportPlaywrightImporter::FILTER_CAMPAIGNS],
];
}

public function testReportIDSuiteID(): void
{
$client = static::createClient();
Expand Down

0 comments on commit 8eea88d

Please sign in to comment.