| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,54 @@ | |||
| 1 | + /// <reference types="Cypress" /> | ||
| 2 | + | ||
| 3 | + import { moveGutterByMouse, checkSplitDirAndSizes } from '../support/splitUtils' | ||
| 4 | + | ||
| 5 | + context('Toggling DOM and visibility example page tests', () => { | ||
| 6 | + const W = 1076 | ||
| 7 | + const H = 150 | ||
| 8 | + const GUTTER = 15 | ||
| 9 | + | ||
| 10 | + beforeEach(() => { | ||
| 11 | + cy.visit('/examples/toggling-dom-and-visibility') | ||
| 12 | + }) | ||
| 13 | + | ||
| 14 | + it('Display initial state', () => { | ||
| 15 | + checkSplitDirAndSizes('.split-example > as-split', 'horizontal', W, H, GUTTER, [348.66, 348.66, 348.66]) | ||
| 16 | + }) | ||
| 17 | + | ||
| 18 | + it('Hide first area and move gutter', () => { | ||
| 19 | + getVisibilityButton(0).click() | ||
| 20 | + checkSplitDirAndSizes('.split-example > as-split', 'horizontal', W, H, [0, GUTTER], [0, 530.5, 530.5]) | ||
| 21 | + | ||
| 22 | + moveGutterByMouse('.as-split-gutter', 1, 50, 0) | ||
| 23 | + checkSplitDirAndSizes('.split-example > as-split', 'horizontal', W, H, [0, GUTTER], [0, 580.5, 480.5]) | ||
| 24 | + | ||
| 25 | + moveGutterByMouse('.as-split-gutter', 1, -100, 0) | ||
| 26 | + checkSplitDirAndSizes('.split-example > as-split', 'horizontal', W, H, [0, GUTTER], [0, 480.5, 580.5]) | ||
| 27 | + }) | ||
| 28 | + | ||
| 29 | + it('Hide mid area and move gutter', () => { | ||
| 30 | + getVisibilityButton(1).click() | ||
| 31 | + checkSplitDirAndSizes('.split-example > as-split', 'horizontal', W, H, [GUTTER, 0], [530.5, 0, 530.5]) | ||
| 32 | + | ||
| 33 | + moveGutterByMouse('.as-split-gutter', 0, 50, 0) | ||
| 34 | + checkSplitDirAndSizes('.split-example > as-split', 'horizontal', W, H, [GUTTER, 0], [580.5, 0, 480.5]) | ||
| 35 | + | ||
| 36 | + moveGutterByMouse('.as-split-gutter', 0, -100, 0) | ||
| 37 | + checkSplitDirAndSizes('.split-example > as-split', 'horizontal', W, H, [GUTTER, 0], [480.5, 0, 580.5]) | ||
| 38 | + }) | ||
| 39 | + | ||
| 40 | + it('Hide last area and move gutter', () => { | ||
| 41 | + getVisibilityButton(2).click() | ||
| 42 | + checkSplitDirAndSizes('.split-example > as-split', 'horizontal', W, H, [GUTTER, 0], [530.5, 530.5, 0]) | ||
| 43 | + | ||
| 44 | + moveGutterByMouse('.as-split-gutter', 0, 50, 0) | ||
| 45 | + checkSplitDirAndSizes('.split-example > as-split', 'horizontal', W, H, [GUTTER, 0], [580.5, 480.5, 0]) | ||
| 46 | + | ||
| 47 | + moveGutterByMouse('.as-split-gutter', 0, -100, 0) | ||
| 48 | + checkSplitDirAndSizes('.split-example > as-split', 'horizontal', W, H, [GUTTER, 0], [480.5, 580.5, 0]) | ||
| 49 | + }) | ||
| 50 | + }) | ||
| 51 | + | ||
| 52 | + function getVisibilityButton(index) { | ||
| 53 | + return cy.get('.btn-group:first').find('> .btn').eq(index) | ||
| 54 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,12 +57,10 @@ export function checkSplitDirAndCalcSizes(el, dir, w, h, gutter, sizes) { | |||
| 57 | 57 | ||
| 58 | 58 | ////////////////////////////////////////// | |
| 59 | 59 | ||
| 60 | - export function checkSplitDirAndSizes(el, dir, w, h, gutter, sizes) { | ||
| 61 | - cy.log(`-- NEW SPLIT CHECK (${dir},${w},${h},${gutter})`) | ||
| 60 | + export function checkSplitDirAndSizes(el, dir, w, h, gutterOrGutters, sizes) { | ||
| 61 | + const gutters = Array.isArray(gutterOrGutters) ? gutterOrGutters : new Array(sizes.length - 1).fill(gutterOrGutters) | ||
| 62 | 62 | ||
| 63 | - // Before real test, check if values provided are ok ! | ||
| 64 | - const total = sizes.reduce((acc, v) => acc + v, 0) + gutter * (sizes.length - 1) | ||
| 65 | - // expect(total).to.eq((dir === 'horizontal') ? w : h); | ||
| 63 | + cy.log(`-- NEW SPLIT CHECK (${dir},${w},${h},[${gutters.join(',')}],[${sizes.join(',')}])`) | ||
| 66 | 64 | ||
| 67 | 65 | const propGridDir = dir === 'vertical' ? 'grid-template-rows' : 'grid-template-columns' | |
| 68 | 66 | cy.get(el).should('have.css', propGridDir).should('include', ' ') | |
@@ -75,10 +73,10 @@ export function checkSplitDirAndSizes(el, dir, w, h, gutter, sizes) { | |||
| 75 | 73 | ||
| 76 | 74 | cy.get(`${el} > .as-split-gutter`).should('have.length', sizes.length - 1) | |
| 77 | 75 | ||
| 78 | - cy.get(`${el} > .as-split-gutter`).then(($el) => { | ||
| 76 | + cy.get(`${el} > .as-split-gutter`).each(($el, index) => { | ||
| 79 | 77 | const rect = $el[0].getBoundingClientRect() | |
| 80 | 78 | ||
| 81 | - expect(rect[propSize]).to.be.eq(gutter) | ||
| 79 | + expect(rect[propSize]).to.be.eq(gutters[index]) | ||
| 82 | 80 | expect(round(rect[propSize2])).to.be.eq(round(propValue2)) | |
| 83 | 81 | }) | |
| 84 | 82 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -521,15 +521,18 @@ export class SplitComponent { | |||
| 521 | 521 | const tempAreasPixelSizes = [...dragStartContext.areasPixelSizes] | |
| 522 | 522 | // As we are going to shuffle the areas order for easier iterations we should work with area indices array | |
| 523 | 523 | // instead of actual area sizes array. | |
| 524 | - // We must also remove the invisible ones as we can't expand or shrink them. | ||
| 525 | - const areasIndices = tempAreasPixelSizes.map((_, index) => index).filter((index) => this._areas()[index].visible()) | ||
| 524 | + const areasIndices = tempAreasPixelSizes.map((_, index) => index) | ||
| 526 | 525 | // The two variables below are ordered for iterations with real area indices inside. | |
| 526 | + // We must also remove the invisible ones as we can't expand or shrink them. | ||
| 527 | 527 | const areasIndicesBeforeGutter = this.restrictMove() | |
| 528 | 528 | ? [dragStartContext.areaBeforeGutterIndex] | |
| 529 | - : areasIndices.slice(0, dragStartContext.areaBeforeGutterIndex + 1).reverse() | ||
| 529 | + : areasIndices | ||
| 530 | + .slice(0, dragStartContext.areaBeforeGutterIndex + 1) | ||
| 531 | + .filter((index) => this._areas()[index].visible()) | ||
| 532 | + .reverse() | ||
| 530 | 533 | const areasIndicesAfterGutter = this.restrictMove() | |
| 531 | 534 | ? [dragStartContext.areaAfterGutterIndex] | |
| 532 | - : areasIndices.slice(dragStartContext.areaAfterGutterIndex) | ||
| 535 | + : areasIndices.slice(dragStartContext.areaAfterGutterIndex).filter((index) => this._areas()[index].visible()) | ||
| 533 | 536 | // Based on direction we need to decide which areas are expanding and which are shrinking | |
| 534 | 537 | const potentialAreasIndicesArrToShrink = isDraggingForward ? areasIndicesAfterGutter : areasIndicesBeforeGutter | |
| 535 | 538 | const potentialAreasIndicesArrToExpand = isDraggingForward ? areasIndicesBeforeGutter : areasIndicesAfterGutter | |
| Back | FazBrowse Home | New Git URL |
0 commit comments