fix: open individual sectors from catalogue cards without repeated detail
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -47,17 +47,22 @@ class SectorCatalogueContentTest extends TestCase
|
||||
$before = [DB::table('desk_cases')->count(), DB::table('opportunities')->count(), DB::table('portal_resources')->count()];
|
||||
|
||||
$props = $this->get('/sectores')->assertOk()->inertiaProps();
|
||||
$this->assertSame(array_column($props['sectors'], 'id'), array_column(array_column($props['sectorDetails'], 'sector'), 'id'));
|
||||
foreach ($props['sectorDetails'] as $detail) {
|
||||
$single = $this->get('/sectores/'.$detail['sector']['slug'])->assertOk()->inertiaProps();
|
||||
$this->assertSame($single['sector'], $detail['sector']);
|
||||
$this->assertSame($single['sectorEntry'], $detail['sectorEntry']);
|
||||
$this->assertSame($single['opportunities'], $detail['opportunities']);
|
||||
$this->assertIsArray($detail['sectorEntry']['articles']);
|
||||
$this->assertIsArray($detail['sectorEntry']['relations']);
|
||||
$this->assertIsArray($detail['sectorEntry']['locations']);
|
||||
$this->assertArrayNotHasKey('sectorDetails', $props);
|
||||
$ids = array_column($props['sectors'], 'id');
|
||||
$this->assertSame($ids, array_values(array_unique($ids)));
|
||||
foreach ($props['sectors'] as $card) {
|
||||
$this->assertSame(\App\Services\SectorOrganization::href($card['slug']), $card['url']);
|
||||
$this->assertStringNotContainsString('#', $card['url']);
|
||||
$single = $this->get($card['url'])->assertOk()->inertiaProps();
|
||||
$this->assertSame('sector', $single['section']);
|
||||
$this->assertSame($card['id'], $single['sector']['id']);
|
||||
$this->assertArrayNotHasKey('sectorDetails', $single);
|
||||
$this->assertArrayNotHasKey('sectors', $single);
|
||||
$this->assertIsArray($single['sectorEntry']['articles']);
|
||||
$this->assertIsArray($single['sectorEntry']['relations']);
|
||||
$this->assertIsArray($single['sectorEntry']['locations']);
|
||||
}
|
||||
$entry = collect($props['sectorDetails'])->firstWhere('sector.id', $withoutGuide->id)['sectorEntry'];
|
||||
$entry = $this->get('/sectores/'.$withoutGuide->slug)->assertOk()->inertiaProps()['sectorEntry'];
|
||||
$this->assertSame([], $entry['articles']);
|
||||
$this->assertSame('/minhas-oportunidades/create?sector_id='.$withoutGuide->id, $entry['register_href']);
|
||||
$this->assertNotNull($entry['start_href']);
|
||||
@@ -80,10 +85,11 @@ class SectorCatalogueContentTest extends TestCase
|
||||
}
|
||||
config(['investor-path.enabled' => false, 'portal.profile_access_enabled' => false]);
|
||||
$props = $this->get('/sectores')->assertOk()->inertiaProps();
|
||||
$ids = array_column(array_column($props['sectorDetails'], 'sector'), 'id');
|
||||
$this->assertArrayNotHasKey('sectorDetails', $props);
|
||||
$ids = array_column($props['sectors'], 'id');
|
||||
$this->assertNotContains($unpublished->id, $ids);
|
||||
$this->assertNotContains($inactive->id, $ids);
|
||||
$detail = collect($props['sectorDetails'])->firstWhere('sector.id', $public->id);
|
||||
$detail = $this->get('/sectores/'.$public->slug)->assertOk()->inertiaProps();
|
||||
$this->assertSame([$slugs['published']], array_column($detail['opportunities'], 'slug'));
|
||||
$this->assertNull($detail['sectorEntry']['start_href']);
|
||||
$this->assertNull($detail['sectorEntry']['register_href']);
|
||||
@@ -92,4 +98,29 @@ class SectorCatalogueContentTest extends TestCase
|
||||
$this->get('/sectores/'.$unpublished->slug)->assertNotFound();
|
||||
$this->get('/sectores/'.$inactive->slug)->assertNotFound();
|
||||
}
|
||||
public function test_selecting_a_sector_keeps_opportunities_scoped_on_reload_and_return(): void
|
||||
{
|
||||
$a = $this->sector();$b = $this->sector();
|
||||
foreach ([$a, $b] as $sector) {
|
||||
$slug = 'qa-isolated-'.Str::lower(Str::random(12));
|
||||
Opportunity::create(['sector_id'=>$sector->id, 'reference'=>$slug, 'title'=>$slug, 'slug'=>$slug,
|
||||
'summary'=>'Synthetic scoped opportunity', 'status'=>'published', 'published_at'=>now()->subDay()]);
|
||||
}
|
||||
$index = $this->get('/sectores')->assertOk()->inertiaProps();
|
||||
foreach ([$a, $b, $a] as $sector) {
|
||||
$url = collect($index['sectors'])->firstWhere('id', $sector->id)['url'];
|
||||
$first = $this->get($url)->assertOk()->inertiaProps();
|
||||
$reload = $this->get($url)->assertOk()->inertiaProps();
|
||||
$this->assertSame($first['sector'], $reload['sector']);
|
||||
$this->assertSame($first['opportunities'], $reload['opportunities']);
|
||||
$this->assertSame($sector->id, $first['sector']['id']);
|
||||
$this->assertSame(Opportunity::where('sector_id',$sector->id)->pluck('slug')->all(), array_column($first['opportunities'],'slug'));
|
||||
$this->assertSame('/investimentos/a-partir-do-setor/'.$sector->slug, $first['sectorEntry']['start_href']);
|
||||
$this->get($first['sectorEntry']['start_href'])->assertRedirect('/login');
|
||||
$returned = $this->get('/sectores')->assertOk()->inertiaProps();
|
||||
$this->assertSame($index['sectors'], $returned['sectors']);
|
||||
$this->assertArrayNotHasKey('sectorDetails', $returned);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user