path = sys_get_temp_dir().'/scheme-picker-'.uniqid().'.json'; File::put($this->path, json_encode([ 'default' => 'indigo', 'profiles' => [ 'indigo' => ['label' => 'Indigo', 'light' => ['primary' => '#4f46e5', 'secondary' => '#5b5d72', 'tertiary' => '#77536d'], 'dark' => ['primary' => '#c0c1ff', 'secondary' => '#c4c5dd', 'tertiary' => '#e6bad7']], 'teal' => ['label' => 'Teal', 'light' => ['primary' => '#00897b', 'secondary' => '#4a635f', 'tertiary' => '#456179'], 'dark' => ['primary' => '#80cbc4', 'secondary' => '#b1ccc6', 'tertiary' => '#adcae5']], ], ])); config(['livewire-material.scheme' => $this->path]); }); afterEach(function () { File::delete($this->path); }); it('draws a radio per generated profile, bound, named and previewing on change', function () { $html = (string) $this->blade(''); expect($html) ->toContain('Colour profile') ->toContain('Applies after saving') ->toContain('data-scheme-option="indigo"') ->toContain('data-scheme-option="teal"') ->toMatch('/toContain('x-on:change="$store.theme.previewScheme($event.target.value)"') ->toContain('>Teal') ->toContain('style="--swatch-light: #00897b; --swatch-dark: #80cbc4"'); }); it('keeps its inline styles to the scheme file\'s checked colours', function () { File::put($this->path, json_encode([ 'default' => 'indigo', 'profiles' => ['indigo' => ['label' => 'Indigo', 'light' => ['primary' => 'red; background: url(x)'], 'dark' => []]], ])); $html = (string) $this->blade(''); preg_match_all('/style="([^"]*)"/', $html, $styles); expect($styles[1])->not->toBeEmpty() ->each->toMatch('/^--swatch-light: #[0-9a-fA-F]{6}; --swatch-dark: #[0-9a-fA-F]{6}$/'); }); it('shows a validation message for the bound property instead of the hint', function () { $this->withViewErrors(['colorProfile' => ['Choose one of the colour profiles.']]) ->blade('') ->assertSee('Choose one of the colour profiles.') ->assertDontSee('Applies after saving'); }); it('renders nothing for a single scheme', function () { File::put($this->path, json_encode(['light' => ['primary' => '#123456'], 'dark' => []])); expect(trim((string) $this->blade('')))->toBe(''); });