-
Notifications
You must be signed in to change notification settings - Fork 900
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
feat(slack): Introduce slack support channel selector #7658
feat(slack): Introduce slack support channel selector #7658
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work. Let me know if you want to discuss the testing comment
app/scripts/modules/core/src/application/modal/createApplication.modal.controller.js
Show resolved
Hide resolved
loading: boolean; | ||
} | ||
|
||
export default class SlackChannelSelector extends React.Component< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm curious why you chose to use a class component over a hooks component??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main hesitation was ensuring that the API was only called one time, rather than after each render. I can refactor to a functional component with useEffect
& a second parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you refactor to functional component, use the useData
or useLatestPromise
hook!
<div className="form-group row"> | ||
<div className="col-sm-3 sm-label-right">Slack Channel</div> | ||
<div className="col-sm-9"> | ||
<VirtualizedSelect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be migrated to <ReactSelectInput mode="VIRTUALIZED" />
? I'd like to move towards using a more opinionated set of components across the board.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, did not see this component so I will swap it out.
it('should fetch a list of public Slack channels', () => { | ||
spyOn(SlackReader, 'getChannels').and.returnValue(Promise.resolve(mockSlackChannels)); | ||
|
||
SlackReader.getChannels().then((channels: ISlackChannel[]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test isn't really asserting anything useful. I can replace SlackReader
reference with an empty stub and the test still passes:
it('should fetch a list of public Slack channels', () => {
const foo = { getChannels() {} };
spyOn(foo, 'getChannels').and.returnValue(Promise.resolve(mockSlackChannels));
foo.getChannels().then((channels: any[]) => {
expect(foo.getChannels).toHaveBeenCalled();
expect(channels.length).toEqual(2);
});
});
The only useful thing to assert that I can think of is if API.one
got called with slack/channels
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I will think about this more. I was trying to remove the dependency on the angular mocks. I assumed this would still call the API and on a successful response return the values, while on a failed response the test would fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should be able to do something like:
const oneSpy = spyOn(API as any, 'one').and.callThrough();
const getSpy = spyOn(API as any, 'getFn').and.returnValue(Promise.resolve(mockSlackChannels));
then you should be able to
expect(oneSpy).toHaveBeenCalledWith('slack/channels);
... I think
fc49cfa
to
4993742
Compare
176bc9d
to
4407b73
Compare
spyOn(SlackReader, 'getChannels').and.callThrough(); | ||
spyOn(API, 'one') | ||
.and.callThrough() | ||
.and.returnValue({ getList: () => Promise.resolve(mockSlackChannels) }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@christopherthielen This was the best I could do using callThrough
because I cannot spy on any of the private methods. I think it is valuable enough of a test to show that we have called API
correctly, while still controlling the response.
Another option is to utilize angular mocks like the other services, but I would prefer to reduce the dependency on angular as much as possible.
Another
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that we should avoid using angular mocks in any new code. this looks great to me, thanks for updating it!
spyOn(SlackReader, 'getChannels').and.callThrough(); | ||
spyOn(API, 'one') | ||
.and.callThrough() | ||
.and.returnValue({ getList: () => Promise.resolve(mockSlackChannels) }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that we should avoid using angular mocks in any new code. this looks great to me, thanks for updating it!
* feat(slack): Introduce slack support channel selector * Use ReactSelectInput * Use hooks instead of class compoonent * Disable slack in settings * Add useLatestPromise hook * Rebase with updated react-select modules * Rebase with updated react-select modules * Update test * Update test * Refactor test
* feat(slack): Introduce slack support channel selector * Use ReactSelectInput * Use hooks instead of class compoonent * Disable slack in settings * Add useLatestPromise hook * Rebase with updated react-select modules * Rebase with updated react-select modules * Update test * Update test * Refactor test
* feat(slack): Introduce slack support channel selector * Use ReactSelectInput * Use hooks instead of class compoonent * Disable slack in settings * Add useLatestPromise hook * Rebase with updated react-select modules * Rebase with updated react-select modules * Update test * Update test * Refactor test
A user can select a Slack support channel when creating an application, or editing an application. This will render in Application Attributes as a link to the channel. This is an optional field which is configured by (1) enabling the feature in deck settings and (2) providing a slack token to gate.