68 lines
2.0 KiB
PHP
68 lines
2.0 KiB
PHP
<?php
|
|
|
|
use App\Livewire\SocialAccounts\Index;
|
|
use App\Models\SocialAccount;
|
|
use Livewire\Livewire;
|
|
|
|
test('social accounts index page lists existing accounts', function () {
|
|
SocialAccount::factory()->create(['username' => 'example_user']);
|
|
|
|
$this->get(route('social-accounts.index'))
|
|
->assertOk()
|
|
->assertSee('example_user');
|
|
});
|
|
|
|
test('a new social account can be created', function () {
|
|
Livewire::test(Index::class)
|
|
->set('network', 'twitter')
|
|
->set('username', 'new_user')
|
|
->set('email', 'new_user@example.com')
|
|
->set('password', 'secret123')
|
|
->set('type', 'post')
|
|
->call('save');
|
|
|
|
expect(SocialAccount::where('username', 'new_user')->exists())->toBeTrue();
|
|
});
|
|
|
|
test('network, username, email, and password are required', function () {
|
|
Livewire::test(Index::class)
|
|
->set('network', '')
|
|
->set('username', '')
|
|
->set('email', '')
|
|
->set('password', '')
|
|
->call('save')
|
|
->assertHasErrors(['network', 'username', 'email', 'password']);
|
|
});
|
|
|
|
test('type can be left null', function () {
|
|
Livewire::test(Index::class)
|
|
->set('network', 'reddit')
|
|
->set('username', 'no_type_user')
|
|
->set('email', 'no_type@example.com')
|
|
->set('password', 'secret123')
|
|
->set('type', null)
|
|
->call('save');
|
|
|
|
$account = SocialAccount::where('username', 'no_type_user')->first();
|
|
expect($account->type)->toBeNull();
|
|
});
|
|
|
|
test('an existing account can be edited', function () {
|
|
$account = SocialAccount::factory()->create(['username' => 'old_name']);
|
|
|
|
Livewire::test(Index::class)
|
|
->call('edit', $account->id)
|
|
->set('username', 'new_name')
|
|
->call('save');
|
|
|
|
expect($account->fresh()->username)->toBe('new_name');
|
|
});
|
|
|
|
test('an account can be deleted', function () {
|
|
$account = SocialAccount::factory()->create();
|
|
|
|
Livewire::test(Index::class)->call('delete', $account->id);
|
|
|
|
expect(SocialAccount::find($account->id))->toBeNull();
|
|
});
|