Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

env config settings is displayed correctly #5879

Merged
merged 13 commits into from
Dec 12, 2019

Conversation

andrew-codes
Copy link
Contributor

@andrew-codes andrew-codes commented Dec 4, 2019

User facing changelog

env configuration option displays properly within the settings panel. Previously, setting env options would incorrectly render "undefined" as the value.

Additional details

The resolved config has metadata around where the value comes from. For example, blacklistHosts's value is an object with a from and value key. The component rendering the config accepts a normal object, so we do not want to include this additional metadata. Prior to passing it along, the resolved config is normalized without the metadata. However, the env value turned out to be a special case; with its value being the actual value instead of a from and value object. Due to this, the process of normalizing the resolved config stripped this out entirely; leaving an undefined value.

Now, the resolved config is processed to strip metadata and then the env key is explicitly added back.

Tests were also added to ensure the existence of env data is rendered properly; both initially, expanded, and with the correct tooltip information.

How has the user experience changed?

Before Screenshot

image

After Screenshot

image
image

PR Tasks

  • Have tests been added/updated?
  • Has the original issue been tagged with a release in ZenHub?

Previously was being dropped as the value of `env` was slightly different from the rest of the resolved config. It did not have an explicit `from`/`value` combo. NormalizeWithoutMeta strips `from`/`value` to simply the value. This is not explictly done for the env key's values.
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 4, 2019

Thanks for the contribution! Below are some guidelines Cypress uses when doing PR reviews.

  • Please write [WIP] in the title of your Pull Request if your PR is not ready for review - someone will review your PR as soon as the [WIP] is removed.
  • Please familiarize yourself with the PR Review Checklist and feel free to make updates on your PR based on these guidelines.

PR Review Checklist

If any of the following requirements can't be met, leave a comment in the review selecting 'Request changes', otherwise 'Approve'.

User Experience

  • The feature/bugfix is self-documenting from within the product.
  • The change provides the end user with a way to fix their problem (no dead ends).

Functionality

  • The code works and performs its intended function with the correct logic.
  • Performance has been factored in (for example, the code cleans up after itself to not cause memory leaks).
  • The code guards against edge cases and invalid input and has tests to cover it.

Maintainability

  • The code is readable (too many nested 'if's are a bad sign).
  • Names used for variables, methods, etc, clearly describe their function.
  • The code is easy to understood and there are relevant comments explaining.
  • New algorithms are documented in the code with link(s) to external docs (flowcharts, w3c, chrome, firefox).
  • There are comments containing link(s) to the addressed issue (in tests and code).

Quality

  • The change does not reimplement code.
  • There's not a module from the ecosystem that should be used instead.
  • There is no redundant or duplicate code.
  • There are no irrelevant comments left in the code.
  • Tests are testing the code’s intended functionality in the best way possible.

Internal

  • The original issue has been tagged with a release in ZenHub.

@cypress
Copy link

cypress bot commented Dec 4, 2019



Test summary

3588 0 47 0


Run details

Project cypress
Status Passed
Commit e1a97a1
Started Dec 12, 2019 9:40 PM
Ended Dec 12, 2019 9:46 PM
Duration 05:32 💡
OS Linux Debian - 9.11
Browser Multiple

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@andrew-codes andrew-codes requested a review from a team December 4, 2019 15:50
Copy link
Member

@jennifer-shehane jennifer-shehane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually tested, looks good - also nests the env vars. 👍 I did not have time to review the code.

Also, just as a note @andrew-codes, in the section for 'How has the user experience changed' it's nice to have a before/after screenshot (after like the one below) demonstrating the fix versus the undefined value before. It's quicker than having to go look at the issue or read all the text explaining.

Screen Shot 2019-12-04 at 10 25 00 PM

@jennifer-shehane jennifer-shehane requested a review from a team December 4, 2019 15:58
@andrew-codes
Copy link
Contributor Author

Let me pull a screenshot of before and after. Thank you for the feedback @jennifer-shehane

@chrisbreiding
Copy link
Contributor

Is this what we want when env is undefined? I feel like it shouldn't be there or should say null or undefined instead of being blank.

Screen Shot 2019-12-05 at 1 39 43 PM

@andrew-codes
Copy link
Contributor Author

Good catch @chrisbreiding. Let me add a test and resolve the issue when there is no env value.

Comment on lines 186 to 233
it('displays env settings', () => {
cy.get('@config').then(({ resolved }) => {
const getEnvKeys = flow([
get('env'),
toPairs,
map(([key]) => key),
sortBy(get('')),
])

cy.contains('.line', 'env').contains(flow([getEnvKeys, join(', ')])(resolved))
cy.contains('.line', 'env').click()
const assertKeyExists = each((key) => cy.contains('.line', key))
const assertKeyValuesExists = flow([
map((key) => {
return flow([
get(['env', key, 'value']),
(v) => {
if (isString(v)) {
return `"${v}"`
}

return v
},
])(resolved)
}),
each((v) => {
cy.contains('.key-value-pair-value', v)
}),
])

const assertFromTooltipsExist = flow([
map((key) => {
return [key,
flow([
get(['env', key, 'from']),
(from) => `.${from}`,
])(resolved)]
}),
each(([key, fromTooltipClassName]) => {
cy.contains(key).parents('.line').first().find(fromTooltipClassName)
}),
])

flow([getEnvKeys, assertKeyExists])(resolved)
flow([getEnvKeys, assertKeyValuesExists])(resolved)
flow([getEnvKeys, assertFromTooltipsExist])(resolved)
})
})
Copy link
Member

@brian-mann brian-mann Dec 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks pretty gnarly, and i think you could use some cypress-isms to clean this up. come find me and i can show you some tricks

Comment on lines 195 to 196
cy.contains('.line', 'env').contains(flow([getEnvKeys, join(', ')])(resolved))
cy.contains('.line', 'env').click()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these lines should go below the const ... = assignments because the execute async.

It's generally better to group the sync/async code together

Copy link
Member

@brian-mann brian-mann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments and since I don't see the test for handling when env is undefined I assume you still need to commit something...

So I'll Request Changes in the mean time so you can address the other feedback.

Comment on lines 194 to 207
this.ipc.openProject.onCall(1).resolves(setConfigEnv(this.config, null))
this.ipc.onConfigChanged.yield()

cy.contains('.line', 'env:null')

this.ipc.openProject.onCall(2).resolves(setConfigEnv(this.config, {}))
this.ipc.onConfigChanged.yield()

cy.contains('.line', 'env:null')

this.ipc.openProject.onCall(3).resolves(setConfigEnv(this.config, undefined))
this.ipc.onConfigChanged.yield()

cy.contains('.line', 'env:null')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't believe you're coordinating the stubs + the cypress commands correctly here because the cypress commands are async and the this.ipc.onConfigChanged.yield() is synchronous. I believe it's synchronously firing the onConfigChanged immediately (three times), and so the final undefined value is being flushed to the DOM, and then the three cy.contains(...) are running only against the last render of the DOM (which is undefined).

To fix this you need to use a .then() so that the IPC events are fired after the cy.contains()

Copy link
Contributor Author

@andrew-codes andrew-codes Dec 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out and going over it with me. Consequently, the implementation passes for each use case, null, undefined, and {}. However, even with the new code changes to the test that we worked on, I get strange behavior. I broke them into 3 separate E2E test cases, but I don't much like it. I'd love it if anyone has any insights on how to combine them into a single test case.

brian-mann and others added 3 commits December 12, 2019 13:02
implementation works individually for each of the three test cases. I don't like breaking them into three separate E2E tests, but I'm unsure how to orchestrate them properly otherwise.
brian-mann
brian-mann previously approved these changes Dec 12, 2019
Copy link
Member

@brian-mann brian-mann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving assuming we get the tests cleaned up a bit and passing

- only a single test; no longer 3 separate tests for the same case
@andrew-codes andrew-codes merged commit 7757252 into develop Dec 12, 2019
@andrew-codes andrew-codes deleted the issue-5859-env-vars-show-undefined branch December 12, 2019 22:01
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 12, 2019

Released in 3.8.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configuration shows env variables as undefined
5 participants