Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { defineConfig } from 'cypress'
import { trimEnd } from 'cypress/types/lodash'

import plugin from './cypress/plugins'

export default defineConfig({
viewportWidth: 1200,
viewportHeight: 800,
Expand All @@ -10,7 +12,7 @@ export default defineConfig({
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
return plugin(on, config)
},
baseUrl: 'http://localhost:4242',
},
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/1.simple.cy.js → cypress/e2e/1.simple.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference types="Cypress" />
/// <reference types="cypress" />

import {
moveGutterByMouse,
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/10.toggle.cy.js → cypress/e2e/10.toggle.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference types="Cypress" />
/// <reference types="cypress" />

import { moveGutterByMouse, checkSplitDirAndSizes } from '../support/splitUtils'

Expand Down Expand Up @@ -49,6 +49,6 @@ context('Toggling DOM and visibility example page tests', () => {
})
})

function getVisibilityButton(index) {
function getVisibilityButton(index: number): Cypress.Chainable<JQuery<HTMLElement>> {
return cy.get('.btn-group:first').find('> .btn').eq(index)
}
13 changes: 9 additions & 4 deletions cypress/e2e/2.minmax.cy.js → cypress/e2e/2.minmax.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference types="Cypress" />
/// <reference types="cypress" />

import {
moveGutterByMouse,
Expand Down Expand Up @@ -255,15 +255,20 @@ context('Min & max splits example page tests', () => {
})
})

function checkAreasClasses(sel, all) {
cy.get(sel).then(($areas) => {
interface AreaClassExpectation {
haveTo: string[]
notHaveTo: string[]
}

function checkAreasClasses(sel: string, all: AreaClassExpectation[]): void {
cy.get(sel).then(($areas: JQuery<HTMLElement>) => {
all.forEach((item, index) => {
checkAreaClasses($areas.eq(index), item.haveTo, item.notHaveTo)
})
})
}

function checkAreaClasses($area, haveTo, notHaveTo) {
function checkAreaClasses($area: JQuery<HTMLElement>, haveTo: string[], notHaveTo: string[]): void {
console.log('$area, haveTo, notHaveTo', $area, haveTo, notHaveTo)
haveTo.forEach((cl) => cy.wrap($area).should('have.class', cl))
notHaveTo.forEach((cl) => cy.wrap($area).should('not.have.class', cl))
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/3.nested.cy.js → cypress/e2e/3.nested.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference types="Cypress" />
/// <reference types="cypress" />

import { moveGutterByMouse, checkSplitDirAndSizes } from '../support/splitUtils'

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/4.sync.cy.js → cypress/e2e/4.sync.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference types="Cypress" />
/// <reference types="cypress" />

import { moveGutterByMouse, checkSplitDirAndSizes } from '../support/splitUtils'

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/5.style.cy.js → cypress/e2e/5.style.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference types="Cypress" />
/// <reference types="cypress" />

import { moveGutterByMouse, checkSplitDirAndSizes } from '../support/splitUtils'

Expand Down
18 changes: 16 additions & 2 deletions cypress/e2e/7.click.cy.js → cypress/e2e/7.click.cy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
/// <reference types="Cypress" />
/// <reference types="cypress" />

import { moveGutterByMouse, checkSplitDirAndSizes } from '../support/splitUtils'

function checkEventCount({ dragStartCount, dragEndCount, gutterClickCount, gutterDblClickCount, transitionEndCount }) {
interface GutterEventCounts {
dragStartCount?: number
dragEndCount?: number
gutterClickCount?: number
gutterDblClickCount?: number
transitionEndCount?: number
}

function checkEventCount({
dragStartCount,
dragEndCount,
gutterClickCount,
gutterDblClickCount,
transitionEndCount,
}: GutterEventCounts): void {
if (dragStartCount !== undefined) {
cy.get('.logs ul li').filter('.dragStart').should('have.length', dragStartCount)
}
Expand Down
14 changes: 7 additions & 7 deletions cypress/e2e/9.geek.cy.js → cypress/e2e/9.geek.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference types="Cypress" />
/// <reference types="cypress" />

import { moveGutterByMouse, checkSplitDirAndSizes } from '../support/splitUtils'

Expand Down Expand Up @@ -276,22 +276,22 @@ context('Geek demo example page tests', () => {
})
})

function checkAreaOrder() {
function checkAreaOrder(): void {
// Retrieve all as-split-area displayed in order
cy.get('.as-split-area').then(($splitAreas) => {
const splitAreasNum = $splitAreas.map((i, $el) => $el.textContent)
cy.get('.as-split-area').then(($splitAreas: JQuery<HTMLElement>) => {
const splitAreasNum = $splitAreas.map((_i, $el) => $el.textContent)

// Retrieve all listed areas displayed in order
cy.get('.opts-area div[draggable="true"] .num').then(($controlAreas) => {
const controlAreasNum = $controlAreas.map((i, $el) => $el.textContent)
cy.get('.opts-area div[draggable="true"] .num').then(($controlAreas: JQuery<HTMLElement>) => {
const controlAreasNum = $controlAreas.map((_i, $el) => $el.textContent)

// Compare 2 lists > should be the same
expect(splitAreasNum.get()).to.deep.eq(controlAreasNum.get())
})
})
}

function moveArea(numArea, gap) {
function moveArea(numArea: number, gap: number): void {
cy.get('.opts-area div[draggable="true"]')
.eq(numArea)
.as('movedItem')
Expand Down
4 changes: 3 additions & 1 deletion cypress/plugins/index.js → cypress/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

module.exports = (on, config) => {
function plugin(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions): void {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}

export default plugin
File renamed without changes.
2 changes: 2 additions & 0 deletions cypress/support/e2e.js → cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// https://on.cypress.io/configuration
// ***********************************************************

/// <reference types="cypress" />

// Import commands.js using ES2015 syntax:
import './commands'

Expand Down
54 changes: 39 additions & 15 deletions cypress/support/splitUtils.js → cypress/support/splitUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export function moveGutterByMouse(gutters, num, x, y) {
export type SplitDirection = 'horizontal' | 'vertical'

type RectSize = 'width' | 'height'

function isGutterArray(value: number | readonly number[]): value is readonly number[] {
return Array.isArray(value)
}

export function moveGutterByMouse(gutters: string, num: number, x: number, y: number): void {
cy.get(gutters)
.eq(num)
.trigger('mousedown', { which: 1, clientX: 0, clientY: 0, button: 0 })
Expand All @@ -13,38 +21,45 @@ export function moveGutterByMouse(gutters, num, x, y) {
cy.wait(10)
}

export function moveGutterByKeyboard(gutters, num, numKeyPresses, keySequence) {
export function moveGutterByKeyboard(gutters: string, num: number, numKeyPresses: number, keySequence: string): void {
for (let i = 0; i < numKeyPresses; i++) {
cy.get(gutters).eq(num).focus().type(`{${keySequence}}`)
cy.wait(10)
}
}

export function checkGutterAriaLabel(gutters, num, ariaLabel) {
export function checkGutterAriaLabel(gutters: string, num: number, ariaLabel: string): void {
cy.get(gutters).eq(num).should('have.attr', 'aria-label').and('equal', ariaLabel)
}

export function checkGuttersAriaValueTexts(gutters, ariaValueTexts) {
export function checkGuttersAriaValueTexts(gutters: string, ariaValueTexts: ReadonlyArray<string | null>): void {
cy.get(gutters).each(($gutter, index) => {
const ariaValueText = ariaValueTexts[index]
if (ariaValueText === null) {
cy.wrap($gutter).should('not.have.attr', 'aria-valuetext')
} else {
cy.wrap($gutter).should('have.attr', 'aria-valuetext').and('equal', ariaValueTexts[index])
cy.wrap($gutter).should('have.attr', 'aria-valuetext').and('equal', ariaValueText)
}
})
}

//////////////////////////////////////////

export function checkSplitDirAndCalcSizes(el, dir, w, h, gutter, sizes) {
export function checkSplitDirAndCalcSizes(
el: string,
dir: SplitDirection,
w: number,
h: number,
gutter: number,
sizes: ReadonlyArray<number | string>,
): void {
const propFlexDir = dir === 'horizontal' ? 'row' : 'column'
cy.get(el).should('have.css', 'flex-direction', propFlexDir)

const propSize = dir === 'horizontal' ? 'width' : 'height'
const propSize: RectSize = dir === 'horizontal' ? 'width' : 'height'
cy.get(`${el} > .as-split-gutter`).should('have.css', propSize, `${gutter}px`)

const propSize2 = propSize === 'width' ? 'height' : 'width'
const propSize2: RectSize = propSize === 'width' ? 'height' : 'width'
const propValue2 = propSize === 'width' ? h : w

cy.get(`${el} > as-split-area`)
Expand All @@ -57,23 +72,32 @@ export function checkSplitDirAndCalcSizes(el, dir, w, h, gutter, sizes) {

//////////////////////////////////////////

export function checkSplitDirAndSizes(el, dir, w, h, gutterOrGutters, sizes) {
const gutters = Array.isArray(gutterOrGutters) ? gutterOrGutters : new Array(sizes.length - 1).fill(gutterOrGutters)
export function checkSplitDirAndSizes(
el: string,
dir: SplitDirection,
w: number,
h: number,
gutterOrGutters: number | readonly number[],
sizes: readonly number[],
): void {
const gutters = isGutterArray(gutterOrGutters)
? gutterOrGutters
: new Array<number>(sizes.length - 1).fill(gutterOrGutters)

cy.log(`-- NEW SPLIT CHECK (${dir},${w},${h},[${gutters.join(',')}],[${sizes.join(',')}])`)

const propGridDir = dir === 'vertical' ? 'grid-template-rows' : 'grid-template-columns'
cy.get(el).should('have.css', propGridDir).should('include', ' ')

const propSize = dir === 'horizontal' ? 'width' : 'height'
const propSize2 = propSize === 'width' ? 'height' : 'width'
const propSize: RectSize = dir === 'horizontal' ? 'width' : 'height'
const propSize2: RectSize = propSize === 'width' ? 'height' : 'width'
const propValue2 = propSize === 'width' ? h : w

const round = (value) => Math.round(value * 10) / 10
const round = (value: number): number => Math.round(value * 10) / 10

cy.get(`${el} > .as-split-gutter`).should('have.length', sizes.length - 1)

cy.get(`${el} > .as-split-gutter`).each(($el, index) => {
cy.get(`${el} > .as-split-gutter`).each(($el: JQuery<HTMLElement>, index) => {
const rect = $el[0].getBoundingClientRect()

expect(rect[propSize]).to.be.eq(gutters[index])
Expand All @@ -82,7 +106,7 @@ export function checkSplitDirAndSizes(el, dir, w, h, gutterOrGutters, sizes) {

cy.get(`${el} > .as-split-area`)
.should('have.length', sizes.length)
.each(($li, index) => {
.each(($li: JQuery<HTMLElement>, index) => {
const rect = $li[0].getBoundingClientRect()

expect(round(rect[propSize])).to.be.eq(round(sizes[index]))
Expand Down
16 changes: 16 additions & 0 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["cypress", "node"],
"lib": ["es2022", "dom"],
"module": "es2020",
"moduleResolution": "node10",
"noEmit": true,
"strict": true,
"skipLibCheck": true,
"isolatedModules": true,
"sourceMap": false
},
"include": ["./**/*.ts", "../cypress.config.ts"],
"exclude": []
}
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"lint_lib": "wireit",
"lint_app": "wireit",
"lint": "wireit",
"cypress_typecheck": "wireit",
"ng": "ng",
"start": "wireit",
"prepare": "husky install",
Expand Down Expand Up @@ -127,10 +128,21 @@
"test_ci": {
"dependencies": [
"build",
"cypress_typecheck",
"cypress_serve",
"cypress_run"
]
},
"cypress_typecheck": {
"command": "tsc -p cypress/tsconfig.json --noEmit --pretty false",
"files": [
"cypress/**/*.ts",
"cypress/tsconfig.json",
"cypress.config.ts",
"tsconfig.json"
],
"output": []
},
"ng_serve": {
"command": "ng serve --port 4242",
"service": true
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
},
"angularCompilerOptions": {
"strictTemplates": true
}
},
"exclude": ["cypress", "cypress.config.ts"]
}