|
| 1 | +// Imports |
| 2 | +import buildRequestURL from './build-request-url'; |
| 3 | + |
| 4 | +// Tests |
| 5 | +describe('#buildRequestURL()', () => { |
| 6 | + it('Handles parameters with text value', () => { |
| 7 | + expect( |
| 8 | + buildRequestURL({ |
| 9 | + text: '.foo { text-align: center; }', |
| 10 | + medium: undefined, |
| 11 | + warningLevel: undefined, |
| 12 | + }) |
| 13 | + ).toBe( |
| 14 | + 'https://jigsaw.w3.org/css-validator/validator?text=.foo%20%7B%20text-align%3A%20center%3B%20%7D&usermedium=all&warning=no&output=application/json&profile=css3' |
| 15 | + ); |
| 16 | + }); |
| 17 | + |
| 18 | + it('Handles parameters with URL value', () => { |
| 19 | + expect( |
| 20 | + buildRequestURL({ |
| 21 | + url: 'https://raw.githubusercontent.com/sparksuite/w3c-css-validator/master/public/css/valid.css', |
| 22 | + medium: undefined, |
| 23 | + warningLevel: undefined, |
| 24 | + }) |
| 25 | + ).toBe( |
| 26 | + 'https://jigsaw.w3.org/css-validator/validator?uri=https%3A%2F%2Fraw.githubusercontent.com%2Fsparksuite%2Fw3c-css-validator%2Fmaster%2Fpublic%2Fcss%2Fvalid.css&usermedium=all&warning=no&output=application/json&profile=css3' |
| 27 | + ); |
| 28 | + }); |
| 29 | + |
| 30 | + it('Uses provided parameters over default values', () => { |
| 31 | + expect( |
| 32 | + buildRequestURL({ |
| 33 | + text: '.foo { text-align: center; }', |
| 34 | + medium: 'braille', |
| 35 | + warningLevel: 3, |
| 36 | + }) |
| 37 | + ).toBe( |
| 38 | + 'https://jigsaw.w3.org/css-validator/validator?text=.foo%20%7B%20text-align%3A%20center%3B%20%7D&usermedium=braille&warning=2&output=application/json&profile=css3' |
| 39 | + ); |
| 40 | + }); |
| 41 | + |
| 42 | + it('Complains if text and URL values are provided simultaneously', () => { |
| 43 | + expect(() => |
| 44 | + buildRequestURL({ |
| 45 | + text: '.foo { text-align: center; }', |
| 46 | + // @ts-expect-error: We're trying to force an error here |
| 47 | + url: 'https://raw.githubusercontent.com/sparksuite/w3c-css-validator/master/public/css/valid.css', |
| 48 | + medium: undefined, |
| 49 | + warningLevel: undefined, |
| 50 | + }) |
| 51 | + ).toThrow('Only a text or a URL value can be provided'); |
| 52 | + }); |
| 53 | +}); |
0 commit comments