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

feat(slack): Introduce slack support channel selector #7658

Merged
merged 12 commits into from
Dec 2, 2019

Conversation

caseyhebebrand
Copy link
Contributor

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.

Screen Shot 2019-11-25 at 1 38 48 PM
Screen Shot 2019-11-25 at 1 39 13 PM

Copy link
Contributor

@christopherthielen christopherthielen left a 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

loading: boolean;
}

export default class SlackChannelSelector extends React.Component<
Copy link
Contributor

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??

Copy link
Contributor Author

@caseyhebebrand caseyhebebrand Nov 26, 2019

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.

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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[]) => {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

yarn.lock Outdated Show resolved Hide resolved
halconfig/settings.js Show resolved Hide resolved
Comment on lines +27 to +30
spyOn(SlackReader, 'getChannels').and.callThrough();
spyOn(API, 'one')
.and.callThrough()
.and.returnValue({ getList: () => Promise.resolve(mockSlackChannels) });
Copy link
Contributor Author

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

Copy link
Contributor

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!

Comment on lines +27 to +30
spyOn(SlackReader, 'getChannels').and.callThrough();
spyOn(API, 'one')
.and.callThrough()
.and.returnValue({ getList: () => Promise.resolve(mockSlackChannels) });
Copy link
Contributor

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!

@caseyhebebrand caseyhebebrand merged commit bf2ffe2 into spinnaker:master Dec 2, 2019
@caseyhebebrand caseyhebebrand deleted the slack-support branch December 2, 2019 18:20
afcastano pushed a commit to afcastano/deck that referenced this pull request Dec 4, 2019
* 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
sergiopena pushed a commit to sergiopena/deck that referenced this pull request Jan 10, 2020
* 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
yunzhangit pushed a commit to yunzhangit/deck that referenced this pull request Mar 28, 2021
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants