/* bender-tags: editor,unit */
/* bender-ckeditor-plugins: wysiwygarea,structuredheadings,toolbar,basicstyles,dialog,richcombo */

// Clean up all instances been created on the page.
(function () {

  var comboName = "NumStyles";

  bender.editor = {
    allowedForTests: "h1; h2; p"
  };

  bender.test({
    setUp: function () {
      //Anything to be run before each test if needed
    },
    "apply numbering style to a non-autonumbered heading": function () {
      var bot = this.editorBot;
      var ed = this.editor;
      bot.setHtmlWithSelection("<h1>^foo</h1>");
      var styleCombo = ed.ui.get(comboName);
      assert.areSame(CKEDITOR.TRISTATE_OFF, styleCombo._.state, "check state OFF");

      bot.combo(comboName, function (combo) {
        assert.areSame(CKEDITOR.TRISTATE_ON, combo._.state, "check state ON when opened");
        combo.onClick("1. a. i. a. i.");
        assert.areSame(
            "<h1 class=\"autonumber autonumber-0 autonumber-N\">^foo</h1>",
            bot.htmlWithSelection(),
            "applied 1aiai to h1"
        );
      });
    },
    "apply numbering style to multiple non-autonumbered h1": function () {
      var bot = this.editorBot;
      var ed = this.editor;
      bot.setHtmlWithSelection("[<h1>foo</h1><h1>bar</h1>]");
      var styleCombo = ed.ui.get(comboName);
      assert.areSame(CKEDITOR.TRISTATE_OFF, styleCombo._.state, "check state OFF");

      bot.combo(comboName, function (combo) {
        assert.areSame(CKEDITOR.TRISTATE_ON, combo._.state, "check state ON when opened");
        combo.onClick("1. a. i. a. i.");
        assert.areSame(
            "<h1 class=\"autonumber autonumber-0 autonumber-N\">foo</h1>" +
            "<h1 class=\"autonumber autonumber-0 autonumber-N\">bar</h1>",
            bot.getData(),
            "applied 1aiai to both h1"
        );
      });
    },
    "apply numbering style to multiple non-autonumbered h1 using a partial selection": function () {
      var bot = this.editorBot;
      var ed = this.editor;
      bot.setHtmlWithSelection("[<h1>foo</h1><h1>b]ar</h1>");
      var styleCombo = ed.ui.get(comboName);
      assert.areSame(CKEDITOR.TRISTATE_OFF, styleCombo._.state, "check state OFF");

      bot.combo(comboName, function (combo) {
        assert.areSame(CKEDITOR.TRISTATE_ON, combo._.state, "check state ON when opened");
        combo.onClick("1. a. i. a. i.");
        assert.areSame(
            "<h1 class=\"autonumber autonumber-0 autonumber-N\">foo</h1>" +
            "<h1 class=\"autonumber autonumber-0 autonumber-N\">bar</h1>",
            bot.getData(),
            "applied 1aiai to both h1"
        );
      });
    }
  });
})();

@@ -2637,24 +2637,865 @@
 ;%0A      %7D);%0A
+    %7D,%0A    %22attempt to apply numbering style to a range containing non-haedings%22: function () %7B%0A      var bot = this.editorBot;%0A      var ed = this.editor;%0A      bot.setHtmlWithSelection(%22%5B%3Ch1%3Efoo%3C/h1%3E%3Cp%3Ebar%3C/p%3E%3Ch1%3Ebaz%5D%3C/h1%3E%22);%0A      var styleCombo = ed.ui.get(comboName);%0A      assert.areSame(CKEDITOR.TRISTATE_OFF, styleCombo._.state, %22check state OFF%22);%0A%0A      bot.combo(comboName, function (combo) %7B%0A        assert.areSame(CKEDITOR.TRISTATE_ON, combo._.state, %22check state ON when opened%22);%0A        combo.onClick(%221. a. i. a. i.%22);%0A        assert.areSame(%0A            %22%3Ch1 class=%5C%22autonumber autonumber-0 autonumber-N%5C%22%3Efoo%3C/h1%3E%22 +%0A            %22%3Cp%3Ebar%3C/p%3E%22 +%0A            %22%3Ch1 class=%5C%22autonumber autonumber-0 autonumber-N%5C%22%3Ebaz%3C/h1%3E%22,%0A            bot.getData(),%0A            %22applied 1aiai to both h1 and p is intact%22%0A        );%0A      %7D);%0A
     %7D%0A  %7D);%0A

add a case where non-headings are contained within a range