Skip to content

Commit

Permalink
✨ feat(testing): cypress flexible imports (#1012)
Browse files Browse the repository at this point in the history
* feat(testing): split exports into seperate files

* chore: enable src folder for npm

* chore: change build strategy

* chore: add changeset

* chore: change to es5

* chore: add new command

* feat(testing): add new commands

* chore: improve docs

* chore: remove duplicate changes

* chore: update docs
  • Loading branch information
hirsch88 committed Aug 9, 2023
1 parent c271ed2 commit 1d5dcc7
Show file tree
Hide file tree
Showing 26 changed files with 282 additions and 133 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-cobras-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baloise/design-system-testing': minor
---

testing library supports file by file import
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"Baloise",
"bday",
"bubu",
"myusername",
"googlemaps",
"gapless",
"FAVICONS",
Expand Down
3 changes: 2 additions & 1 deletion packages/components/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { defineConfig } from 'cypress'
import getCompareSnapshotsPlugin from 'cypress-visual-regression/dist/plugin'

export default defineConfig({
projectId: 'dnm1ky',
video: false,
screenshotOnRunFailure: true,
screenshotsFolder: './cypress/snapshots/actual',
Expand All @@ -15,6 +14,8 @@ export default defineConfig({
failSilently: false,
},

includeShadowDom: true,

e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { I18n } from '../../interfaces'

interface I18nCloseLabel {
interface I18nBalClose {
close: string
}

export const i18nCloseLabel: I18n<I18nCloseLabel> = {
export const i18nBalClose: I18n<I18nBalClose> = {
de: {
close: 'Schliessen',
},
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/components/bal-close/bal-close.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { inheritAttributes } from '../../utils/attributes'
import { BEM } from '../../utils/bem'
import { BalConfigObserver, BalConfigState } from '../../interfaces'
import { BalLanguage, BalRegion, ListenToConfig, defaultConfig } from '../../utils/config'
import { i18nCloseLabel } from './bal-close.i18n'
import { i18nBalClose } from './bal-close.i18n'

@Component({
tag: 'bal-close',
Expand Down Expand Up @@ -47,7 +47,7 @@ export class Close implements ComponentInterface, BalConfigObserver {
const blockEl = BEM.block('close')
const buttonEl = blockEl.element('button')
const iconEl = buttonEl.element('icon')
const label = i18nCloseLabel[this.language].close
const label = i18nBalClose[this.language].close

return (
<Host class={{ ...blockEl.class() }}>
Expand Down
13 changes: 7 additions & 6 deletions packages/components/src/components/bal-steps/stories/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ describe('Steps', () => {

A list of the custom commands for this specific component.

| Command | Description | Signature |
| ----------------------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `balStepsFindItems` | Returns the tab items. | `(options?: Partial<Loggable>): Chainable<JQuery>` |
| `balStepsFindLabel` | Returns the label of the tab item. | `(options?: Partial<Loggable>): Chainable<JQuery>` |
| `balStepsShouldHaveItems` | Assert that the tab has the given item. | `(labels: string[], dataType?: 'label' \| 'value', options?: Partial<Loggable>): Chainable<JQuery>` |
| `balStepsItemShouldHaveState` | Assert that the tab item has the given state. | `(state: 'done' \| 'failed' \| 'active' \| 'disabled', options?: Partial<Loggable>): Chainable<JQuery>` |
| Command | Description | Signature |
| -------------------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `balStepsFindItems` | Returns the tab items. | `(options?: Partial<Loggable>): Chainable<JQuery>` |
| `balStepsFindLabel` | Returns the label of the tab item. | `(options?: Partial<Loggable>): Chainable<JQuery>` |
| `balStepsShouldHaveItems` | Assert that the tab has the given item. | `(labels: string[], dataType?: 'label' \| 'value', options?: Partial<Loggable>): Chainable<JQuery>` |
| `balStepsItemShouldHaveState` | Assert that the tab item has the given state. | `(state: 'done' \| 'failed' \| 'active' \| 'disabled', options?: Partial<Loggable>): Chainable<JQuery>` |
| `balStepsItemShouldNotHaveState` | Assert that the tab item has not the given state. | `(state: 'done' \| 'failed' \| 'active' \| 'disabled', options?: Partial<Loggable>): Chainable<JQuery>` |


### Component Element Selectors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { I18n } from '../../../interfaces'

interface I18nDate {
interface I18nBalDatepicker {
months: string[]
monthsShort: string[]
weekdays: string[]
weekdaysShort: string[]
weekdaysMin: string[]
}

export const i18nDate: I18n<I18nDate> = {
export const i18nBalDatepicker: I18n<I18nBalDatepicker> = {
de: {
months: 'Januar_Februar_März_April_Mai_Juni_Juli_August_September_Oktober_November_Dezember'.split('_'),
monthsShort: 'Jan._Feb._März_Apr._Mai_Juni_Juli_Aug._Sep._Okt._Nov._Dez.'.split('_'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
} from '@baloise/web-app-utils'
import isNil from 'lodash.isnil'
import { ACTION_KEYS, isCtrlOrCommandKey, NUMBER_KEYS } from '../../../utils/constants/keys.constant'
import { i18nDate } from './bal-datepicker.i18n'
import { i18nBalDatepicker } from './bal-datepicker.i18n'
import {
defaultConfig,
BalConfigObserver,
Expand Down Expand Up @@ -449,7 +449,7 @@ export class Datepicker
}

get months(): { name: string; index: number }[] {
const monthNames = i18nDate[this.language].monthsShort
const monthNames = i18nBalDatepicker[this.language].monthsShort
let months = monthNames.map((name, index) => ({ name, index }))

if (this.min && this.pointerDate.year === getYear(parse(this.min) as Date)) {
Expand All @@ -466,7 +466,7 @@ export class Datepicker
}

get weekDays(): string[] {
const translations = [...i18nDate[this.language].weekdaysMin]
const translations = [...i18nBalDatepicker[this.language].weekdaysMin]
translations.push(translations.shift() || '')
return translations
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { I18n } from '../../../../interfaces'

interface I18nFieldLabel {
interface I18nBalFieldLabel {
optional: string
}

export const i18nFieldLabel: I18n<I18nFieldLabel> = {
export const i18nBalFieldLabel: I18n<I18nBalFieldLabel> = {
de: {
optional: ' (optional)',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { I18n } from '../../../interfaces'

interface I18nTime {
interface I18nBalTimeInput {
hours: string
minutes: string
}

export const i18nTime: I18n<I18nTime> = {
export const i18nBalTimeInput: I18n<I18nBalTimeInput> = {
de: {
hours: 'hh',
minutes: 'mm',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { debounceEvent, findItemLabel } from '../../../utils/helpers'
import { inheritAttributes } from '../../../utils/attributes'
import { ACTION_KEYS, NUMBER_KEYS, isCtrlOrCommandKey } from '../../../utils/constants/keys.constant'
import { BEM } from '../../../utils/bem'
import { i18nTime } from './bal-time-input.i18n'
import { i18nBalTimeInput } from './bal-time-input.i18n'

@Component({
tag: 'bal-time-input',
Expand Down Expand Up @@ -281,7 +281,7 @@ export class TimeInput implements ComponentInterface, BalConfigObserver, FormInp
disabled={this.disabled}
readonly={this.readonly}
required={this.required}
placeholder={`${i18nTime[this.language].hours}:${i18nTime[this.language].minutes}`}
placeholder={`${i18nBalTimeInput[this.language].hours}:${i18nBalTimeInput[this.language].minutes}`}
value={value}
onInput={ev => this.onInput(ev as InputEvent)}
onFocus={e => this.onFocus(e)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { I18n } from '../../../interfaces'

interface I18nLabel {
interface I18nBalLabel {
optional: string
}

export const i18nLabel: I18n<I18nLabel> = {
export const i18nBalLabel: I18n<I18nBalLabel> = {
de: {
optional: ' (optional)',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ListenToConfig,
} from '../../../utils/config'
import { Loggable, Logger, LogInstance } from '../../../utils/log'
import { i18nLabel } from './bal-label.i18n'
import { i18nBalLabel } from './bal-label.i18n'
import { BalElementStateInfo } from '../../../utils/element-states'
import { BalMutationObserver, ListenToMutation } from '../../../utils/mutation'

Expand Down Expand Up @@ -167,7 +167,7 @@ export class BalLabel

render() {
const block = BEM.block('label')
const suffix = this.required === false ? i18nLabel[this.language].optional || '' : ''
const suffix = this.required === false ? i18nBalLabel[this.language].optional || '' : ''
const disabled = !!this.disabled || !!this.readonly
const danger = !!this.invalid
const success = !!this.valid
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export * from './components/notice/bal-modal/bal-modal.type'
export * from './components/form/bal-checkbox/bal-checkbox.type'
export * from './components/form/bal-radio/bal-radio.type'

/**
* i18n
*/
export * from './components/bal-close/bal-close.i18n'
export * from './components/form/bal-field/bal-field-label/bal-field-label.i18n'
export * from './components/form/bal-datepicker/bal-datepicker.i18n'
export * from './components/form/bal-time-input/bal-time-input.i18n'
export * from './components/typography/bal-label/bal-label.i18n'

/**
* Utils
*/
Expand Down
Loading

0 comments on commit 1d5dcc7

Please sign in to comment.