/*
* Copyright 2024 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import {ColorSlider, ColorSliderContext} from '../src/ColorSlider';
import {ColorThumb} from '../src/ColorThumb';
import {fireEvent, pointerMap, render} from '@react-spectrum/test-utils-internal';
import {Label} from '../src/Label';
import React from 'react';
import {SliderOutput, SliderTrack} from '../src/Slider';
import userEvent from '@testing-library/user-event';
let TestColorSlider = ({sliderProps, thumbProps, trackProps, outputProps}) => (
);
let renderSlider = (sliderProps, thumbProps, trackProps, outputProps) =>
render();
describe('ColorSlider', () => {
let user;
beforeAll(() => {
user = userEvent.setup({delay: null, pointerMap});
});
it('should render a slider with default class', () => {
let {getByRole} = renderSlider();
let group = getByRole('group');
expect(group).toHaveAttribute('class', 'react-aria-SliderTrack');
expect(group.parentElement).toHaveAttribute('class', 'react-aria-ColorSlider');
expect(group).toHaveAttribute('aria-labelledby');
expect(document.getElementById(group.getAttribute('aria-labelledby'))).toHaveTextContent('Red');
expect(getByRole('status')).toHaveTextContent('255');
expect(group.querySelector('.react-aria-ColorThumb')).toBeInTheDocument();
});
it('should render a slider with custom class', () => {
let {getByRole} = renderSlider({className: 'test'});
let group = getByRole('group');
expect(group.parentElement).toHaveAttribute('class', 'test');
});
it('should support DOM props', () => {
let {getByRole} = renderSlider(
{'data-foo': 'bar'},
{'data-bar': 'foo'},
{'data-test': 'test'},
{'data-output': 'output'}
);
let slider = getByRole('group').parentElement;
expect(slider).toHaveAttribute('data-foo', 'bar');
expect(slider.querySelector('.react-aria-ColorThumb')).toHaveAttribute('data-bar', 'foo');
expect(slider.querySelector('.react-aria-SliderTrack')).toHaveAttribute('data-test', 'test');
expect(slider.querySelector('.react-aria-SliderOutput')).toHaveAttribute(
'data-output',
'output'
);
});
it('should support custom render function', () => {
let {getByRole} = renderSlider(
{render: props =>