/** * @license * Copyright 2020 Google Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ import {MDCCircularProgress, MDCCircularProgressFoundation} from '../../mdc-circular-progress/index'; import {createFixture, html} from '../../../testing/dom'; const RADIUS = 18; function getFixture() { return createFixture(html`
`); } function setupTest() { const root = getFixture(); const component = new MDCCircularProgress(root); return {root, component}; } describe('MDCCircularProgress', () => { it('attachTo initializes and returns a MDCCircularProgress instance', () => { expect( MDCCircularProgress.attachTo(getFixture()) instanceof MDCCircularProgress) .toBeTruthy(); }); it('set indeterminate', () => { const {root, component} = setupTest(); component.determinate = false; expect(root).toHaveClass('mdc-circular-progress--indeterminate'); expect( root.getAttribute(MDCCircularProgressFoundation.strings.ARIA_VALUENOW)) .toEqual(null); }); it('set progress', () => { const {root, component} = setupTest(); const progressTestValue = 0.5; component.progress = progressTestValue; const determinateCircle = root.querySelector( MDCCircularProgressFoundation.strings.DETERMINATE_CIRCLE_SELECTOR)!; expect( root.getAttribute(MDCCircularProgressFoundation.strings.ARIA_VALUENOW)) .toEqual(progressTestValue.toString()); const strokeDashoffset = Number(determinateCircle.getAttribute( MDCCircularProgressFoundation.strings.STROKE_DASHOFFSET)); const expectedVal = progressTestValue * 2 * Math.PI * RADIUS; expect(strokeDashoffset).toBeLessThan(expectedVal + .001); expect(strokeDashoffset).toBeGreaterThan(expectedVal - .001); }); it('open and close', () => { const {root, component} = setupTest(); component.close(); expect(root).toHaveClass('mdc-circular-progress--closed'); expect(component.isClosed).toBe(true); component.open(); expect(root).not.toHaveClass('mdc-circular-progress--closed'); expect(component.isClosed).toBe(false); }); });