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

test: Assert Assistant code block #305

Merged
merged 11 commits into from
Jun 26, 2024
Merged

Conversation

dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented Jun 26, 2024

Fixes https://github.com/Automattic/dotcom-forge/issues/7698.

Proposed Changes

Refactor the Assistant code block to a separate file to enable automated tests.
This is required as we currently mock react-markdown due to its ESM-only
build
.

Testing Instructions

N/A, no user-facing changes.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@dcalhoun dcalhoun self-assigned this Jun 26, 2024
@dcalhoun dcalhoun changed the title test: Assert assistant code block test: Assert Assistant code block Jun 26, 2024
Comment on lines -37 to -39
jest.mock( 'strip-ansi', () => ( {
default: jest.fn().mockImplementation( ( str: string ) => str ),
} ) );
Copy link
Member Author

Choose a reason for hiding this comment

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

Relocated to the __mocks__ directory to co-locate third-party mocks and make the mock universal for all tests.

setCliTime( block?.cliTime ?? null );
}
}
}, [ blocks, cliOutput, content, setCliOutput, setCliStatus, setCliTime ] );
Copy link
Member Author

Choose a reason for hiding this comment

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

blocks was added addressing the missing dependency lint warning.

@dcalhoun dcalhoun marked this pull request as ready for review June 26, 2024 03:19
Copy link
Member Author

Choose a reason for hiding this comment

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

I explored enabling Jest's experimental ESM support to remove the react-markdown mock (1264f3a, 3121004, 66f9b14). I was successful getting Jest tests to pass, but encountered errors building/running the app itself. So, I pivoted to relocating this logic instead to enable more straightforward unit tests.

Copy link
Contributor

@fluiddot fluiddot Jun 26, 2024

Choose a reason for hiding this comment

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

I prefer this disposition of having a separated component. Thanks David for making the change 🙇 !

@dcalhoun dcalhoun requested a review from a team June 26, 2024 03:26
Copy link
Contributor

@fluiddot fluiddot left a comment

Choose a reason for hiding this comment

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

LGTM 🎊 !

Copy link
Contributor

@fluiddot fluiddot Jun 26, 2024

Choose a reason for hiding this comment

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

I prefer this disposition of having a separated component. Thanks David for making the change 🙇 !

src/components/tests/assistant-code-block.test.tsx Outdated Show resolved Hide resolved
dcalhoun added 2 commits June 26, 2024 09:50
Replace erroneous copy and paste with the intended test case.
@dcalhoun dcalhoun merged commit 4e8d1b9 into trunk Jun 26, 2024
10 checks passed
@dcalhoun dcalhoun deleted the test/assert-assistant-code-block branch June 26, 2024 14:02
@dcalhoun dcalhoun restored the test/assert-assistant-code-block branch June 26, 2024 14:02
@fluiddot fluiddot deleted the test/assert-assistant-code-block branch June 26, 2024 16:04
fluiddot pushed a commit that referenced this pull request Jun 27, 2024
* refactor: Abstract code block to separate module

Simplify automated testing. We mock `react-markdown` due to its ESM-only
architecture, so this module cannot be tested through the chat message
module.

* test: Assert the code "copy" button

* test: Assert the code "run" button

* test: Assert inline code

* test: Assert the "run" button logic

* test: Assert code "copy" button

* refactor: Relocate manual strip-ansi mock to file-based mock

Co-located third-party manual mocks.

* test: Assert code block displays past execution output

* refactor: Add missing Hook dependency

* refactor: Fix typo

* test: Fix non-wp-cli code assertion

Replace erroneous copy and paste with the intended test case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants