-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: extract assertFormLayoutGrid test helper
- Loading branch information
Showing
4 changed files
with
34 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { expect } from '@vaadin/chai-plugins'; | ||
|
||
/** | ||
* Asserts that the given form layout has the specified number of columns and rows. | ||
*/ | ||
export function assertFormLayoutGrid(layout, { columns, rows }) { | ||
const children = [...layout.children]; | ||
expect(new Set(children.map((child) => child.offsetLeft)).size).to.equal(columns, `expected ${columns} columns`); | ||
expect(new Set(children.map((child) => child.offsetTop)).size).to.equal(rows, `expected ${rows} rows`); | ||
} | ||
|
||
/** | ||
* Asserts that the given form layout has the specified label position. | ||
*/ | ||
export function assertFormLayoutLabelPosition(layout, { position }) { | ||
const columnWidth = parseFloat(layout.columnWidth); | ||
const labelWidth = parseFloat(getComputedStyle(layout).getPropertyValue('--vaadin-form-layout-label-width')); | ||
const labelSpacing = parseFloat(getComputedStyle(layout).getPropertyValue('--vaadin-form-layout-label-spacing')); | ||
|
||
[...layout.children].forEach((child) => { | ||
if (child.localName !== 'vaadin-form-item') { | ||
return; | ||
} | ||
|
||
if (position === 'aside') { | ||
expect(child.offsetWidth).to.equal(columnWidth + labelWidth + labelSpacing, 'expected labels to be aside'); | ||
} else { | ||
expect(child.offsetWidth).to.equal(columnWidth, 'expected labels to be above'); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters