cssClass.mjs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { describe, it, before, after, afterEach } from 'mocha'
  2. import { expect } from 'chai'
  3. import { By } from 'selenium-webdriver'
  4. import {
  5. getRootAndWait,
  6. takeScreenshotOnFailure,
  7. } from '../../lib/elements.js'
  8. describe('config: cssClass', function () {
  9. before(async function () {
  10. await runner.start('cssClass')
  11. })
  12. after(async () => {
  13. await runner.stop()
  14. })
  15. afterEach(function () {
  16. takeScreenshotOnFailure(this.currentTest, webdriver)
  17. })
  18. it('cssClass is applied to action button (link component)', async function () {
  19. await getRootAndWait()
  20. const buttonWithClass = await webdriver.findElements(By.css('.action-button button.test-custom-class'))
  21. expect(buttonWithClass).to.have.length.at.least(1, 'Action button should have cssClass test-custom-class on the button')
  22. const classAttr = await buttonWithClass[0].getAttribute('class')
  23. expect(classAttr).to.include('test-custom-class')
  24. })
  25. it('custom theme applies background color to action button via cssClass', async function () {
  26. await getRootAndWait()
  27. const buttonWithClass = await webdriver.findElements(By.css('.action-button button.test-custom-class'))
  28. expect(buttonWithClass).to.have.length.at.least(1, 'Action button with test-custom-class should exist')
  29. const bgColor = await buttonWithClass[0].getCssValue('background-color')
  30. expect(bgColor, 'Theme theme.css should set .action-button button.test-custom-class background to rgb(32, 64, 128)')
  31. .to.match(/rgba?\(\s*32\s*,\s*64\s*,\s*128\s*(,\s*1)?\s*\)/)
  32. })
  33. it('cssClass override: style rule targeting custom class wins over component styles', async function () {
  34. await getRootAndWait()
  35. const buttonWithClass = await webdriver.findElements(By.css('.action-button button.test-custom-class'))
  36. expect(buttonWithClass).to.have.length.at.least(1)
  37. const beforePx = await buttonWithClass[0].getCssValue('border-top-width')
  38. await webdriver.executeScript(`
  39. var style = document.getElementById('cssclass-test-override-style');
  40. if (!style) {
  41. style = document.createElement('style');
  42. style.id = 'cssclass-test-override-style';
  43. style.textContent = '.test-custom-class { border-top-width: 31px !important; }';
  44. document.head.appendChild(style);
  45. } else {
  46. style.textContent = '.test-custom-class { border-top-width: 31px !important; }';
  47. }
  48. `)
  49. await webdriver.sleep(150)
  50. const afterPx = await buttonWithClass[0].getCssValue('border-top-width')
  51. const afterNum = parseInt(afterPx, 10)
  52. expect(afterNum).to.be.greaterThan(10, 'Override targeting cssClass should win over component 1px (before=' + beforePx + ' after=' + afterPx + ') (#804)')
  53. })
  54. it('cssClass is applied to display component', async function () {
  55. await getRootAndWait()
  56. const displayElements = await webdriver.findElements(By.css('.display.test-display-class'))
  57. expect(displayElements).to.have.length.at.least(1, 'Display component with cssClass test-display-class should be in DOM')
  58. const classAttr = await displayElements[0].getAttribute('class')
  59. expect(classAttr).to.include('test-display-class')
  60. })
  61. })