本文整理汇总了TypeScript中wed/gui/modal.Modal类的典型用法代码示例。如果您正苦于以下问题:TypeScript Modal类的具体用法?TypeScript Modal怎么用?TypeScript Modal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Modal类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe("Modal", () => {
let wedroot: HTMLElement;
let modal: Modal;
function clearWedRoot(): void {
// tslint:disable-next-line:no-inner-html
wedroot.innerHTML = "";
}
before(() => {
wedroot = makeWedRoot(document);
document.body.appendChild(wedroot);
});
after(() => {
document.body.removeChild(wedroot);
});
beforeEach(() => {
modal = new Modal();
});
describe("setTitle", () => {
it("sets the title", () => {
let $title = modal.getTopLevel().find(".modal-header>h3");
assert.equal($title.text(), "Untitled", "initial title");
modal.setTitle($("<b>foo</b>"));
$title = modal.getTopLevel().find(".modal-header>h3");
assert.equal($title[0].innerHTML, "<b>foo</b>", "new title");
});
});
describe("setBody", () => {
it("sets the body", () => {
const body = modal.getTopLevel().find(".modal-body")[0];
assert.equal(body.innerHTML.trim(), "<p>No body.</p>", "initial body");
modal.setBody($("<p>A body.</p>"));
assert.equal(body.innerHTML, "<p>A body.</p>", "new body");
});
});
describe("setFooter", () => {
it("sets the footer", () => {
const footer = modal.getTopLevel().find(".modal-footer")[0];
assert.equal(footer.innerHTML.trim(), "", "initial footer");
modal.setFooter($("<p>A footer.</p>"));
assert.equal(footer.innerHTML, "<p>A footer.</p>", "new footer");
});
});
describe("addButton", () => {
it("adds a button", () => {
const footer = modal.getTopLevel().find(".modal-footer")[0];
assert.equal(footer.innerHTML.trim(), "", "initial footer");
const $button = modal.addButton("test");
assert.isTrue($button.closest(footer).length > 0,
"button is present in footer");
assert.equal($button.text(), "test");
assert.isFalse($button.hasClass("btn-primary"));
});
it("adds a primary button", () => {
const footer = modal.getTopLevel().find(".modal-footer")[0];
assert.equal(footer.innerHTML.trim(), "", "initial footer");
const $button = modal.addButton("test", true);
assert.isTrue($button.closest(footer).length > 0,
"button is present in footer");
assert.equal($button.text(), "test");
assert.isTrue($button.hasClass("btn-primary"));
});
});
describe("getPrimary", () => {
it("returns an empty set if there is no primary", () => {
assert.equal(modal.getPrimary()[0], undefined);
});
it("returns the primary", () => {
const $button = modal.addButton("test", true);
assert.equal(modal.getPrimary()[0], $button[0]);
});
});
function makeAddXYTest(first: string, second: string): void {
describe(`add${first}${second}`, () => {
it(`adds ${first} and ${second} button, ${first} is primary`, () => {
const footer = modal.getTopLevel().find(".modal-footer")[0];
assert.equal(footer.innerHTML.trim(), "", "initial footer");
// tslint:disable-next-line:no-any
const buttons = (modal as any)[`add${first}${second}`].call(modal);
assert.isTrue(buttons[0].closest(footer).length > 0,
"button 0 is present in footer");
assert.isTrue(buttons[1].closest(footer).length > 0,
"button 1 is present in footer");
assert.equal(buttons[0].text(), first, "button 0 name");
assert.equal(buttons[1].text(), second, "button 1 name");
assert.isTrue(buttons[0].hasClass("btn-primary"),
"button 0 is primary");
//.........这里部分代码省略.........
开发者ID:lddubeau,项目名称:wed,代码行数:101,代码来源:modal-test.ts
示例2: it
it("sets the title", () => {
let $title = modal.getTopLevel().find(".modal-header>h3");
assert.equal($title.text(), "Untitled", "initial title");
modal.setTitle($("<b>foo</b>"));
$title = modal.getTopLevel().find(".modal-header>h3");
assert.equal($title[0].innerHTML, "<b>foo</b>", "new title");
});
开发者ID:lddubeau,项目名称:wed,代码行数:7,代码来源:modal-test.ts
示例3: click
it("cleans event handlers properly", (done) => {
function click(): void {
modal.getPrimary().click();
}
window.setTimeout(click, 1);
let first = 0;
modal.modal(() => {
first++;
});
window.setTimeout(click, 1);
let second = 0;
modal.modal(() => {
second++;
assert.equal(first, 1, "first handler count");
assert.equal(second, 1, "second handler count");
done();
});
});
开发者ID:lddubeau,项目名称:wed,代码行数:20,代码来源:modal-test.ts
注:本文中的wed/gui/modal.Modal类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论