Skip to content

[BD-29] [TNL-7268] Add high priority tests - #97

Closed
Agrendalath wants to merge 12 commits into
openedx:masterfrom
open-craft:agrendalath/bb-2593-high_priority_tests
Closed

[BD-29] [TNL-7268] Add high priority tests#97
Agrendalath wants to merge 12 commits into
openedx:masterfrom
open-craft:agrendalath/bb-2593-high_priority_tests

Conversation

@Agrendalath

@Agrendalath Agrendalath commented Jun 26, 2020

Copy link
Copy Markdown
Member

This adds tests for:

  • src/courseware/course/sequence/sequence-navigation/SequenceNavigation.jsx
  • src/courseware/course/sequence/sequence-navigation/SequenceNavigationDropdown.jsx
  • src/courseware/course/sequence/sequence-navigation/SequenceNavigationTabs.jsx
  • src/courseware/course/sequence/sequence-navigation/UnitButton.jsx
  • src/courseware/course/sequence/sequence-navigation/UnitNavigation.jsx
  • src/courseware/course/sequence/Unit.jsx
  • src/courseware/course/sequence/Sequence.jsx
  • src/courseware/course/sequence/SequenceContent.jsx

Testing instructions:

  1. Run npm i && npm test.

Reviewers

@openedx-webhooks

openedx-webhooks commented Jun 26, 2020

Copy link
Copy Markdown

Thanks for the pull request, @Agrendalath! I've created BLENDED-394 to keep track of it in Jira. More details are on the BD-29 project page.

When this pull request is ready, tag your edX technical lead.

@openedx-webhooks openedx-webhooks added needs triage open-source-contribution PR author is not from Axim or 2U labels Jun 26, 2020

@pcockwell pcockwell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Agrendalath
I've never come across any of this, so I definitely feel a little out of place with reviews, but ill go back and take a look through some jest documentation before I come back for a full review round. So far this is looking good though. I did notice you have some snapshots that seem unused, and npm test fails, listing those obsolete snapshots as the reason.

 › 5 snapshots obsolete.
   • Unit Navigation displays loading message 1
   • Unit Navigation displays message for no content 1
   • Unit Navigation displays message for the locked content 1
   • Unit Navigation displays messages for the locked content 1
   • Unit Navigation displays messages for the locked content 2

Also, package-lock.json is conflicting

@Agrendalath
Agrendalath force-pushed the agrendalath/bb-2593-high_priority_tests branch from a3c2075 to 01bf231 Compare June 29, 2020 02:21
@Agrendalath Agrendalath changed the title [TNL-7268] WIP: Add high priority tests [TNL-7268] Add high priority tests Jun 29, 2020

@pcockwell pcockwell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Several questions and a few nitpicks, but overall, it looks good. Would like to hear from you regarding the comments though.

Leaving this on Approved (meant to do it with this, review, but messed that up, so it was done separately below) so you can respond and address concerns and not be blocked on me though since none of the comments are blocking.

  • I tested this: ran npm i && npm test and received passing tests
Test Suites: 9 passed, 9 total
Tests:       73 passed, 73 total
Snapshots:   34 passed, 34 total
  • I read through the code

Comment thread src/courseware/course/sequence/Sequence.test.jsx Outdated
Comment thread src/courseware/course/sequence/Sequence.test.jsx Outdated
Comment thread src/courseware/course/sequence/Sequence.test.jsx Outdated
Comment thread src/setupTest.js Outdated

@pcockwell pcockwell left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

  • I tested this: ran tests again
  • I read through the code

@natabene

Copy link
Copy Markdown

@Agrendalath Thank you for your contribution. Please let me know once this is ready for review.

@openedx-webhooks openedx-webhooks added waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. and removed needs triage labels Jun 30, 2020
@davidjoy

Copy link
Copy Markdown
Contributor

It's on me for not getting this note into the TNL-7268 ticket, but I'm wondering if we can focus on specific assertions rather than snapshot tests - the latter are very brittle and difficult to maintain. We should be mindful not to over-assert on implementation/styling details in component tests, which is basically what a snapshot does. Doing so makes it much more likely to break on inconsequential changes.

