-
Notifications
You must be signed in to change notification settings - Fork 3
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
1847: Activity log tests #1889
base: main
Are you sure you want to change the base?
1847: Activity log tests #1889
Conversation
8263368
to
7a07802
Compare
7a07802
to
2584643
Compare
off-topic but I haven't tested this functionality before, so just wanted to ask now: |
12bad63
to
f0f9d68
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good to me now, thanks!
const { getByTestId } = render(<ActivityLogEntry timestamp={new Date()} card={activityLogCardExample} />) | ||
expect(getByTestId('activity-log-entry-timestamp').textContent).toBe('1/1/2024, 12:00:00 AM') | ||
expect(getByTestId('activity-log-entry-fullname').textContent).toBe('Thea Test') | ||
expect(getByTestId('activity-log-entry-pass-id').textContent).toBe('3132222') | ||
expect(getByTestId('activity-log-entry-birthday').textContent).toBe('01.02.2000') | ||
expect(getByTestId('activity-log-entry-expiry').textContent).toBe('01.01.2026') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Why are you testing with test id? That should only be used as last resort if asserting on anything else is not possible. Same for other tests.
See https://testing-library.com/docs/queries/about/#priority
Hmm I see, testing tables is apparently not that easily possible with react testing library. Found some issue/gists here though which sounds like an okay solution. testing-library/dom-testing-library#583 (comment)
Since setting a test id and then matching that the content is correct basically only tests that some specific text is present as well. This still does not assert that the correct text is rendered in the right column (if eg the table header order changes). Personally, I would therefore prefer to avoid the test id and just assert that some text is rendered.
const { getByTestId } = render(<ActivityLogEntry timestamp={new Date()} card={activityLogCardExample} />) | |
expect(getByTestId('activity-log-entry-timestamp').textContent).toBe('1/1/2024, 12:00:00 AM') | |
expect(getByTestId('activity-log-entry-fullname').textContent).toBe('Thea Test') | |
expect(getByTestId('activity-log-entry-pass-id').textContent).toBe('3132222') | |
expect(getByTestId('activity-log-entry-birthday').textContent).toBe('01.02.2000') | |
expect(getByTestId('activity-log-entry-expiry').textContent).toBe('01.01.2026') | |
expect(getByText('1/1/2024, 12:00:00 AM')).toBeTruthy() | |
expect(getByText('Thea Test')).toBeTruthy() | |
expect(getByText('3132222')).toBeTruthy() | |
expect(getByText('01.02.2000')).toBeTruthy() | |
expect(getByText('01.01.2026')).toBeTruthy() |
const { getByText, getByTestId } = renderWithTranslation( | ||
<ActivityLogTable activityLog={[]} activityLogConfig={nuernbergConfig.activityLogConfig!} /> | ||
) | ||
expect(getByTestId('activity-log-column-names').textContent).toBe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 I think the following would more closely resemble how a user would use the table (and avoid cluttering the code with test ids):
expect(getByTestId('activity-log-column-names').textContent).toBe( | |
expect(queryAllByRole('row')[0].textContent).toBe(nuernbergConfig.activityLogConfig!.columnNames.join('')) |
expect(getByTestId('activity-log-column-names').textContent).toBe( | ||
nuernbergConfig.activityLogConfig!.columnNames.join('') | ||
) | ||
expect(queryByText('Keine Einträge vorhanden')).toBeNull() | ||
expect(getByTestId('activity-log-table-body').children).toHaveLength(2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(getByTestId('activity-log-column-names').textContent).toBe( | |
nuernbergConfig.activityLogConfig!.columnNames.join('') | |
) | |
expect(queryByText('Keine Einträge vorhanden')).toBeNull() | |
expect(getByTestId('activity-log-table-body').children).toHaveLength(2) | |
expect(queryAllByRole('row')[0].textContent).toBe(nuernbergConfig.activityLogConfig!.columnNames.join('')) | |
expect(queryByText('Keine Einträge vorhanden')).toBeNull() | |
expect(queryAllByRole('row')).toHaveLength(3)) |
Short description
Added some tests for the activity log
Proposed changes
ActivityLog.ts
(session storage)ActivityLogTable
to improve testabilitytbody
Side effects
Testing
npm run test
Resolved issues
Fixes: #1847