Skip to content

Add tests for atoms toast templates#77

Merged
brandongregoryscott merged 10 commits into
rsm-hcd:mainfrom
SaidShah:add-tests-for-atoms-toast-templates
Nov 11, 2020
Merged

Add tests for atoms toast templates#77
brandongregoryscott merged 10 commits into
rsm-hcd:mainfrom
SaidShah:add-tests-for-atoms-toast-templates

Conversation

@SaidShah
Copy link
Copy Markdown
Contributor

@SaidShah SaidShah commented Nov 3, 2020

  • Related GitHub issue(s) linked in PR description
  • Destination branch merged, built and tested with your changes
  • Code formatted and follows best practices and patterns
  • Code builds cleanly (no additional warnings or errors)
  • Manually tested
  • Automated tests are passing
  • No decreases in automated test coverage
  • Documentation updated (readme, docs, comments, etc.)
  • Localization: No hard-coded error messages in code files (minimally in string constants)
  • New component and/ or properties? Make sure to update storybook

Closes #34

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 3, 2020

Codecov Report

Merging #77 (8270025) into main (757bd1a) will increase coverage by 8.59%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #77      +/-   ##
==========================================
+ Coverage   25.66%   34.25%   +8.59%     
==========================================
  Files          51       51              
  Lines         900      902       +2     
  Branches      209      209              
==========================================
+ Hits          231      309      +78     
+ Misses        662      591      -71     
+ Partials        7        2       -5     
Impacted Files Coverage Δ
src/atoms/buttons/button.tsx 100.00% <ø> (ø)
src/atoms/forms/input-character-count.tsx 100.00% <ø> (ø)
src/atoms/forms/password-input.tsx 100.00% <ø> (ø)
src/atoms/forms/text-input.tsx 100.00% <ø> (+100.00%) ⬆️
src/atoms/progress-bar/progress-bar.tsx 100.00% <100.00%> (+100.00%) ⬆️
src/molecules/dropdown-button/dropdown-button.tsx 100.00% <100.00%> (+100.00%) ⬆️
src/molecules/form-fields/input-form-field.tsx 100.00% <100.00%> (+31.25%) ⬆️
src/atoms/forms/select.tsx 100.00% <0.00%> (+9.09%) ⬆️
src/molecules/form-fields/checkbox-form-field.tsx 100.00% <0.00%> (+16.66%) ⬆️
... and 8 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 61ffc08...db64719. Read the comment docs.

Copy link
Copy Markdown
Contributor

@brandongregoryscott brandongregoryscott left a comment

Choose a reason for hiding this comment

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

Thanks for filling these in @SaidShah! Left some feedback for breaking up these test suites a bit - I think it should help with future addition or maintenance to the tests as well as readability

Comment thread src/utilities/toast-manager.test.ts Outdated
test.skip("TODO: Backfill tests for issue https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/34", () => {});
test("when error toast created, returns toastId", () => {
// Arrange
const testToastId = faker.random.number(99);
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.

Thought: Being as this is the value we're expecting to be returned from the function under test, this would be a good candidate to be named expected 👍

Comment thread src/utilities/toast-manager.test.ts Outdated

describe("ToastManager", () => {
test.skip("TODO: Backfill tests for issue https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/34", () => {});
test("when error toast created, returns toastId", () => {
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.

We typically wrap each function being tested in its own ts-region block and a describe block. While these sections may only contain one test right now, it's more consistent with the rest of our test suites and will be easier to maintain if additional tests need to be added in here.

In terms of naming sequential tests, it could also reduce some of the boilerplate due to the context:

// -----------------------------------------------------------------------------------------
// #region info
// -----------------------------------------------------------------------------------------

describe("info", () => {
    test("when toastId provided, returns toastId", () => {
        // Arrange
        const expected = faker.random.number(99);
        const toastContent = faker.random.word();
        const toastOptions = { toastId: expected };
    
        // Act
        const toastId = ToastManager.info(toastContent, toastOptions);
    
        // Assert
        expect(toastId).toBe(expected);
    });
})

// #endregion info

I'd recommend a similar change for the toast template tests ☝️

Comment thread src/utilities/toast-manager.test.ts Outdated
// Arrange
const testToastId = faker.random.number(99);
const toastContent = faker.random.word();
const toastOptions = { toastId: testToastId };
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.

It should return an id of the created toast without explicitly passing one in, right? Can we add test(s) for those cases?

Comment thread src/utilities/toast-manager.test.ts Outdated
expect(dismissMethodSpy).toHaveBeenCalled();
});

test("when dismiss All toasts, calls dismissAll method", () => {
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.

The suggested region/describe blocks would probably help with this test name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@brandongregoryscott - Thanks for your feedback. Can you take a second look when you have time.

Copy link
Copy Markdown
Contributor

@brandongregoryscott brandongregoryscott left a comment

Choose a reason for hiding this comment

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

@SaidShah Just a tiny update here and it's all set 👍 Thanks for making those changes!

Comment thread src/utilities/toast-manager.test.ts Outdated

// Assert
expect(dismissAllMethodSpy).toHaveBeenCalled();
describe("dismissAll", () => {
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.

Just one tiny nitpick @SaidShah: could you alphabetize these regions? If the functions in the class are not alphabetized, they should be moved around too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback. I have updated the regions if you want to take another look. 👍

@brandongregoryscott brandongregoryscott merged commit 059eef4 into rsm-hcd:main Nov 11, 2020
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.

Backfill tests for Atoms/ToastManager

3 participants