(Similar comment over here: openedx/frontend-app-authoring#2 (comment))

Making specific assertions also helps with maintainability by signaling intent. It helps us understand what specific things we consider our acceptance criteria - i.e., the sequence nav appears with the right number of buttons. Put another way, these tests shouldn't fail if we add another <div> into the DOM to attach some styling to it.

Let me know what you think - thanks!

@openedx-webhooks openedx-webhooks added changes requested and removed waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Jun 30, 2020
@marcotuts marcotuts changed the title [TNL-7268] Add high priority tests [BD-29] [TNL-7268] Add high priority tests Jul 2, 2020
@davidjoy

davidjoy commented Jul 2, 2020

Copy link
Copy Markdown
Contributor

Note, I just merged https://github.com/edx/frontend-app-learning/pull/102 which does some code organization. I don't expect it should affect these tests too much beyond needing to adjust some imports, perhaps. The contents of the files didn't change for the most part, I just moved some things around. Let me know if you have any issues.

@Agrendalath
Agrendalath force-pushed the agrendalath/bb-2593-high_priority_tests branch from d9d44e1 to 8db73e9 Compare July 9, 2020 01:55
@davidjoy

Copy link
Copy Markdown
Contributor

FYI, I've added some tests for the CoursewareContainer here:

https://github.com/edx/frontend-app-learning/pull/108

As part of that, I used the rosie factories from the data integration tests to set up a redux store, and modified them so that they could allow for multiple units (useful for testing sequence navigation, presumably). Not all components will need the full store, but it was pretty nice being able to set up the store and simply mock the API requests.

I noticed in this PR here there's a bunch of manual set up of redux store states... it might be more resilient to take the approach pioneered in those data int tests. Manually setup stores have a tendency to diverge from what gets set up by actions. (i.e., if someone changes the store, they don't know to go update the manual testing state)

@Agrendalath
Agrendalath force-pushed the agrendalath/bb-2593-high_priority_tests branch from d8bece2 to 09b322a Compare July 15, 2020 20:59
@codecov

codecov Bot commented Jul 15, 2020

Copy link
Copy Markdown

Codecov Report

Merging #97 into master will increase coverage by 8.77%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #97      +/-   ##
==========================================
+ Coverage   53.43%   62.21%   +8.77%     
==========================================
  Files         113      113              
  Lines        1295     1310      +15     
  Branches      258      267       +9     
==========================================
+ Hits          692      815     +123     
+ Misses        581      476     -105     
+ Partials       22       19       -3     
Impacted Files Coverage Δ
...equence/sequence-navigation/SequenceNavigation.jsx 100.00% <100.00%> (+15.38%) ⬆️
...rseware/data/__factories__/courseBlocks.factory.js 100.00% <100.00%> (ø)
...are/data/__factories__/sequenceMetadata.factory.js 70.00% <100.00%> (+12.85%) ⬆️
src/courseware/data/api.js 97.05% <0.00%> (+2.94%) ⬆️
...eware/course/sequence/sequence-navigation/hooks.js 100.00% <0.00%> (+8.33%) ⬆️
src/courseware/data/selectors.js 100.00% <0.00%> (+16.66%) ⬆️
src/courseware/course/sequence/SequenceContent.jsx 100.00% <0.00%> (+16.66%) ⬆️
...course/sequence/sequence-navigation/UnitButton.jsx 100.00% <0.00%> (+30.00%) ⬆️
src/courseware/course/sequence/Sequence.jsx 95.16% <0.00%> (+48.38%) ⬆️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cdab895...7e07bb0. Read the comment docs.

@Agrendalath

Copy link
Copy Markdown
Member Author

@davidjoy, as mentioned on Slack, it totally makes sense to use factories here to have more reliable and consistent approach. I rebased the branch and made some amends (e.g. global.MutationObserver issue for async functions has been fixed after updating dependencies (yay!) and the FontAwesome icon mock turned out to be redundant, as we're not using the snapshot tests eventually).
Given that there's plenty of tests, I'll continue rewriting this tomorrow, as it's still in a WIP state for me.

@Agrendalath

Copy link
Copy Markdown
Member Author

@davidjoy, a quick update: it seems to be a bit more tricky than I expected. For now I'm using something similar to this snippet for providing a generic way to create stores for tests. I'm invoking it this way:

  beforeEach(async () => {
    store = await initializeTestStore();

    const sequence = Object.values(store.getState().models.sequences)[0];
    unit = store.getState().models.units[sequence.unitIds[0]];
    mockData = {
      unitId: unit.id,
      onClick: () => {},
    };
  });

The solution from #108 is very verbose, but if we end up using it for all existing tests, we'll end up with tons of boilerplate code that will make them very hard to read. Currently I'm looking for a way to customize the generated metadata without duplicating too many lines fo code.
What do you think about this?

@davidjoy

Copy link
Copy Markdown
Contributor

I think the above initializeTestStore snippet makes sense. My only caution would be that we try to use it where we need it, and not just have it initialize on all tests whether they need it or not. The test suite isn't going to be massive, but running all that on tests that don't need it feels a bit overkill. :)

