本文整理汇总了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");
//.........这里部分代码省略.........
示例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");
});
示例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();
});
});