Repository navigation
feat(activity): enum TimelineReaction #557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f8b6d37
feat(reaction): add TimelineReaction enum with labels and emojis
GabrielFVDev f25a87b
feat(reaction): update reaction column comment to use TimelineReactio…
GabrielFVDev cc63042
feat(reaction): enhance TimelineReaction enum with color and descript…
GabrielFVDev 5234b0e
feat(reaction): rename emoji method to getEmoji for consistency
GabrielFVDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
app-modules/activity/src/Reaction/Enums/TimelineReaction.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace He4rt\Activity\Reaction\Enums; | ||
|
|
||
| use App\Enums\Concerns\StringifyEnum; | ||
| use Filament\Support\Colors\Color; | ||
| use Filament\Support\Contracts\HasColor; | ||
| use Filament\Support\Contracts\HasDescription; | ||
| use Filament\Support\Contracts\HasLabel; | ||
|
|
||
| /** | ||
| * Conjunto fechado de reações da timeline web. O banco guarda só o value; | ||
| * rótulo, cor e glifo vivem aqui e nunca são persistidos. | ||
| */ | ||
| enum TimelineReaction: string implements HasColor, HasDescription, HasLabel | ||
| { | ||
| use StringifyEnum; | ||
|
|
||
| case Like = 'like'; | ||
| case Love = 'love'; | ||
| case Laugh = 'laugh'; | ||
| case Celebrate = 'celebrate'; | ||
| case Fire = 'fire'; | ||
| case Sad = 'sad'; | ||
|
|
||
| public function getLabel(): string | ||
| { | ||
| return match ($this) { | ||
| self::Like => 'Curtir', | ||
| self::Love => 'Amei', | ||
| self::Laugh => 'Haha', | ||
| self::Celebrate => 'Parabéns', | ||
| self::Fire => 'Fogo', | ||
| self::Sad => 'Triste', | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Conjunto não-ordenado: não há ramp claro->danger. Cada cor puxa a do | ||
| * próprio glifo, para o rótulo textual não brigar com o emoji ao lado. | ||
| * | ||
| * @return array<int, string> | ||
| */ | ||
| public function getColor(): array | ||
| { | ||
| return match ($this) { | ||
| self::Like => Color::Sky, | ||
| self::Love => Color::Rose, | ||
| self::Laugh => Color::Amber, | ||
| self::Celebrate => Color::Violet, | ||
| self::Fire => Color::Orange, | ||
| self::Sad => Color::Slate, | ||
| }; | ||
| } | ||
|
|
||
| public function getDescription(): string | ||
| { | ||
| return match ($this) { | ||
| self::Like => 'Concorda ou apoia sem muito peso', | ||
| self::Love => 'Guardou carinho pelo conteúdo', | ||
| self::Laugh => 'Achou graça', | ||
| self::Celebrate => 'Comemora uma conquista de alguém da comunidade', | ||
| self::Fire => 'Reconhece que o conteúdo ficou excelente', | ||
| self::Sad => 'Solidariza com uma notícia difícil', | ||
| }; | ||
| } | ||
|
|
||
| public function emoji(): string | ||
| { | ||
| return match ($this) { | ||
| self::Like => '👍', | ||
| self::Love => '❤️', | ||
| self::Laugh => '😂', | ||
| self::Celebrate => '🎉', | ||
| self::Fire => '🔥', | ||
| self::Sad => '😢', | ||
| }; | ||
| } | ||
| } | ||
71 changes: 71 additions & 0 deletions
71
app-modules/activity/tests/Unit/Reaction/TimelineReactionTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Filament\Support\Contracts\HasColor; | ||
| use Filament\Support\Contracts\HasDescription; | ||
| use Filament\Support\Contracts\HasLabel; | ||
| use He4rt\Activity\Reaction\Enums\TimelineReaction; | ||
|
|
||
| it('tem exatamente os seis casos do conjunto fixo', function (): void { | ||
| expect(TimelineReaction::cases())->toHaveCount(6) | ||
| ->and(TimelineReaction::Like->value)->toBe('like') | ||
| ->and(TimelineReaction::Love->value)->toBe('love') | ||
| ->and(TimelineReaction::Laugh->value)->toBe('laugh') | ||
| ->and(TimelineReaction::Celebrate->value)->toBe('celebrate') | ||
| ->and(TimelineReaction::Fire->value)->toBe('fire') | ||
| ->and(TimelineReaction::Sad->value)->toBe('sad'); | ||
| }); | ||
|
|
||
| it('implementa os contratos Filament para todos os casos', function (TimelineReaction $reaction): void { | ||
| expect($reaction)->toBeInstanceOf(HasColor::class) | ||
| ->toBeInstanceOf(HasDescription::class) | ||
| ->toBeInstanceOf(HasLabel::class) | ||
| ->and($reaction->getLabel())->toBeString()->not->toBeEmpty() | ||
| ->and($reaction->getColor())->toBeArray()->not->toBeEmpty() | ||
| ->and($reaction->getDescription())->toBeString()->not->toBeEmpty() | ||
| ->and($reaction->emoji())->toBeString()->not->toBeEmpty(); | ||
| })->with(TimelineReaction::cases()); | ||
|
|
||
| it('devolve o rótulo pt-BR de cada reação', function (): void { | ||
| expect(TimelineReaction::Like->getLabel())->toBe('Curtir') | ||
| ->and(TimelineReaction::Love->getLabel())->toBe('Amei') | ||
| ->and(TimelineReaction::Laugh->getLabel())->toBe('Haha') | ||
| ->and(TimelineReaction::Celebrate->getLabel())->toBe('Parabéns') | ||
| ->and(TimelineReaction::Fire->getLabel())->toBe('Fogo') | ||
| ->and(TimelineReaction::Sad->getLabel())->toBe('Triste'); | ||
| }); | ||
|
|
||
| it('devolve o glifo de cada reação', function (): void { | ||
| expect(TimelineReaction::Like->emoji())->toBe('👍') | ||
| ->and(TimelineReaction::Love->emoji())->toBe('❤️') | ||
| ->and(TimelineReaction::Laugh->emoji())->toBe('😂') | ||
| ->and(TimelineReaction::Celebrate->emoji())->toBe('🎉') | ||
| ->and(TimelineReaction::Fire->emoji())->toBe('🔥') | ||
| ->and(TimelineReaction::Sad->emoji())->toBe('😢'); | ||
| }); | ||
|
|
||
| it('não repete cor, rótulo, descrição nem glifo entre os casos', function (): void { | ||
| $cases = TimelineReaction::cases(); | ||
|
|
||
| $colors = array_map(fn (TimelineReaction $r): string => serialize($r->getColor()), $cases); | ||
| $labels = array_map(fn (TimelineReaction $r): string => $r->getLabel(), $cases); | ||
| $descriptions = array_map(fn (TimelineReaction $r): string => $r->getDescription(), $cases); | ||
| $emojis = array_map(fn (TimelineReaction $r): string => $r->emoji(), $cases); | ||
|
|
||
| expect(array_unique($colors))->toHaveCount(6) | ||
| ->and(array_unique($labels))->toHaveCount(6) | ||
| ->and(array_unique($descriptions))->toHaveCount(6) | ||
| ->and(array_unique($emojis))->toHaveCount(6); | ||
| }); | ||
|
|
||
| it('devolve null para valor fora do conjunto', function (): void { | ||
| expect(TimelineReaction::tryFrom('xpto'))->toBeNull() | ||
| ->and(TimelineReaction::tryFrom(''))->toBeNull() | ||
| ->and(TimelineReaction::tryFrom('👍'))->toBeNull(); | ||
| }); | ||
|
|
||
| it('lista os seis values em stringifyCases', function (): void { | ||
| expect(TimelineReaction::stringifyCases()) | ||
| ->toBe('Available enum cases: like, love, laugh, celebrate, fire, sad'); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.