Skip to content

chore: add all missing tests for backstage-plugin-coder #101

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

Merged
merged 12 commits into from
Mar 29, 2024

Conversation

Parkreiner
Copy link
Member

@Parkreiner Parkreiner commented Mar 29, 2024

Closes #8

Changes made

  • Added integration test for CoderWorkspacesCard
    • It basically tests all the sub-components when wired together
  • Filled in stub test for useCoderWorkspacesQuery
  • Updated how mock data was defined, and changed how the MSW handlers were returning data

Notes

There is one more behavior that could use a test, but I'm not sure if it's worth it. Basic steps are:

  1. Log into the Coder deployment with user account 1
  2. Log into Backstage
  3. Get the auth token for user account 1, and insert it
  4. Go back to the Coder deployment, log out, and then log in with user account 2
  5. Expect that the workspaces for user account 1 no longer appear

I was running into this when I was logged into the Full-stack challenge account, but had a token loaded for my personal Coder account. I think there is a way to simulate this at least, but:

  1. I don't know if it's 100% reliable and would give us that much confidence
  2. I don't know if this edge case is too niche to warrant complicating some of the testing setup

@Parkreiner Parkreiner self-assigned this Mar 29, 2024
Comment on lines +109 to +111
<h3 hidden id={formHeaderId}>
Authenticate with Coder
</h3>
Copy link
Member Author

Choose a reason for hiding this comment

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

This was missing from the component before – has two purposes:

  • Increasing accessibility for the overall form
  • Providing another way to hook into the component during testing

Comment on lines 133 to 149
it('Will not show any workspaces at all when the query text is empty', async () => {
await renderWorkspacesCard({ readEntityData: true });

const user = userEvent.setup();
const inputField = await screen.findByRole('searchbox', {
name: /Search your Coder workspaces/i,
});

await user.tripleClick(inputField);
await user.keyboard('[Backspace]');

const emptyState = await screen.findByText(
/Use the search bar to find matching Coder workspaces/,
);

expect(emptyState).toBeInTheDocument();
});
Copy link
Member Author

@Parkreiner Parkreiner Mar 29, 2024

Choose a reason for hiding this comment

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

Hoping we can get rid of this test pretty quickly, but while this behavior is in the codebase, it felt better to assure that it was working reliably

Comment on lines +71 to +72
await waitFor(() => expect(result.current.status).toBe('success'));
expect(result.current.data?.length).toBe(2);
Copy link
Member Author

@Parkreiner Parkreiner Mar 29, 2024

Choose a reason for hiding this comment

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

With the updated test helpers, I don't think the old comment applies anymore

@Parkreiner Parkreiner merged commit f2f0689 into main Mar 29, 2024
@Parkreiner Parkreiner deleted the mes/ws-int-test branch March 29, 2024 19:20
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.

Add tests for main CoderWorkspacesList component
2 participants