Skip to content

Commit

Permalink
fix dubious display
Browse files Browse the repository at this point in the history
  • Loading branch information
g5bot committed Feb 4, 2025
1 parent 44e52c2 commit 1519fa9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,17 @@ public function render(CellDataInterface $data, PanelAttributesInterface $panel)

private function getDisplayCount(SpacecraftCountData $data): ?string
{
if ($data->isDubious()) {
return "!";
}

if (!$data->isEnabled()) {
return null;
}

$spacecraftCount = $data->getSpacecraftCount();
if ($spacecraftCount > 0) {
return (string) $spacecraftCount;
return $data->isDubious() ? '!' : (string) $spacecraftCount;
}
if ($data->hasCloakedShips()) {
if ($this->showCloakedEverywhere) {
return "?";
return $data->isDubious() ? '!' : "?";
}

$currentSpacecraft = $this->currentSpacecraft;
Expand All @@ -59,7 +55,7 @@ private function getDisplayCount(SpacecraftCountData $data): ?string
&& abs($data->getPosX() - $currentSpacecraft->getPosX()) <= $this->getTachyonRange($currentSpacecraft)
&& abs($data->getPosY() - $currentSpacecraft->getPosY()) <= $this->getTachyonRange($currentSpacecraft)
) {
return "?";
return $data->isDubious() ? '!' : "?";
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,43 @@ protected function setUp(): void
$this->panel = mock(AbstractVisualPanel::class);
}

public function testRenderExpectExclamationMarkWhenDubiousEffect(): void
public function testRenderExpectNothingWhenDubiousEffectButNoSignatures(): void
{
$mapData = $this->mock(SpacecraftCountData::class);

$mapData->shouldReceive('isEnabled')
->withNoArgs()
->andReturn(true);
$mapData->shouldReceive('isDubious')
->withNoArgs()
->andReturn(true);
$mapData->shouldReceive('getSpacecraftCount')
->withNoArgs()
->andReturn(0);
$mapData->shouldReceive('hasCloakedShips')
->withNoArgs()
->andReturn(false);

$subject = new SpacecraftCountLayerRenderer(false, null);

$result = $subject->render($mapData, $this->panel);

$this->assertEquals('', $result);
}

public function testRenderExpectExclamationMarkWhenDubiousEffectAndSignatures(): void
{
$mapData = $this->mock(SpacecraftCountData::class);

$mapData->shouldReceive('isEnabled')
->withNoArgs()
->andReturn(true);
$mapData->shouldReceive('isDubious')
->withNoArgs()
->andReturn(true);
$mapData->shouldReceive('getSpacecraftCount')
->withNoArgs()
->andReturn(42);

$this->panel->shouldReceive('getFontSize')
->withNoArgs()
Expand Down Expand Up @@ -87,13 +117,24 @@ public function testRenderExpectShipCount(): void
$this->assertEquals('<div style="FONTSIZE; z-index: 6;" class="centered">1</div>', $result);
}

public function testRenderExpectCloakedInfoWhenSet(): void
public static function dubiousAndCloakedSignDataProvider(): array
{
return [
[false, '?'],
[true, '!'],
];
}

#[DataProvider('dubiousAndCloakedSignDataProvider')]
public function testRenderExpectCloakedInfoWhenSet(
bool $isDubious,
string $expectedSign
): void {
$mapData = $this->mock(SpacecraftCountData::class);

$mapData->shouldReceive('isDubious')
->withNoArgs()
->andReturn(false);
->andReturn($isDubious);
$mapData->shouldReceive('isEnabled')
->withNoArgs()
->andReturn(true);
Expand All @@ -113,7 +154,7 @@ public function testRenderExpectCloakedInfoWhenSet(): void

$result = $subject->render($mapData, $this->panel);

$this->assertEquals('<div style="FONTSIZE; z-index: 6;" class="centered">?</div>', $result);
$this->assertEquals(sprintf('<div style="FONTSIZE; z-index: 6;" class="centered">%s</div>', $expectedSign), $result);
}

public function testRenderExpectNoCloakedInfoWhenNotSet(): void
Expand Down Expand Up @@ -217,7 +258,7 @@ public static function parameterDataProvider(): array
}

#[DataProvider('parameterDataProvider')]
public function testRenderExpectNoCloakedInfoWhenTachyonInRange(
public function testRenderExpectCloakedInfoWhenTachyonInRange(
bool $isStation,
int $shipX,
int $shipY,
Expand Down

0 comments on commit 1519fa9

Please sign in to comment.