#Clipboard contents after action has been clicked

11 messages · Page 1 of 1 (latest)

austere yacht
#

I want to tests a copy to clipboard action and im wondering if it is possible to grab the clipboard contents inside a test.

regal sphinxBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

austere yacht
plain atlas
austere yacht
# plain atlas could you share the code?
// Custom action btw
Action::make('copy')
    ->icon('heroicon-s-clipboard')
    ->color('gray')
    ->visible(fn ($state) => $this->getCopyable() && ! empty($state))
    ->action(function ($livewire, $state, Action $action) {
        $action->icon('heroicon-s-clipboard-document-check')
            ->color('success');

        $livewire->dispatch('copy-to-clipboard', text: $state);
    }),
#

After that is basically writes to the clipboard. navigator.clipboard.writeText(text);

#

But im not sure if we can even access something like that in tests. 🤔

plain atlas
austere yacht
#

Mmm, what i wanted to test is if the state was matching the clipboard, so have to execute some JS i think 🤔

#

This will be a nice addition to it tho.

->assertDispatched('copy-to-clipboard')
✓ it can copy to clipboard with ('email')
✓ it can copy to clipboard with ('phone')