當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript modal.Modal類代碼示例

本文整理匯總了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;未經允許,請勿轉載。