Skip to content

Commit

Permalink
chore(flags): add cypress regression test to ensure flags rendering a…
Browse files Browse the repository at this point in the history
…s expected in FlagSelector component (#26103)
  • Loading branch information
havenbarnes authored Nov 12, 2024
1 parent 87c1a79 commit 3cbb152
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
23 changes: 23 additions & 0 deletions cypress/e2e/featureFlags.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,27 @@ describe('Feature Flags', () => {
cy.get('[data-attr=taxonomic-operator]').contains('= equals').click({ force: true })
cy.get('.operator-value-option').contains('> after').should('not.exist')
})

it('Renders flags in FlagSelector', () => {
// Create flag name
cy.get('[data-attr=top-bar-name]').should('contain', 'Feature flags')
cy.get('[data-attr=new-feature-flag]').click()
cy.get('[data-attr=feature-flag-key]').click().type(`{moveToEnd}${name}`).should('have.value', name)
cy.get('[data-attr=rollout-percentage]').clear().type('50').should('have.value', '50')

// save the feature flag
cy.get('[data-attr=save-feature-flag]').first().click()

// go to surveys page to check if the flag is rendered in the FlagSelector
cy.reload()
cy.clickNavMenu('surveys')
cy.get('[data-attr="new-survey"]').click()
cy.get('[data-attr="new-blank-survey"]').click()

cy.get('[data-attr="survey-display-conditions"]').click()
cy.get('[data-attr="survey-display-conditions-select"]').click()
cy.get('[data-attr="survey-display-conditions-select-users"]').click()
cy.get('[data-attr="survey-display-conditions-linked-flag"]').contains('Select flag').click()
cy.get('.Popover__box').should('contain', name)
})
})
1 change: 1 addition & 0 deletions frontend/src/lib/lemon-ui/LemonCollapse/LemonCollapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface LemonCollapsePanel<K extends React.Key> {
key: K
header: ReactNode
content: ReactNode
dataAttr?: string
className?: string
}

Expand Down
13 changes: 11 additions & 2 deletions frontend/src/scenes/surveys/SurveyEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ export default function SurveyEdit(): JSX.Element {
{
key: SurveyEditSection.DisplayConditions,
header: 'Display conditions',
dataAttr: 'survey-display-conditions',
content: (
<LemonField.Pure>
<LemonSelect
Expand All @@ -528,8 +529,13 @@ export default function SurveyEdit(): JSX.Element {
value={!hasTargetingSet}
options={[
{ label: 'All users', value: true },
{ label: 'Users who match all of the following...', value: false },
{
label: 'Users who match all of the following...',
value: false,
'data-attr': 'survey-display-conditions-select-users',
},
]}
data-attr="survey-display-conditions-select"
/>
{!hasTargetingSet ? (
<span className="text-muted">
Expand All @@ -548,7 +554,10 @@ export default function SurveyEdit(): JSX.Element {
}
>
{({ value, onChange }) => (
<div className="flex">
<div
className="flex"
data-attr="survey-display-conditions-linked-flag"
>
<FlagSelector value={value} onChange={onChange} />
{value && (
<LemonButton
Expand Down

0 comments on commit 3cbb152

Please sign in to comment.