|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const { ariaTest } = require('..'); |
| 4 | +const { By } = require('selenium-webdriver'); |
| 5 | +const assertAriaLabelledby = require('../util/assertAriaLabelledby'); |
| 6 | +const assertAriaRoles = require('../util/assertAriaRoles'); |
| 7 | + |
| 8 | +const exampleFile = 'meter/meter.html'; |
| 9 | + |
| 10 | +const ex = { |
| 11 | + meterSelector: '#example [role="meter"]', |
| 12 | + fillSelector: '#example [role="meter"] > svg' |
| 13 | +}; |
| 14 | + |
| 15 | +// Attributes |
| 16 | +ariaTest('role="meter" element exists', exampleFile, 'meter-role', async (t) => { |
| 17 | + await assertAriaRoles(t, 'example', 'meter', '1', 'div'); |
| 18 | +}); |
| 19 | + |
| 20 | +ariaTest('"aria-labelledby" attribute', exampleFile, 'meter-aria-labelledby', async (t) => { |
| 21 | + await assertAriaLabelledby(t, ex.meterSelector); |
| 22 | +}); |
| 23 | + |
| 24 | +ariaTest('"aria-valuemin" attribute', exampleFile, 'meter-aria-valuemin', async (t) => { |
| 25 | + const meter = await t.context.session.findElement(By.css(ex.meterSelector)); |
| 26 | + const valuemin = await meter.getAttribute('aria-valuemin'); |
| 27 | + |
| 28 | + t.is(typeof valuemin, 'string', 'aria-valuemin is present on the meter'); |
| 29 | + t.false(isNaN(parseFloat(valuemin)), 'aria-valuemin is a number'); |
| 30 | +}); |
| 31 | + |
| 32 | +ariaTest('"aria-valuemax" attribute', exampleFile, 'meter-aria-valuemax', async (t) => { |
| 33 | + const meter = await t.context.session.findElement(By.css(ex.meterSelector)); |
| 34 | + const [valuemax, valuemin] = await Promise.all([ |
| 35 | + meter.getAttribute('aria-valuemax'), |
| 36 | + meter.getAttribute('aria-valuemin') |
| 37 | + ]); |
| 38 | + |
| 39 | + t.is(typeof valuemax, 'string', 'aria-valuemax is present on the meter'); |
| 40 | + t.false(isNaN(parseFloat(valuemax)), 'aria-valuemax is a number'); |
| 41 | + t.true(parseFloat(valuemax) >= parseFloat(valuemin), 'max value is greater than min value'); |
| 42 | +}); |
| 43 | + |
| 44 | +ariaTest('"aria-valuenow" attribute', exampleFile, 'meter-aria-valuenow', async (t) => { |
| 45 | + const meter = await t.context.session.findElement(By.css(ex.meterSelector)); |
| 46 | + const [valuenow, valuemax, valuemin] = await Promise.all([ |
| 47 | + meter.getAttribute('aria-valuenow'), |
| 48 | + meter.getAttribute('aria-valuemax'), |
| 49 | + meter.getAttribute('aria-valuemin') |
| 50 | + ]); |
| 51 | + |
| 52 | + t.is(typeof valuenow, 'string', 'aria-valuenow is present on the meter'); |
| 53 | + t.false(isNaN(parseFloat(valuenow)), 'aria-valuenow is a number'); |
| 54 | + t.true(parseFloat(valuenow) >= parseFloat(valuemin), 'current value is greater than min value'); |
| 55 | + t.true(parseFloat(valuenow) <= parseFloat(valuemax), 'current value is less than max value'); |
| 56 | +}); |
| 57 | + |
| 58 | +ariaTest('fill matches current value', exampleFile, 'meter-aria-valuenow', async (t) => { |
| 59 | + const meter = await t.context.session.findElement(By.css(ex.meterSelector)); |
| 60 | + const fill = await t.context.session.findElement(By.css(ex.fillSelector)); |
| 61 | + const [valuenow, valuemax, valuemin] = await Promise.all([ |
| 62 | + meter.getAttribute('aria-valuenow'), |
| 63 | + meter.getAttribute('aria-valuemax'), |
| 64 | + meter.getAttribute('aria-valuemin') |
| 65 | + ]); |
| 66 | + |
| 67 | + const currentPercent = (valuenow - valuemin) / (valuemax - valuemin); |
| 68 | + const [fillSize, meterSize] = await Promise.all([fill.getRect(), meter.getRect()]); |
| 69 | + |
| 70 | + // fudging a little here, since meter has 8px total border + padding |
| 71 | + // would be better in a unit test eventually |
| 72 | + const expectedFillWidth = (meterSize.width - 8) * currentPercent; |
| 73 | + t.true(Math.abs(expectedFillWidth - fillSize.width) < 10, 'Fill width is the correct percent of meter, +/- 10px'); |
| 74 | +}); |
0 commit comments