|
| 1 | +/** |
| 2 | + * Copyright (C) 2023 Green Code Initiative |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | +"use strict"; |
| 18 | + |
| 19 | +//------------------------------------------------------------------------------ |
| 20 | +// Requirements |
| 21 | +//------------------------------------------------------------------------------ |
| 22 | + |
| 23 | +const rule = require("../../../lib/rules/provide-print-css"); |
| 24 | +const RuleTester = require("eslint").RuleTester; |
| 25 | + |
| 26 | +//------------------------------------------------------------------------------ |
| 27 | +// Tests |
| 28 | +//------------------------------------------------------------------------------ |
| 29 | + |
| 30 | +const ruleTester = new RuleTester({ |
| 31 | + parserOptions: { |
| 32 | + ecmaVersion: 6, |
| 33 | + sourceType: "module", |
| 34 | + ecmaFeatures: { |
| 35 | + jsx: true, |
| 36 | + }, |
| 37 | + }, |
| 38 | +}); |
| 39 | + |
| 40 | +const expectedError = { |
| 41 | + messageId: "noPrintCSSProvided", |
| 42 | + type: "JSXElement", |
| 43 | +}; |
| 44 | + |
| 45 | +ruleTester.run("provide-print-css", rule, { |
| 46 | + valid: [ |
| 47 | + ` |
| 48 | + <head> |
| 49 | + <title>Web Page</title> |
| 50 | + <link rel="stylesheet" href="styles.css" media="print" /> |
| 51 | + </head> |
| 52 | + `, |
| 53 | + ` |
| 54 | + <head> |
| 55 | + <title>Web Page</title> |
| 56 | + <style>@media print {}</style> |
| 57 | + </head> |
| 58 | + `, |
| 59 | + ` |
| 60 | + <head> |
| 61 | + <title>Web Page</title> |
| 62 | + <style>{'@media print {}'}</style> |
| 63 | + </head> |
| 64 | + `, |
| 65 | + ` |
| 66 | + <head> |
| 67 | + <title>Web Page</title> |
| 68 | + <link rel="stylesheet" href="styles.css" media="print" />, |
| 69 | + <style>{'@media print {}'}</style> |
| 70 | + </head> |
| 71 | + `, |
| 72 | + "<head><style>{`@media print {}`}</style></head>", |
| 73 | + `<link rel="stylesheet" href="styles.css" />`, |
| 74 | + ], |
| 75 | + invalid: [ |
| 76 | + { |
| 77 | + code: ` |
| 78 | + <head> |
| 79 | + <title>Web Page</title> |
| 80 | + <link rel="stylesheet" href="styles.css" /> |
| 81 | + </head> |
| 82 | + `, |
| 83 | + errors: [expectedError], |
| 84 | + }, |
| 85 | + { |
| 86 | + code: ` |
| 87 | + <head> |
| 88 | + <title>Web Page</title> |
| 89 | + <style>{'@media desktop {}'}</style> |
| 90 | + </head> |
| 91 | + `, |
| 92 | + errors: [expectedError], |
| 93 | + }, |
| 94 | + ], |
| 95 | +}); |
0 commit comments