|
| 1 | +/** |
| 2 | + * This file contains tests that check the style of the slides. |
| 3 | + * It checks that the slides are not too high or wide and that |
| 4 | + * the code examples are not too wide or high based on the visibility of scrollbars. |
| 5 | + * |
| 6 | + * Slides that exist on the exemptions lists are tested for that violation |
| 7 | + * and if they are not violating the style, this alerts and the author should remove |
| 8 | + * the slide from the exemption list. This acts as a regression check. |
| 9 | + */ |
| 10 | +import { describe, it } from "mocha"; |
| 11 | +import { expect } from "@wdio/globals"; |
| 12 | +import { slides } from "./slides/slides.list.ts"; |
| 13 | +import { |
| 14 | + playground_size_exemptions, |
| 15 | + size_exemptions, |
| 16 | +} from "./slides/slide-exemptions.list.ts"; |
| 17 | +import Slide from "./objects/slide.ts"; |
| 18 | + |
| 19 | +// these are empirically determined values in 16:9 ratio |
| 20 | +const MAX_HEIGHT = 1333; |
| 21 | +const MAX_WIDTH = 750; |
| 22 | + |
| 23 | +const slide = new Slide(); |
| 24 | +slides.forEach((slide_path) => { |
| 25 | + describe("Slide " + slide_path, () => { |
| 26 | + before(async () => { |
| 27 | + slide.load(slide_path); |
| 28 | + }); |
| 29 | + |
| 30 | + // slide size evaluation |
| 31 | + if (size_exemptions.includes(slide_path)) { |
| 32 | + // This slide is exempted and violated rules before. |
| 33 | + // It is expected to still do this and if not it should be removed from exemptions. |
| 34 | + // This acts as a regression check |
| 35 | + it("is on the exemption list but should be removed from size_exemptions in slide-exemptions.list.ts", async () => { |
| 36 | + const main_element = slide.main_content; |
| 37 | + console.info("slide " + slide_path + " is on the exemption list"); |
| 38 | + expect( |
| 39 | + await slide.violates_max_size(main_element, MAX_HEIGHT, MAX_WIDTH), |
| 40 | + ).toBe(true); |
| 41 | + }); |
| 42 | + } else { |
| 43 | + it( |
| 44 | + "should not be higher than " + |
| 45 | + MAX_HEIGHT + |
| 46 | + " pixels or wider than " + |
| 47 | + MAX_WIDTH + |
| 48 | + " pixels", |
| 49 | + async () => { |
| 50 | + const main_element = slide.main_content; |
| 51 | + expect( |
| 52 | + await slide.violates_max_size(main_element, MAX_HEIGHT, MAX_WIDTH), |
| 53 | + ).toBe(false); |
| 54 | + }, |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + // playground code examples are not too wide |
| 59 | + if (playground_size_exemptions.includes(slide_path)) { |
| 60 | + it("is on the exemption list but should be removed from playground_size_exemptions in slide-exemptions.list.ts", async () => { |
| 61 | + // This slide is exempted and violated rules before. |
| 62 | + // It is expected to still do this and if not it should be removed from exemptions. |
| 63 | + // This acts as a regression check |
| 64 | + await Promise.any([ |
| 65 | + expect(slide.scrollbar_h).toBeDisplayed(), |
| 66 | + expect(slide.scrollbar_v).toBeDisplayed(), |
| 67 | + ]); |
| 68 | + }); |
| 69 | + } else { |
| 70 | + it("should not show a scrollbar", async () => { |
| 71 | + if (await slide.has_code_example) { |
| 72 | + await Promise.all([ |
| 73 | + expect(slide.scrollbar_h).not.toBeDisplayed(), |
| 74 | + expect(slide.scrollbar_v).not.toBeDisplayed(), |
| 75 | + ]); |
| 76 | + } |
| 77 | + }); |
| 78 | + } |
| 79 | + }); |
| 80 | +}); |
0 commit comments