Skip to content
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

Alternative way to add onboarding steps #34

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions src/OnboardingSteps.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public function addStep(string $title, string $model = null): OnboardingStep
{
$step = new OnboardingStep($title);

return $this->addOnboardingStep($step, $model);
fedeisas marked this conversation as resolved.
Show resolved Hide resolved
}

public function addOnboardingStep(OnboardingStep $step, string $model = null): OnboardingStep
{
if ($model && new $model() instanceof Onboardable) {
return $this->steps[$model][] = $step;
}
Expand Down
48 changes: 48 additions & 0 deletions tests/OnboardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


use Spatie\Onboard\OnboardingManager;
use Spatie\Onboard\OnboardingStep;
use Spatie\Onboard\OnboardingSteps;
use Spatie\Onboard\Tests\Team;
use Spatie\Onboard\Tests\User;
Expand Down Expand Up @@ -294,3 +295,50 @@
->user_name->toBe($this->user->name)
->title->tobe('Step 1');
});

test('can add step objects', function () {
$onboardingSteps = new OnboardingSteps();
$firstStep = (new OnboardingStep('Step 1'))
->link('/some/url')
->cta('Test This!');
$secondStep = (new class ('Step 2') extends OnboardingStep {})
->link('/another/url')
->cta('Test That!');
$onboardingSteps->addOnboardingStep($firstStep);
$onboardingSteps->addOnboardingStep($secondStep);

$onboarding = new OnboardingManager($this->user, $onboardingSteps);

$step = $onboarding->steps()->first();

expect($step)
->title->toBe('Step 1')
->cta->toBe('Test This!');

expect($onboarding->steps()->last())
->title->toBe('Step 2')
->cta->toBe('Test That!');

$firstStep->title = 'Step 11';
$secondStep->title = 'Step 22';

expect($step)
->title->toBe('Step 11')
->toArray()->toBe([
'title' => 'Step 11',
'link' => '/some/url',
'cta' => 'Test This!',
'complete' => false,
'excluded' => false,
]);

expect($onboarding->steps()->last())
->title->toBe('Step 22')
->toArray()->toBe([
'title' => 'Step 22',
'link' => '/another/url',
'cta' => 'Test That!',
'complete' => false,
'excluded' => false,
]);
});