Skip to content
Snippets Groups Projects
Select Git revision
  • 295f0577b3ec6c229f63957cb020a561d72047a3
  • master default protected
  • 1.31
  • 4.38.8
  • 4.38.7
  • 4.38.6
  • 4.38.5
  • 4.38.4
  • 4.38.3
  • 4.38.2
  • 4.38.1
  • 4.38.0
  • 4.37.2
  • 4.37.1
  • 4.37.0
  • 4.36.0
  • 4.35.0
  • 4.34.1
  • 4.34.0
  • 4.33.1
  • 4.33.0
  • 4.32.2
  • 4.32.1
23 results

stylesheet.mjs

Blame
  • stylesheet.mjs 2.65 KiB
    'use strict';
    
    import * as chai from 'chai';
    import {Stylesheet} from "../../../../../source/dom/resource/link/stylesheet.mjs";
    import {DataUrl} from "../../../../../source/types/dataurl.mjs";
    import {ID} from "../../../../../source/types/id.mjs";
    import {chaiDom} from "../../../../util/chai-dom.mjs";
    import {cleanupDOMFromTesting, initMutationObserverForTesting} from "../../../../util/cleanupdom.mjs";
    import {initJSDOM} from "../../../../util/jsdom.mjs";
    
    let expect = chai.expect;
    
    chai.use(chaiDom);
    
    let html1 = `
    
    `;
    
    
    describe('Stylesheet', function () {
    
        before(function (done) {
            initJSDOM({
                runScripts: "dangerously",
                resources: "usable"
            }).then(() => {
                done()
            }).catch(e => done(e));
        });
    
        beforeEach(() => {
            initMutationObserverForTesting()
        })
    
        afterEach(() => {
            cleanupDOMFromTesting();
        })
    
        describe('Stylesheet()', function () {
            it('connect().available()', function (done) {
    
                const stylesheet = new Stylesheet({
                    href: new DataUrl('', 'text/css').toString(),
                });
    
                stylesheet.connect().available().then(() => {
                    const id = stylesheet.getOption('id')
                    done()
                }).catch(e => done(e));
    
            })
        });
    
        describe('External Stylesheet', () => {
    
            let id = new ID('Stylesheet').toString();
            let stylesheet, url = 'https://alvine.io/main.min.css';
    
            beforeEach(() => {
    
                stylesheet = new Stylesheet({
                    href: url,
                    id: id,
                });
    
            });
    
            it('append and remove Stylesheet ', (done) => {
    
                expect(stylesheet.isConnected()).to.be.false;
    
                stylesheet.connect().available().then(() => {
                    expect(stylesheet.isConnected()).to.be.true;
                    expect(document.querySelector('[href="' + url + '"]')).to.exist;
    
                    document.getElementById(id).remove();
                    expect(stylesheet.isConnected()).to.be.false;
                    expect(document.querySelector('[href="' + url + '"]')).not.to.exist;
    
                    stylesheet.connect().available().then(() => {
                        expect(stylesheet.isConnected()).to.be.true;
                        expect(document.querySelector('[href="' + url + '"]')).to.exist;
    
                        document.getElementById(id).remove();
                        expect(document.querySelector('[href="' + url + '"]')).not.to.exist;
                        expect(stylesheet.isConnected()).to.be.false;
    
                        done()
                    }).catch(e => done(e));
    
    
                }).catch(e => done(e));
    
    
            });
    
    
        });
    
    
    });