mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-13 09:28:29 +01:00
Add some button tests
This commit is contained in:
parent
ef3848fd3c
commit
584d6bf51d
@ -19,7 +19,7 @@ export class Et2Button extends Et2InputWidget(Et2Widget(SlotMixin(LionButton)))
|
||||
{
|
||||
protected _created_icon_node : HTMLImageElement;
|
||||
protected clicked : boolean = false;
|
||||
private image : string;
|
||||
private _image : string;
|
||||
|
||||
static get styles()
|
||||
{
|
||||
@ -67,7 +67,7 @@ export class Et2Button extends Et2InputWidget(Et2Widget(SlotMixin(LionButton)))
|
||||
super();
|
||||
|
||||
// Property default values
|
||||
this.image = '';
|
||||
this._image = '';
|
||||
|
||||
// Do not add icon here, no children can be added in constructor
|
||||
|
||||
@ -84,13 +84,21 @@ export class Et2Button extends Et2InputWidget(Et2Widget(SlotMixin(LionButton)))
|
||||
super.connectedCallback();
|
||||
|
||||
//this.classList.add("et2_button")
|
||||
|
||||
if(this.image)
|
||||
{
|
||||
this._iconNode.src = egw.image(this.image);
|
||||
}
|
||||
}
|
||||
|
||||
set image(new_image : string)
|
||||
{
|
||||
let oldValue = this._image;
|
||||
if(new_image.indexOf("http") >= 0)
|
||||
{
|
||||
this._image = new_image
|
||||
}
|
||||
else
|
||||
{
|
||||
this._image = this.egw().image(new_image, 'etemplate');
|
||||
}
|
||||
this.requestUpdate("image", oldValue);
|
||||
}
|
||||
|
||||
_handleClick(event : MouseEvent) : boolean
|
||||
{
|
||||
@ -126,6 +134,8 @@ export class Et2Button extends Et2InputWidget(Et2Widget(SlotMixin(LionButton)))
|
||||
return '';
|
||||
}
|
||||
|
||||
this._iconNode.src = this._image;
|
||||
|
||||
return html`
|
||||
<div class="button-content et2_button" id="${this._buttonId}">
|
||||
<slot name="icon"></slot>
|
||||
|
@ -23,7 +23,9 @@ describe("Button widget", () =>
|
||||
|
||||
// Stub egw()
|
||||
sinon.stub(element, "egw").returns({
|
||||
tooltipUnbind: () => {}
|
||||
tooltipUnbind: () => {},
|
||||
// Image always give check mark. Use data URL to avoid having to serve an actual image
|
||||
image: i => "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNS4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkViZW5lXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB3aWR0aD0iMzJweCIgaGVpZ2h0PSIzMnB4IiB2aWV3Qm94PSIwIDAgMzIgMzIiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDMyIDMyIiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBmaWxsPSIjNjk2OTY5IiBkPSJNNi45NDMsMjguNDUzDQoJYzAuOTA2LDAuNzY1LDIuMDk3LDEuMTI3LDMuMjg2LDEuMTA5YzAuNDMsMC4wMTQsMC44NTItMC4wNjgsMS4yNjUtMC4yMDdjMC42NzktMC4xOCwxLjMyOC0wLjQ1LDEuODY2LTAuOTAyTDI5LjQwMywxNC45DQoJYzEuNzcyLTEuNDk4LDEuNzcyLTMuOTI1LDAtNS40MjJjLTEuNzcyLTEuNDk3LTQuNjQ2LTEuNDk3LTYuNDE4LDBMMTAuMTE5LDIwLjM0OWwtMi4zODktMi40MjRjLTEuNDQtMS40NTctMy43NzItMS40NTctNS4yMTIsMA0KCWMtMS40MzgsMS40Ni0xLjQzOCwzLjgyNSwwLDUuMjgxQzIuNTE4LDIzLjIwNiw1LjQ3NCwyNi45NDcsNi45NDMsMjguNDUzeiIvPg0KPC9zdmc+DQo="
|
||||
});
|
||||
});
|
||||
|
||||
@ -39,4 +41,29 @@ describe("Button widget", () =>
|
||||
|
||||
assert.equal(element.textContent, "Label set");
|
||||
})
|
||||
|
||||
it("click happens", () =>
|
||||
{
|
||||
// Setup
|
||||
let clickSpy = sinon.spy();
|
||||
element.onclick = clickSpy;
|
||||
|
||||
// Click
|
||||
element.dispatchEvent(new MouseEvent("click"));
|
||||
|
||||
// Check for once & only once
|
||||
assert(clickSpy.calledOnce, "Click only once");
|
||||
})
|
||||
|
||||
it("gets an icon", async() =>
|
||||
{
|
||||
element.image = "check";
|
||||
|
||||
// Wait for the render to finish
|
||||
await element.updateComplete;
|
||||
|
||||
let image = element.querySelectorAll("img");
|
||||
assert.equal(image.length, 1);
|
||||
assert.equal(image[0].src, element.egw().image("check"));
|
||||
})
|
||||
});
|
Loading…
Reference in New Issue
Block a user