all files / modules/headers/__tests__/ AcceptCharset-test.js

100% Statements 32/32
100% Branches 0/0
100% Functions 13/13
100% Lines 32/32
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                                                   
/* jshint -W058 */
const assert = require("assert");
const expect = require("expect");
const AcceptCharset = require("../AcceptCharset");
 
describe("AcceptCharset", function () {
    let header;
 
    describe("with no value", function () {
        beforeEach(function () {
            header = new AcceptCharset();
        });
 
        it("has the correct toString representation", function () {
            expect(header.toString()).toEqual("Accept-Charset: ");
        });
 
        it("has the correct quality factors", function () {
            expect(header.qualityFactorForCharset("iso-8859-1")).toEqual(1);
            expect(header.qualityFactorForCharset("iso-8859-5")).toEqual(0);
            expect(header.qualityFactorForCharset("unicode-1-1")).toEqual(0);
        });
 
        it("accepts iso-8859-1", function () {
            assert(header.accepts("iso-8859-1"));
        });
 
        it("does not accept other charsets", function () {
            assert(!header.accepts("iso-8859-5"));
            assert(!header.accepts("unicode-1-1"));
        });
    });
 
    describe("with a value of \"unicode-1-1;q=0.8, *;q=0.5\"", function () {
        beforeEach(function () {
            header = new AcceptCharset("unicode-1-1, *;q=0.5");
        });
 
        it("has the correct quality factors", function () {
            expect(header.qualityFactorForCharset("iso-8859-1")).toEqual(1);
            expect(header.qualityFactorForCharset("iso-8859-5")).toEqual(0.5);
            expect(header.qualityFactorForCharset("unicode-1-1")).toEqual(1);
        });
 
        it("accepts iso-8859-1", function () {
            assert(header.accepts("iso-8859-1"));
        });
 
        it("accepts iso-8859-5", function () {
            assert(header.accepts("iso-8859-5"));
        });
 
        it("accepts unicode-1-1", function () {
            assert(header.accepts("unicode-1-1"));
        });
    });
});