aboutsummaryrefslogtreecommitdiff
path: root/exampleData/ruleSets/combinedRules.json
blob: 5aa573d0d15f93b5da27bd5d951037263bf36fab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
{ 'name': "Combined color, font, image, and text rules"
, 'description': "Site colors, fonts, images, and text should conform to these general guidelines"
, 'rules': [
//---------------------------------
          { "id":13
             , "name": "Reports three times"
             , "description": "Test guideline that reports three errors"
             , "rule":
               function() {
                 report('Problem 1 (g1)', null);
                 report('Problem 3 (g1)', null);
                 report('Problem 2 (g1)', null);
               }
             },
//---------------------------------
           { "id":14
             , "name": "Reports two times"
             , "description": "Test guideline that reports two errors."
             , "rule":
               function() {
                 report('Problem 1 (g2)', null);
                 report('Problem 2 (g2)', null);
               }
              },
  //----------------------------------------------------------------
  { 'name': "Foreground check"
  , 'description': "Foreground colors should be in the set:"+
                   "#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738"
  , 'rule':
  function () {
    var allow = "#00 #FF #3D #F7 #C2 #B4 #4E #FFCB05 #7B8738".split(" ");
    $5(":visible")
      .cssIsNot("color", allow, fiveui.color.colorToHex)
      .each(function (i, elt) {
        var color = fiveui.color.colorToHex($(elt).css("color"));
        report("foreground color: " + color, elt);
      });
  }
  },
  //----------------------------------------------------------------
  { 'name': "Background check"
  , 'description': "Backgrounds colors should be in the set:" +
                   "#00 #FF #3D #F7 #C2 #B4 #4E"
  , 'rule':
  function () {
    var allow = "#00 #FF #3D #F7 #C2 #B4 #4E".split(" ");
    $5(":visible")
      .cssIsNot("background-color", allow, fiveui.color.colorToHex)
      .each(function (i, elt) {
        var color = fiveui.color.colorToHex($(elt).css("background-color"));
        report("non-standard background color: " + color, elt);
      });
  }
  },
  //----------------------------------------------------------------
  { 'name': "Content area color"
  , 'description': "Background color should be: " +
                   "#F7"
  , 'rule':
  function () {
    var allow = "#F7";
    $5("#content")
      .cssIsNot("background-color", allow, fiveui.color.colorToHex)
      .each(function (i, elt) {
        var color = fiveui.color.colorToHex($(elt).css("background-color"));
        report("non-standard content background color: " + color, elt);
      });
  }
  },
  //----------------------------------------------------------------
  { 'name': "Left navigation color"
  , 'description': "Left navigation color should be: " +
                   "#C2"
  , 'rule':
  function () {
    var allow = "#C2";
    $5("#leftNav")
      .cssIsNot("color", allow, fiveui.color.colorToHex)
      .each(function (i, elt) {
        var color = fiveui.color.colorToHex($(elt).css("color"));
        report("non-standard left navigation color: " + color, elt);
      });
  }
  },
  //----------------------------------------------------------------
  { 'name': "Header color check"
  , 'description': "Header color should be: " +
                   "#3D"
  , 'rule':
  function () {
    var allow = "#3D";
    $5(":header")
      .cssIsNot("color", allow, fiveui.color.colorToHex)
      .each(function (i, elt) {
        var color = fiveui.color.colorToHex($(elt).css("color"));
        report("non-standard header color: " + color, elt);
      });
  }
  },
  //---
  { "id": 1, "name": "Disallow Empty Headers"
    , "description": "Heading elements should contain text."
    , "rule": function() {
        fiveui.query(':header').each(function(ix, elt) {
          if($(elt).text() == '') {
            report('Heading does not contain text', elt);
          }
        });
      }
    },
  //---------------------------------------------------------
  { 'name': "Font properties check"
  , 'description': "Verify that fonts (family, size, weight) are \"standard\""
  , 'rule':
  function() {
    var allow = {
      "Verdana": { "bold": [25, 22, 12, 10]
                 , "normal": [12, 11, 10] }};
    fiveui.query('body p,:header').each(
      function(i, elt) {
        var font = fiveui.font.getFont($(elt));
        if (!fiveui.font.validate(allow, font)) {
          report('non-standard font: ' +
                 font.family + ", " +
                 font.size + ", " +
                 font.weight, $(elt));
        }
      });
  }
  },
//------------
  { "id": 1
  , "name": "Headings are capitalized"
  , "description": "Check to see if all headings use leading capital letters"
  , "rule":
    function() {
      var badHeadings =
        fiveui.query(':header').filter(
          function(idx) {
            var ch = $(this).text()[0];
            if (ch) {
              return (ch == ch.toLowerCase() );
            } else {
              return false;
            }
          });
      $(badHeadings).map(function(idx, elt){
                           report('Heading does not start with a capital letter', elt);
                         });

    }
  },
//------------
  { "id": 2
    , "name": "Disallow Empty Headers"
    , "description": "Heading elements should contain text"
    , "rule": function() {
      fiveui.query(':header').each(
        function(ix, elt) {
          if($(elt).text() == '') {
            report('Heading does not contain text', elt);
          }
        });
    }
  },
  //----------------------------------------------------------------
  { 'name': "Banner check"
  , 'description': "Banner image banner.gif must appear and link to somewhere"
  , 'severity': 1
  , 'rule':
  function() {
      var elt = $5("div[id=header]");          // get the div with id=header
      var b = elt.css("background");           // get its background CSS property
      var l = $5("a[href]", elt).prop("href"); // get the <a href=...> string inside the div
      if (/banner\.gif/.test(b)) {
        report("banner.gif missing", elt);
      }
      if (l.length == 0) {                     // this list will be empty if there is no link
        report("banner.gif link is missing", elt);
      }
  }
  },
  //----------------------------------------------------------------
  { 'name': "Image Size check"
  , 'description': "All site images should have height and width in a given set of choices"
  , 'severity': 2
  , 'rule':
  function() {
    var allowedDimensions = { 446: { 300: {}}               // allow any image with these height:width pairs
                            , 342: { 228: {}}
                            , 150: { 100: {}} };
    var specialWidths     = { 640: {}                       // allow any image with these special widths
                            , 100: {} };
    $5("img").not("div.filmstrip *")                        // skip filmstrip images
             .each(function (i, elt) {
      var borderStr = /^[0-9]+/.exec($(elt).css("border")); // compensate for image border
      var border = borderStr ? parseInt(borderStr[0]) : 0;
      var w = $(elt).width() + 2*border;
      var h = $(elt).height() + 2*border;
      if (!((w in specialWidths) ||
            (h in allowedDimensions && w in allowedDimensions[h]))) {
        report("non-standard dimensions "+h+"x"+w, elt);
      }
    });
  }
  },
  //----------------------------------------------------------------
  { 'name': "Image Border check"
  , 'description': "All site images should have 1px solid #3D border"
  , 'severity': 1
  , 'rule':
  function() {
    var norm = function (s) { return /^\w+\s+\w+/.exec(s)[0]; } // select out first two words of the input
    var imgs = $5("img").not("div.filmstrip *");         // select images not in the filmstrip
    imgs.cssIsNot("border", "1px solid", norm)
        .each(function (i, elt) {
          report("non-standard border style", elt);
        });
    imgs.cssIsNot("border-color", "#3D3D3D", fiveui.color.colorToHex)
        .each(function (i, elt) {
          report("non-standard border color", elt);
        });
  }
  },
  //---------------------------------------------------------
  { 'name': "Footer check"
  , 'description': "Footer should appear on the page"
  , 'rule':
  function() {
    if ($5("div.footer").length === 0) {
      report('Footer does not appear', elt);
    }
  }
  },
  //---------------------------------------------------------
  { 'name': "Main content width check"
  , 'description': "Main content div should be between 520px and 1200px wide"
  , 'rule':
  function() {
    var width;
    var elt = $5("#content");
    if (elt) {
      width = elt.width();
      if (width > 1200) {
        report('Main content is too wide: ' + width, elt);
      } else if (width < 520) {
        report('Main content is too narrow: ' + width, elt);
      }
    }
  }
  },
//---
  { 'name': 'Test rule',
               'description': 'An empty test rule',
               'rule': function() {
                  fiveui.query('p').each(
                    function(idx, elt) {
                      if ($(elt).text().indexOf('Sample text') != -1) {
                        report('test error', elt);
                      }
                    });
               }
             },
  //---
  {"id":42,"name":"r1","description":"desc1","rule":"rule txt1"},
  //---
  {"id":43,"name":"r2","description":"desc2","rule":"rule txt2"},
//---
          { "id":42
             , "name": "Headings are capitalized"
             , "description": "Check to see if all h1 headings use leading capital letters."
             , "rule":
               function() {
                 var badHeadings = $('h1').filter(function(idx) {
                                                    var ch = $(this).text()[0];
                                                    if (ch) {
                                                      return (ch == ch.toLowerCase() );
                                                    } else {
                                                      return false;
                                                    }
                                                  });
                 $(badHeadings).map(function(idx, elt){
                                      report('Heading does not start with a capitol letter.', elt);
                 });

               },
//--------------------------------------------
             { 'name': "RULE NAME"
             , 'description': "RULE DESC"
             , 'rule':
             function() {} // Function that checks the rule
             },
  //---------------------------------------------------------------
  { "id": 13
   , "name": "Sentence case"
   , "description": "Titles should be written in sentence case"
   , "rule":
     function() {
       var posLength = function(ar) {
         return 1 <= ar.length;
       };

       /**
        * Test str to see if it is in sentence case.
        */
       var assertSentenceCase = function(inStr, elt) {
         var str = fiveui.string.trim(inStr);

         if ( !fiveui.word.capitalized(str[0]) ) {
           report('The heading: "'+str+'" is not in sentence case.', elt);
           return;
         }

         var tokens = str.split(' ').filter(posLength);

         for (var i=1; i < tokens.length; ++i) {
           if (fiveui.word.capitalized(tokens[i])) {
             report('The heading: "'+str+'" is not in sentence case.', elt);
             return;
           }
         }
       };

       fiveui.query(':header').each(function(idx, elt) {
                                      assertSentenceCase($(elt).text(), elt);
                                    });
     }
   },
   //---------------------------------------------------------------
   { "id":14
   , "name": "Capitalization check"
   , "description": "Capitalize \"Galois\" and \"Galwegian\" when referring to the company"
   , "rule":
     function() {
       fiveui.query('*').hasText('galois').each(function (i, elt) {
         report('"Galois" should be capitalized', elt);
       })

       fiveui.query('*').hasText('galwegian').each(function (i, elt) {
         report('"Galwegian" should be capitalized', elt);
       })
     }
    },
//-----------------------------------
  { 'id': 1, 'name': 'Test rule',
               'description': 'An empty test rule',
               'rule': function() { report('test error'); }
}
]}