Skip to content

Commit

Permalink
ColorBox: value should be formatted to rgba after apply on tab (T1193…
Browse files Browse the repository at this point in the history
…656) (#25755)
  • Loading branch information
Zedwag authored Oct 9, 2023
1 parent 6182bb6 commit f9ce308
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/devextreme/js/ui/color_box/color_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,16 @@ const ColorBox = DropDownEditor.inherit({
},

_applyColorFromInput: function(value) {
const { editAlphaChannel } = this.option();
const newColor = new Color(value);

if(newColor.colorIsInvalid) {
this._resetInputValue();
value = this.option('value');
return this.option('value');
}

if(editAlphaChannel) {
return colorUtils.makeRgba(value);
}

return value;
Expand Down
18 changes: 18 additions & 0 deletions packages/devextreme/testing/testcafe/model/colorbox.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import { WidgetName } from '../helpers/createWidget';
import Widget from './internal/widget';
import Popup from './popup';

const CLASS = {
input: 'dx-texteditor-input',
popup: 'dx-popup',
};

export default class ColorBox extends Widget {
input: Selector;

constructor(id: string | Selector) {
super(id);

this.input = this.element.find(`.${CLASS.input}`);
}

getPopup(): Popup {
return new Popup(this.element.find(`.${CLASS.popup}`));
}

// eslint-disable-next-line class-methods-use-this
getName(): WidgetName { return 'dxColorBox'; }
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Selector } from 'testcafe';
import { createScreenshotsComparer } from 'devextreme-screenshot-comparer';
import ColorBox from '../../../model/colorbox';
import url from '../../../helpers/getPageUrl';
import createWidget from '../../../helpers/createWidget';
import { testScreenshot } from '../../../helpers/themeUtils';
import { appendElementTo, setStyleAttribute } from '../../../helpers/domUtils';
import { clearTestPage } from '../../../helpers/clearPage';

fixture.disablePageReloads`Colorbox`
.page(url(__dirname, '../../container.html'));
.page(url(__dirname, '../../container.html'))
.afterEach(async () => clearTestPage());

test('Colorbox should display full placeholder', async (t) => {
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
Expand All @@ -25,3 +28,25 @@ test('Colorbox should display full placeholder', async (t) => {
placeholder: 'I am a very long placeholder',
}, '#colorBox');
});

['#00ffff', 'rgb(0,255,255)', 'rgba(0,255,255,1)', 'aqua'].forEach((inputText) => {
['enter', 'tab'].forEach((key) => {
test(`input value=${inputText} should be formatted to rgba after apply on ${key} key press`, async (t) => {
const colorBox = new ColorBox('#container');
const expectedValue = 'rgba(0, 255, 255, 1)';

await t
.click(colorBox.input);

await t
.typeText(colorBox.input, inputText)
.pressKey(key)
.expect(colorBox.option('text'))
.eql(expectedValue)
.expect(colorBox.option('value'))
.eql(expectedValue);
}).before(async () => createWidget('dxColorBox', {
editAlphaChannel: true,
}, '#container'));
});
});

0 comments on commit f9ce308

Please sign in to comment.