We should be able to update the store to put it in specific states by dispatching actions/calling thunks. I added that "buildSimpleCourseBlocks" function to try to reduce some of the boilerplate I was seeing... I think it'd be reasonable for the factories to have helpers like that that abstract away a little of the complexity of modifying the factory build. Because all the factories need to interact in very specific ways, it'd be helpful for future test writers to have some helpers they can use easily.

Long story short, I think adding this setup makes sense.

@Agrendalath
Agrendalath force-pushed the agrendalath/bb-2593-high_priority_tests branch from 5534308 to 7e07bb0 Compare July 23, 2020 14:53
@Agrendalath

Copy link
Copy Markdown
Member Author

@davidjoy, I pushed the refactored version that uses factories and api.js for generating test data. It initializes new store at the beginning of each test with beforeAll (instead of beforeEach, which I was using before). Travis reports that it's working even a bit faster than an approach without factories.

There are some minor changes to be done (e.g. renaming sequence to sequences in courseBlocks factory) related to adding support for courses with multiple sections/sequences/units, but except that it's ready for the review. Please let me know if you have any questions about this approach :)

const courseMetadata = Factory.build('courseMetadata');
const courseId = courseMetadata.id;
const { courseBlocks, unitBlock, sequenceBlock } = buildSimpleCourseBlocks(courseId);
const { courseBlocks, unitBlocks, sequenceBlock } = buildSimpleCourseBlocks(courseId);

@davidjoy davidjoy Jul 29, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like sequenceBlock is expected to come back as an array? But I don't see that the thing being returned from buildSimpleCourseBlocks has an array for sequenceBlock - it's just the block. A bit confused how it's working.

@Agrendalath Agrendalath Jul 29, 2020

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's an array, if the options.sequenceBlock is undefined. I'll reword this to plural to make it less confusing.

Edit: linking the related snippet here, because GitHub doesn't seem to be scrolling to the code from the link for some reason:

const sequenceBlock = options.sequenceBlock || [Factory.build(
  'block',
  { type: 'sequential', children: unitBlocks.map(block => block.id) },
  { courseId },
)];

@openedx-webhooks openedx-webhooks added blended PR is managed through 2U's blended developmnt program and removed open-source-contribution PR author is not from Axim or 2U labels Jul 29, 2020
@davidjoy

davidjoy commented Jul 29, 2020

Copy link
Copy Markdown
Contributor

FYI - I've rebased and merged this into djoy/high_priority_tests so I can merge it with some recent changes I just made to CoursewareContainer.test.jsx that I don't want you to have to deal with. :) I've caused enough conflicts on your work as it is!

If this is successful, I should be able to merge that in shortly.

@davidjoy

Copy link
Copy Markdown
Contributor

Don't worry about resolving these conflicts for the moment - going to give it a shot myself.

@Agrendalath

Copy link
Copy Markdown
Member Author

Cool, thank you for tackling this, @davidjoy!
Btw. there are some options for reducing code duplication in CoursewareContainer.test by reusing the initializeTestStore approach from this PR, though I'm not sure if we want to do this.

@davidjoy

Copy link
Copy Markdown
Contributor

Heyo - so I resolved the merge conflicts here: https://github.com/edx/frontend-app-learning/pull/136

I merged that in, so we're good here! Thanks @Agrendalath! I'm going to close this one. We'll have to make sure the JIRA tickets and all that get resolved properly.

@davidjoy davidjoy closed this Jul 31, 2020
@Agrendalath
Agrendalath deleted the agrendalath/bb-2593-high_priority_tests branch August 3, 2020 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blended PR is managed through 2U's blended developmnt program rejected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants