-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(sbb-datepicker): attempt to stabilize visual regression tests (#…
- Loading branch information
1 parent
775d1fb
commit 25db2e4
Showing
6 changed files
with
112 additions
and
190 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
92 changes: 49 additions & 43 deletions
92
src/elements/datepicker/datepicker-next-day/datepicker-next-day.visual.spec.ts
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 |
---|---|---|
@@ -1,64 +1,70 @@ | ||
import { sendKeys } from '@web/test-runner-commands'; | ||
import { html, nothing } from 'lit'; | ||
|
||
import { tabKey } from '../../core/testing/private/keys.js'; | ||
import { | ||
describeEach, | ||
describeViewports, | ||
visualDiffDefault, | ||
visualDiffFocus, | ||
visualRegressionFixture, | ||
} from '../../core/testing/private.js'; | ||
import './datepicker-next-day.js'; | ||
|
||
import './datepicker-next-day.js'; | ||
import '../datepicker.js'; | ||
import '../../form-field.js'; | ||
|
||
describe(`sbb-datepicker-next-day`, () => { | ||
const cases = [ | ||
{ name: 'no value', value: null }, | ||
{ name: 'with value', value: '15.02.2023' }, | ||
]; | ||
const cases = { | ||
negative: [true, false], | ||
value: [null, '15.02.2023'], | ||
}; | ||
|
||
describeViewports({ viewports: ['zero', 'medium'] }, () => { | ||
for (const state of [visualDiffDefault, visualDiffFocus]) { | ||
it( | ||
`standalone`, | ||
visualDiffDefault.with(async (setup) => { | ||
await setup.withFixture(html`<sbb-datepicker-next-day></sbb-datepicker-next-day>`); | ||
}), | ||
); | ||
|
||
describeEach(cases, ({ negative, value }) => { | ||
let root: HTMLElement; | ||
|
||
beforeEach(async () => { | ||
root = await visualRegressionFixture( | ||
html` | ||
<sbb-form-field ?negative=${negative}> | ||
<input value=${value || nothing} /> | ||
<sbb-datepicker></sbb-datepicker> | ||
<sbb-datepicker-next-day></sbb-datepicker-next-day> | ||
</sbb-form-field> | ||
`, | ||
{ backgroundColor: negative ? 'var(--sbb-color-black)' : undefined }, | ||
); | ||
}); | ||
|
||
it( | ||
`standalone ${state.name}`, | ||
state.with(async (setup) => { | ||
await setup.withFixture(html` <sbb-datepicker-next-day></sbb-datepicker-next-day> `); | ||
`with form-field`, | ||
visualDiffDefault.with(async (setup) => { | ||
setup.withSnapshotElement(root); | ||
}), | ||
); | ||
|
||
for (const inputValue of cases) { | ||
it( | ||
`with picker ${inputValue.name} ${state.name}`, | ||
state.with(async (setup) => { | ||
await setup.withFixture(html` | ||
<div style="display: flex; gap: 1em;"> | ||
<input value="${inputValue.value || nothing}" id="datepicker-input" /> | ||
<sbb-datepicker | ||
id="datepicker" | ||
input="datepicker-input" | ||
now="2023-01-12T00:00:00Z" | ||
></sbb-datepicker> | ||
<sbb-datepicker-next-day date-picker="datepicker"></sbb-datepicker-next-day> | ||
</div> | ||
`); | ||
}), | ||
); | ||
it( | ||
`with form-field focus`, | ||
visualDiffDefault.with(async (setup) => { | ||
setup.withSnapshotElement(root); | ||
|
||
if (value) { | ||
// Focus input so that with a tab press it should land on next day | ||
setup.snapshotElement.querySelector('input')!.focus(); | ||
} else { | ||
setup.snapshotElement.focus(); | ||
} | ||
|
||
describeEach({ negative: [true, false] }, ({ negative }) => { | ||
it( | ||
`with form-field ${inputValue.name} ${state.name}`, | ||
state.with(async (setup) => { | ||
await setup.withFixture(html` | ||
<sbb-form-field ?negative=${negative}> | ||
<input value=${inputValue.value || nothing} /> | ||
<sbb-datepicker></sbb-datepicker> | ||
<sbb-datepicker-next-day ?negative=${negative}></sbb-datepicker-next-day> | ||
</sbb-form-field> | ||
`); | ||
}), | ||
); | ||
}); | ||
} | ||
} | ||
await sendKeys({ press: tabKey }); | ||
}), | ||
); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.