Skip to content

Commit

Permalink
Merge pull request #34 from tucuota/add_onboarding_step_method
Browse files Browse the repository at this point in the history
Alternative way to add onboarding steps
  • Loading branch information
freekmurze authored Nov 1, 2023
2 parents d32f276 + a62e542 commit 2e7e042
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
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->addingStep($step, $model);
}

public function addingStep(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->addingStep($firstStep);
$onboardingSteps->addingStep($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,
]);
});

0 comments on commit 2e7e042

Please sign in to comment.