|
1 | 1 | /// <reference types="Cypress" /> |
2 | 2 |
|
3 | | -context('Direction change', () => { |
4 | | - beforeEach(() => { |
5 | | - cy.visit('http://localhost:4200/#/examples/simple-split') |
6 | | - }) |
7 | | - |
8 | | - it('cy.viewport() - set the viewport size and dimension', () => { |
9 | | - cy.viewport(800, 600); |
10 | | - |
11 | | - const W = 650; |
| 3 | +context('Basic operation', () => { |
| 4 | + const W = 1070; |
12 | 5 | const H = 300; |
13 | 6 | const GUTTER = 11; |
| 7 | + |
| 8 | + beforeEach(() => { |
| 9 | + cy.visit('http://localhost:4200/#/examples/simple-split') |
| 10 | + cy.viewport(1200, 800); |
| 11 | + }) |
14 | 12 |
|
15 | | - cy.get('as-split').should('have.css', 'flex-direction', 'row'); |
16 | | - cy.get('as-split-area[size="30"]').should('have.css', 'height', `${ H }px`); |
17 | | - cy.get('as-split-area[size="30"]').should('have.css', 'flex', '0 0 calc(-3.3px + 30%)'); |
18 | | - cy.get('as-split-area[size="70"]').should('have.css', 'height', `${ H }px`); |
19 | | - cy.get('as-split-area[size="70"]').should('have.css', 'flex', '0 0 calc(-7.7px + 70%)'); |
| 13 | + it('Display initial state', () => { |
| 14 | + checkSplitDirAndSizes('as-split', 'horizontal', W, H, GUTTER, ['calc(-3.3px + 30%)', 'calc(-7.7px + 70%)']); |
| 15 | + }) |
20 | 16 |
|
21 | | - cy.get('.btns > .btn').click(); |
| 17 | + it('Change direction', () => { |
| 18 | + cy.get('.btns > .btn').click(); |
| 19 | + |
| 20 | + checkSplitDirAndSizes('as-split', 'vertical', W, H, GUTTER, ['calc(-3.3px + 30%)', 'calc(-7.7px + 70%)']); |
| 21 | + }) |
| 22 | + |
| 23 | + it('Move gutter horizontally', () => { |
| 24 | + moveElement('as-split-gutter', 280, 0); |
| 25 | + |
| 26 | + checkSplitDirAndSizes('as-split', 'horizontal', W, H, GUTTER, ['calc(-6.20566px + 56.4151%)', 'calc(-4.79434px + 43.5849%)']); |
| 27 | + }) |
| 28 | + |
| 29 | + it('Change direction & move gutter vertically', () => { |
| 30 | + cy.get('.btns > .btn').click(); |
| 31 | + |
| 32 | + moveElement('as-split-gutter', 0, 60); |
22 | 33 |
|
23 | | - cy.get('as-split').should('have.css', 'flex-direction', 'column'); |
24 | | - cy.get('as-split-area[size="30"]').should('have.css', 'width', `${ W }px`); |
25 | | - cy.get('as-split-area[size="30"]').should('have.css', 'flex', '0 0 calc(-3.3px + 30%)'); |
26 | | - cy.get('as-split-area[size="70"]').should('have.css', 'width', `${ W }px`); |
27 | | - cy.get('as-split-area[size="70"]').should('have.css', 'flex', '0 0 calc(-7.7px + 70%)'); |
28 | | - }) |
| 34 | + checkSplitDirAndSizes('as-split', 'vertical', W, H, GUTTER, ['calc(-5.57586px + 50.6897%)', 'calc(-5.42414px + 49.3103%)']); |
| 35 | + }) |
| 36 | + |
| 37 | + it('Move gutter horizontally and move it back', () => { |
| 38 | + moveElement('as-split-gutter', 280, 0); |
| 39 | + |
| 40 | + checkSplitDirAndSizes('as-split', 'horizontal', W, H, GUTTER, ['calc(-6.20566px + 56.4151%)', 'calc(-4.79434px + 43.5849%)']); |
| 41 | + |
| 42 | + moveElement('as-split-gutter', -280, 0); |
| 43 | + |
| 44 | + checkSplitDirAndSizes('as-split', 'horizontal', W, H, GUTTER, ['calc(-3.29513px + 29.9558%)', 'calc(-7.70487px + 70.0442%)']); |
| 45 | + }) |
29 | 46 | }) |
30 | 47 |
|
| 48 | + |
| 49 | +function moveElement(element, x, y) { |
| 50 | + cy.get(`${ element }`) |
| 51 | + .trigger('mousedown', { which: 1, pageX: 0, pageY: 0 }) |
| 52 | + .trigger('mousemove', { pageX: x, pageY: y }); |
| 53 | + |
| 54 | + cy.document().trigger('mouseup', { force: true }); |
| 55 | + |
| 56 | +} |
| 57 | + |
| 58 | +function checkSplitDirAndSizes(el, dir, w, h, gutter, sizes) { |
| 59 | + const propFlexDir = (dir === 'horizontal') ? 'row' : 'column'; |
| 60 | + cy.get(el).should('have.css', 'flex-direction', propFlexDir); |
| 61 | + |
| 62 | + const propSize = (dir === 'horizontal') ? 'width' : 'height'; |
| 63 | + cy.get(`${ el } as-split-gutter`).should('have.css', propSize, `${ gutter }px`); |
| 64 | + |
| 65 | + const propSize2 = (propSize === 'width') ? 'height' : 'width'; |
| 66 | + const propValue2 = (propSize === 'width') ? h : w; |
| 67 | + |
| 68 | + cy.get(`${ el } as-split-area`) |
| 69 | + .should('have.length', sizes.length) |
| 70 | + .each(($li, index) => { |
| 71 | + cy.wrap($li).should('have.css', 'flex', `0 0 ${ sizes[index] }`); |
| 72 | + cy.wrap($li).should('have.css', propSize2, `${ propValue2 }px`); |
| 73 | + }) |
| 74 | +} |
0 commit comments