Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

MM-12587 Complete migration of job_actions to redux actions #1966

Merged
merged 7 commits into from
Nov 12, 2018

Conversation

sudheerDev
Copy link
Contributor

Summary

Remove job actions from webapp as we can use redux actions for this.

Ticket Link

MM-12587

Checklist

[Place an '[x]' (no spaces) in all applicable fields. Please remove unrelated fields.]

  • Ran make check-style to check for style errors (required for all pull requests)
  • Ran make test to ensure unit and component tests passed
  • Added or updated unit tests (required for all new features)

@sudheerDev sudheerDev added the 2: Dev Review Requires review by a core commiter label Oct 29, 2018
@sudheerDev sudheerDev added this to the v5.6.0 milestone Oct 29, 2018
components/admin_console/jobs/table.jsx Outdated Show resolved Hide resolved
components/admin_console/jobs/table.jsx Outdated Show resolved Hide resolved
@sudheerDev
Copy link
Contributor Author

Waiting for #1999 to rebase

Copy link
Member

@lieut-data lieut-data left a comment

Choose a reason for hiding this comment

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

Two nits for discussion, but otherwise looks good!


actions: PropTypes.shape({

/**
Copy link
Member

Choose a reason for hiding this comment

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

nit: this comment is redundant IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup makes sense. Removed it!

this.reload();
}
);
await this.props.actions.cancelJob(jobId);
Copy link
Member

Choose a reason for hiding this comment

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

So much nicer!

const cancelJob = jest.fn(() => Promise.resolve({}));
const createJob = jest.fn(() => Promise.resolve({}));

beforeEach(() => {
Copy link
Member

Choose a reason for hiding this comment

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

nit: why assign baseProps in beforeEach and not just as a const on line 25?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Usually we assign empty functions on baseProp and mock specific functions in particular tests but that means mocking them multiple times for each test if needed. So instead i am mocking at base prop

The reason why i am doing with beforeEach is because we don't need to worry about test cases if we need to check for instances like toHaveBeenCalledTimes as they are assigned after every test.

I might have went a little overboard. Let me know if you see any downside with this.

Copy link
Member

Choose a reason for hiding this comment

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

I could be mistaken, but I think the values for cancelJob and createJob persist across the tests, since they are only created once anyway -- i.e., you could assert expect(createJob).toHaveBeenCalled(); in your last test and it would be true because it was called in the previous test.

My own preference is to make baseProps const and mock the callbacks of interest locally. IMO, it's easier to reason about mutables when they're "near by". It's perhaps a little verbose, but I think the pattern below works pretty well within each unit test:

const props = {
    ...baseProps,
    actions: {
        ...baseProps.actions,
        cancelJob: jest.fn(() => Promise.resolve({})),
    },
};
// ...
expect(props.actions.cancelJob).toHaveBeenCalled();

Alternatively, you could keep the beforeEach and just make sure to re-create the action callbacks each time. Maybe also inline createJobButtonText and createJobHelpText?

Copy link
Contributor Author

@sudheerDev sudheerDev Nov 6, 2018

Choose a reason for hiding this comment

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

you could assert expect(createJob).toHaveBeenCalled(); in your last test and it would be true because it was called in the previous test.

It was failing if i asserted expect(createJob).toHaveBeenCalled() that in the last test so, i guess both our assumptions are wrong

So, i checked by removing beforeEach and they still work perfectly fine. Just to be sure i copied tests couple of times and the assertions of toHaveBeenCalledTimes(1) works so i guess we don't even need to re-asssign them.

I removed before each and left the mocks at baseProps. I am 1/5 as a personal preference that mocks at base seem more readable as the test has fewer LOC.

Let me know if you have stronger opinion on the readability of mocks in tests i can move them to the tests instead of having them at baseProps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lieut-data ☝️

Copy link
Member

Choose a reason for hiding this comment

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

Aha, looks like package.json configures "clearMocks": true to ensure mocks are reset between tests. That's super useful to know in this context.

At this point, I think my feedback was just subjective, so I've got no more concerns, but I anticipate we may want to iterate on the question of top-level mock functions vs. local ones, as the behaviour here was surprising without the clearMocks context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I anticipate we may want to iterate on the question of top-level mock functions vs. local ones

Sure, i would like to iterate on them too. I need to go back to docs or probably check how other popular projects use jest around to understand few things around mocking. I will get back on this with more info.

Copy link
Member

@saturninoabril saturninoabril left a comment

Choose a reason for hiding this comment

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

LGTM, other than Jesse's comment

const cancelJob = jest.fn(() => Promise.resolve({}));
const createJob = jest.fn(() => Promise.resolve({}));

beforeEach(() => {
Copy link
Member

Choose a reason for hiding this comment

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

I could be mistaken, but I think the values for cancelJob and createJob persist across the tests, since they are only created once anyway -- i.e., you could assert expect(createJob).toHaveBeenCalled(); in your last test and it would be true because it was called in the previous test.

My own preference is to make baseProps const and mock the callbacks of interest locally. IMO, it's easier to reason about mutables when they're "near by". It's perhaps a little verbose, but I think the pattern below works pretty well within each unit test:

const props = {
    ...baseProps,
    actions: {
        ...baseProps.actions,
        cancelJob: jest.fn(() => Promise.resolve({})),
    },
};
// ...
expect(props.actions.cancelJob).toHaveBeenCalled();

Alternatively, you could keep the beforeEach and just make sure to re-create the action callbacks each time. Maybe also inline createJobButtonText and createJobHelpText?

@lieut-data lieut-data self-requested a review November 12, 2018 15:12
@sudheerDev sudheerDev merged commit e243329 into mattermost:master Nov 12, 2018
@sudheerDev sudheerDev deleted the MM-12587 branch November 12, 2018 20:10
@amyblais amyblais added Changelog/Done Required changelog entry has been written Docs/Not Needed Does not require documentation labels Nov 17, 2018
@DHaussermann DHaussermann added the Tests/Done Release tests have been written label Dec 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
2: Dev Review Requires review by a core commiter Changelog/Done Required changelog entry has been written Docs/Not Needed Does not require documentation Tests/Done Release tests have been written
Projects
None yet
5 participants