From 9ce66b63023dd34d244eaa935417dddd8c0dc037 Mon Sep 17 00:00:00 2001 From: kyle Date: Sat, 5 Dec 2020 13:08:39 +0000 Subject: [PATCH] Polyfill switch component for E2E, improve users tests and segment priorities --- common/project.js | 13 ++++++------- tests/helpers.js | 5 +++-- tests/index.test.js | 12 +++++------- tests/segement-priorities.test.js | 9 +++++++-- tests/users.test.js | 17 ++++++++++++----- web/components/Switch.js | 17 +++++++++++++++++ web/project/modals.js | 2 +- web/styles/project/_utils.scss | 7 +++++++ 8 files changed, 58 insertions(+), 24 deletions(-) diff --git a/common/project.js b/common/project.js index 8388b5a0..c24c9305 100644 --- a/common/project.js +++ b/common/project.js @@ -1,12 +1,11 @@ module.exports = global.Project = { - api: 'https://api-dev.bullet-train.io/api/v1/', - flagsmithClientAPI: 'https://api.bullet-train.io/api/v1/', - flagsmith: '8KzETdDeMY7xkqkSkY3Gsg', // This is our Bullet Train API key - Bullet Train runs on Bullet Train! - debug: false, - delighted: true, // determines whether to shw delighted feedback widget - env: 'dev', // This is used for Sentry tracking - ga: 'UA-120237963-3', // This is our Google Analytics key + api: 'https://api-staging.flagsmith.com/api/v1/', + flagsmithClientAPI: 'https://api.flagsmith.com/api/v1/', + flagsmith: 'ENktaJnfLVbLifybz34JmX', // This is our Bullet Train API key - Bullet Train runs on Bullet Train! + env: 'staging', // This is used for Sentry tracking + ga: 'UA-120237963-7', // This is our Google Analytics key maintenance: false, // trigger maintenance mode + delighted: true, // determines whether to shw delighted feedback widget demoAccount: { email: 'kyle+bullet-train@solidstategroup.com', password: 'demo_account', diff --git a/tests/helpers.js b/tests/helpers.js index f6fa1f8d..5355fa1d 100644 --- a/tests/helpers.js +++ b/tests/helpers.js @@ -104,7 +104,7 @@ const testHelpers = { .waitForElementVisible(byId(`feature-item-${index}`)); }, saveFeature(browser) { - browser.pause(500); + browser.pause(200); browser.click('#update-feature-btn') .waitForElementNotPresent('#create-feature-modal'); }, @@ -128,6 +128,7 @@ const testHelpers = { gotoFeature(browser, index) { browser.click(byId(`feature-item-${index}`)) .waitForElementPresent('#create-feature-modal'); + browser.pause(200) }, createTrait(browser, index, id, value) { browser @@ -163,7 +164,7 @@ const testHelpers = { }, setSegmentOverrideIndex: (browser, index, newIndex) => { browser.setValue(byId(`sort-${index}`), `${newIndex}`); - browser.pause(100); + browser.pause(500); }, createSegment: (browser, index, id, rules) => { const setSegmentRule = testHelpers.setSegmentRule; diff --git a/tests/index.test.js b/tests/index.test.js index e25d1b93..d4e02c30 100644 --- a/tests/index.test.js +++ b/tests/index.test.js @@ -5,7 +5,7 @@ const path = require('path'); const SLACK_TOKEN = process.env.SLACK_TOKEN; const slackUpload = SLACK_TOKEN && require('./slack-upload.test'); -const slackMessage = SLACK_TOKEN && require('../server/slack-client'); +const slackMessage = false && require('../server/slack-client'); // to enable e2e slack messages change to SLACK_TOKEN && require const fork = require('child_process').fork; process.env.PORT = 8081; @@ -27,7 +27,7 @@ const formatCommit = function () { }; const sendSuccess = function () { - if (SLACK_TOKEN) { + if (slackMessage) { console.log('SENDING SLACK MESSAGE'); return slackMessage(`Tests Passed!${formatCommit()}`, E2E_SLACK_CHANNEL_NAME); } @@ -73,7 +73,7 @@ const sendFailure = (browser, done, request, error) => { const lastError = error && error.value ? JSON.parse(error.value) : 'No last error'; console.log('Last request:', lastRequest); console.log('Last error:', lastError); - if (SLACK_TOKEN && E2E_SLACK_CHANNEL) { + if (SLACK_TOKEN && E2E_SLACK_CHANNEL && slackMessage) { const uri = path.join(__dirname, 'screenshot.png'); browser.saveScreenshot(uri, () => { slackUpload(uri, `E2E for Bullet Train Failed. ${formatCommit()}\n\`\`\`${JSON.stringify({ @@ -90,8 +90,7 @@ const sendFailure = (browser, done, request, error) => { let testsFailed; const exitTests = (browser, done) => { - if (process.env.BRK) - return + if (process.env.BRK) return; browser.end(); done(); server.kill('SIGINT'); @@ -107,7 +106,7 @@ process.on('SIGINT', () => { module.exports = Object.assign( { before: (browser, done) => { - if (SLACK_TOKEN) { + if (slackMessage) { slackMessage(`Running tests.${formatCommit()}`, E2E_SLACK_CHANNEL_NAME); } server = fork('./server'); @@ -163,4 +162,3 @@ module.exports = Object.assign( require('./register-fail.test'), // Registration failure tests require('./login-fail.test'), // Login failure tests ); - diff --git a/tests/segement-priorities.test.js b/tests/segement-priorities.test.js index 946833b1..283962da 100644 --- a/tests/segement-priorities.test.js +++ b/tests/segement-priorities.test.js @@ -61,7 +61,7 @@ module.exports = { browser.expect.element(byId('user-feature-value-1')).text.to.equal('1'); }, '[Segments Priority Tests] - Prioritise segment 2': function (browser) { - testHelpers.gotoFeatures(browser, 0); + testHelpers.gotoFeatures(browser); testHelpers.gotoFeature(browser, 0); testHelpers.setSegmentOverrideIndex(browser, 1, 0); testHelpers.saveFeature(browser); @@ -73,7 +73,7 @@ module.exports = { browser.waitForElementVisible(byId('user-feature-switch-0-off')); }, '[Segments Priority Tests] - Prioritise segment 3': function (browser) { - testHelpers.gotoFeatures(browser, 0); + testHelpers.gotoFeatures(browser); testHelpers.gotoFeature(browser, 0); testHelpers.setSegmentOverrideIndex(browser, 2, 0); testHelpers.saveFeature(browser); @@ -84,4 +84,9 @@ module.exports = { browser.expect.element(byId('user-feature-value-1')).text.to.equal('3'); browser.waitForElementVisible(byId('user-feature-switch-0-on')); }, + '[Segments Priority Tests] - Clear down features': function (browser) { + testHelpers.gotoFeatures(browser); + testHelpers.deleteFeature(browser, 1, 'flag'); + testHelpers.deleteFeature(browser, 0, 'config'); + }, }; diff --git a/tests/users.test.js b/tests/users.test.js index b520114f..7b7f4141 100644 --- a/tests/users.test.js +++ b/tests/users.test.js @@ -3,16 +3,23 @@ const expect = require('chai').expect; const { byTestID: byId, setSegmentRule } = require('./helpers'); module.exports = { + '[Users Tests] - Create features': function (browser) { + testHelpers.gotoFeatures(browser); + testHelpers.createFeature(browser, 0, 'flag', true); + testHelpers.createRemoteConfig(browser, 0, 'config', 0); + }, '[Users Tests] - Toggle flag for user': function (browser) { + testHelpers.goToUser(browser, 0); + browser - .pause(200) // Additional wait here as it seems rc-switch can be unresponsive for a while - .click(byId('user-feature-switch-0-on')) + .waitAndClick(byId('user-feature-switch-0-on')) .waitAndClick('#confirm-toggle-feature-btn') .waitForElementNotPresent('#confirm-toggle-feature-modal') - .waitForElementVisible(byId('user-feature-switch-0-on')); + .waitForElementVisible(byId('user-feature-switch-0-off')); }, '[Users Tests] - Edit flag for user': function (browser) { browser + .pause(200) .waitAndClick(byId('user-feature-1')) .waitForElementPresent('#create-feature-modal') .waitForElementVisible('[name="featureValue"]') @@ -26,9 +33,9 @@ module.exports = { '[Users Tests] - Toggle flag for user again': function (browser) { browser .pause(200) // Additional wait here as it seems rc-switch can be unresponsive for a while - .click(byId('user-feature-switch-0-on')) + .click(byId('user-feature-switch-0-off')) .waitAndClick('#confirm-toggle-feature-btn') .waitForElementNotPresent('#confirm-toggle-feature-modal') - .waitForElementVisible(byId('user-feature-switch-0-off')); + .waitForElementVisible(byId('user-feature-switch-0-on')); }, }; diff --git a/web/components/Switch.js b/web/components/Switch.js index 198430cd..b7e40f88 100644 --- a/web/components/Switch.js +++ b/web/components/Switch.js @@ -9,6 +9,23 @@ export default class Switch extends PureComponent { render() { // const { props } = this; + + if (E2E) { + return ( +
+ +
+ ); + } return (
diff --git a/web/project/modals.js b/web/project/modals.js index 6cd838d8..2bd03b65 100644 --- a/web/project/modals.js +++ b/web/project/modals.js @@ -75,7 +75,7 @@ const Modal = class extends React.Component { return (