Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions app/Models/LinkList.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class LinkList extends Model implements Auditable
'created_at',
'updated_at',
'random',
'links_count',
];

public string $langBase = 'list';
Expand Down
1 change: 1 addition & 0 deletions app/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Tag extends Model implements Auditable
'created_at',
'updated_at',
'random',
'links_count',
];

public string $langBase = 'tag';
Expand Down
30 changes: 30 additions & 0 deletions tests/Controller/Models/ListControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,36 @@ public function test_index_view(): void
]);
}

public function test_index_view_with_sorting(): void
{
$list1 = LinkList::factory()->create([
'name' => 'Test List',
'user_id' => $this->user->id,
]);
$list2 = LinkList::factory()->create([
'name' => 'Example List',
'user_id' => $this->user->id,
]);

$linksGroups = Link::factory()->count(5)->create()->split(2);
$linksGroups[0]->each(fn($link) => $link->lists()->attach([$list1->id]));
$linksGroups[1]->each(fn($link) => $link->lists()->attach([$list2->id]));

$this->get('lists?orderBy=links_count&orderDir=desc')
->assertOk()
->assertSeeInOrder([
'Test List',
'Example List',
]);

$this->get('lists?orderBy=links_count&orderDir=asc')
->assertOk()
->assertSeeInOrder([
'Example List',
'Test List',
]);
}

public function test_index_view_with_valid_filter_result(): void
{
LinkList::factory()->create([
Expand Down
30 changes: 30 additions & 0 deletions tests/Controller/Models/TagControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,36 @@ public function test_index_view(): void
]);
}

public function test_index_view_with_sorting(): void
{
$tag1 = Tag::factory()->create([
'name' => 'Test Tag',
'user_id' => $this->user->id,
]);
$tag2 = Tag::factory()->create([
'name' => 'Example Tag',
'user_id' => $this->user->id,
]);

$linksGroups = Link::factory()->count(5)->create()->split(2);
$linksGroups[0]->each(fn($link) => $link->tags()->attach([$tag1->id]));
$linksGroups[1]->each(fn($link) => $link->tags()->attach([$tag2->id]));

$this->get('tags?orderBy=links_count&orderDir=desc')
->assertOk()
->assertSeeInOrder([
'Test Tag',
'Example Tag',
]);

$this->get('tags?orderBy=links_count&orderDir=asc')
->assertOk()
->assertSeeInOrder([
'Example Tag',
'Test Tag',
]);
}

public function test_index_view_with_valid_filter_result(): void
{
Tag::factory()->create([
Expand Down
Loading