2020-10-13 15:44:56 +02:00
|
|
|
describe('Feature Flags', () => {
|
2022-06-09 12:14:21 +02:00
|
|
|
let name
|
|
|
|
|
2020-10-13 15:44:56 +02:00
|
|
|
beforeEach(() => {
|
2022-06-09 12:14:21 +02:00
|
|
|
name = 'feature-flag-' + Math.floor(Math.random() * 10000000)
|
2020-10-22 10:58:32 +02:00
|
|
|
cy.visit('/feature_flags')
|
2020-10-13 15:44:56 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Create feature flag', () => {
|
2021-05-20 16:42:26 +02:00
|
|
|
// ensure unique names to avoid clashes
|
2020-10-13 15:44:56 +02:00
|
|
|
cy.get('h1').should('contain', 'Feature Flags')
|
|
|
|
cy.get('[data-attr=new-feature-flag]').click()
|
2022-06-09 12:14:21 +02:00
|
|
|
cy.get('[data-attr=feature-flag-key]').click().type(`{moveToEnd}${name}`).should('have.value', name)
|
2021-03-23 22:34:48 +01:00
|
|
|
cy.get('[data-attr=feature-flag-description]')
|
|
|
|
.type('This is a new feature.')
|
|
|
|
.should('have.value', 'This is a new feature.')
|
2020-11-20 11:03:14 +01:00
|
|
|
|
2022-08-03 18:22:33 +02:00
|
|
|
// Check that feature flags instructions can be displayed in another code language
|
|
|
|
cy.get('[data-attr=feature-flag-instructions-select]').click()
|
|
|
|
cy.get('[data-attr=feature-flag-instructions-select-option-PHP]').click()
|
|
|
|
cy.get('[data-attr=feature-flag-instructions-snippet]').should(
|
|
|
|
'contain',
|
|
|
|
/if (PostHog::isFeatureEnabled('.*', 'some distinct id')) {/
|
|
|
|
)
|
|
|
|
cy.get('[data-attr=feature-flag-instructions-snippet]').should('contain', / \/\/ do something here/)
|
|
|
|
cy.get('[data-attr=feature-flag-instructions-snippet]').should('contain', /}/)
|
|
|
|
cy.get('[data-attr=feature-flag-doc-link]').should(
|
|
|
|
'have.attr',
|
|
|
|
'href',
|
|
|
|
'https://posthog.com/docs/integrations/php-integration?utm_medium=in-product&utm_campaign=feature-flag#feature-flags'
|
|
|
|
)
|
|
|
|
|
2020-11-20 11:03:14 +01:00
|
|
|
// select "add filter" and "property"
|
2022-10-25 04:03:46 +02:00
|
|
|
cy.get('[data-attr=property-select-toggle-0').click()
|
2020-11-20 11:03:14 +01:00
|
|
|
|
|
|
|
// select the first property
|
2021-07-22 20:40:49 +02:00
|
|
|
cy.get('[data-attr=taxonomic-filter-searchfield]').click()
|
|
|
|
cy.get('[data-attr=taxonomic-filter-searchfield]').type('is_demo')
|
|
|
|
cy.get('[data-attr=taxonomic-tab-person_properties]').click()
|
|
|
|
cy.get('[data-attr=prop-filter-person_properties-0]').click({ force: true })
|
2020-11-20 11:03:14 +01:00
|
|
|
|
|
|
|
// selects the first value
|
|
|
|
cy.get('[data-attr=prop-val]').click()
|
|
|
|
cy.get('[data-attr=prop-val-0]').click({ force: true })
|
|
|
|
|
2021-11-16 09:12:21 +01:00
|
|
|
// save the feature flag
|
2022-10-25 04:03:46 +02:00
|
|
|
cy.get('[data-attr=save-feature-flag]').first().click()
|
2021-11-16 09:12:21 +01:00
|
|
|
|
2022-06-09 12:14:21 +02:00
|
|
|
// after save there should be a delete button
|
2022-10-25 04:03:46 +02:00
|
|
|
cy.get('button[data-attr="delete-feature-flag"]').should('have.text', 'Delete feature flag')
|
2022-06-09 12:14:21 +02:00
|
|
|
|
2021-11-16 09:12:21 +01:00
|
|
|
// make sure the data is there as expected after a page reload!
|
|
|
|
cy.reload()
|
|
|
|
|
|
|
|
// click the sidebar item to go back to the list
|
2022-06-09 12:14:21 +02:00
|
|
|
cy.clickNavMenu('featureflags')
|
2021-05-20 16:42:26 +02:00
|
|
|
cy.get('[data-attr=feature-flag-table]').should('contain', name)
|
2021-03-23 22:34:48 +01:00
|
|
|
cy.get('[data-attr=feature-flag-table]').should('not.contain', '%') // By default it's released to everyone, if a % is not specified
|
|
|
|
cy.get('[data-attr=feature-flag-table]').should('contain', 'is_demo')
|
2020-10-13 15:44:56 +02:00
|
|
|
|
2021-11-19 17:50:43 +01:00
|
|
|
cy.get(`[data-row-key=${name}]`).contains(name).click()
|
2022-10-25 04:03:46 +02:00
|
|
|
cy.get(`[data-attr=edit-feature-flag]`).click()
|
2021-05-20 16:42:26 +02:00
|
|
|
cy.get('[data-attr=feature-flag-key]')
|
2022-06-09 12:14:21 +02:00
|
|
|
.click()
|
|
|
|
.type(`{moveToEnd}-updated`)
|
2021-05-20 16:42:26 +02:00
|
|
|
.should('have.value', name + '-updated')
|
2022-10-25 04:03:46 +02:00
|
|
|
cy.get('[data-attr=save-feature-flag]').first().click()
|
2022-03-09 12:36:57 +01:00
|
|
|
cy.wait(100)
|
2022-06-09 12:14:21 +02:00
|
|
|
cy.clickNavMenu('featureflags')
|
2021-05-20 16:42:26 +02:00
|
|
|
cy.get('[data-attr=feature-flag-table]').should('contain', name + '-updated')
|
2021-04-02 20:07:33 +02:00
|
|
|
|
2021-11-19 17:50:43 +01:00
|
|
|
cy.get(`[data-row-key=${name}-updated] [data-attr=more-button]`).click()
|
2021-11-30 10:38:05 +01:00
|
|
|
cy.contains(`Try out in Insights`).click()
|
2021-04-02 20:07:33 +02:00
|
|
|
cy.location().should((loc) => {
|
|
|
|
expect(loc.pathname.toString()).to.contain('/insight')
|
|
|
|
})
|
2020-10-13 15:44:56 +02:00
|
|
|
})
|
2020-10-14 09:01:17 +02:00
|
|
|
|
|
|
|
it('Delete feature flag', () => {
|
|
|
|
cy.get('h1').should('contain', 'Feature Flags')
|
|
|
|
cy.get('[data-attr=new-feature-flag]').click()
|
2022-06-09 12:14:21 +02:00
|
|
|
cy.get('[data-attr=feature-flag-key]').focus().type(name).should('have.value', name)
|
2022-10-25 04:03:46 +02:00
|
|
|
cy.get('[data-attr=save-feature-flag]').first().click()
|
2022-06-09 12:14:21 +02:00
|
|
|
|
|
|
|
// after save there should be a delete button
|
2022-10-25 04:03:46 +02:00
|
|
|
cy.get('button[data-attr="delete-feature-flag"]').should('have.text', 'Delete feature flag')
|
2022-06-09 12:14:21 +02:00
|
|
|
|
|
|
|
cy.clickNavMenu('featureflags')
|
2021-05-20 16:42:26 +02:00
|
|
|
cy.get('[data-attr=feature-flag-table]').should('contain', name)
|
2021-11-19 17:50:43 +01:00
|
|
|
cy.get(`[data-row-key=${name}]`).contains(name).click()
|
2022-10-25 04:03:46 +02:00
|
|
|
cy.get('[data-attr=delete-feature-flag]').click()
|
2022-06-09 12:14:21 +02:00
|
|
|
cy.get('.Toastify').contains('Undo').should('be.visible')
|
2020-10-14 09:01:17 +02:00
|
|
|
})
|
2020-10-13 15:44:56 +02:00
|
|
|
})
|