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

[#2136] Add Tests for Segment CSS #2137

Merged
merged 20 commits into from
Apr 18, 2024

Conversation

sopa301
Copy link
Contributor

@sopa301 sopa301 commented Feb 22, 2024

Fixes #2136

Proposed commit message

Write Tests for Code Highlighting for Segment

A regression has occurred during refactoring of the Segment component.
It would be good to write tests to catch regressions if it happens
again for this component.

Let's write tests to catch further regressions of the same nature.

Other information

Hex values cannot be used directly because of Cypress limitations. Since we'll need an external library (Chai) for that, I have opted to use rgb values instead.

I chose to suppress warnings for testing the colors of a commit history of _colors.scss instead of using another file because it's a scss file which is unlikely to be touched, while the other files are java files. This may not be so necessary if the below concern is addressed.

Also, it seems that for quite a few tests (including the ones these are derived from), the until date is set to the current date, which can produce regressions like #2111. Additionally, for certain types of tests (like the ones which group a repo's entire commit history), certain assumptions (like the latest author for a line of code) can be broken which may cause the test to break.

The most convenient solution would be to set the until date for relevant tests to a fixed date in the past (like 2021), while the generated report for testing could also be anchored to a past date. Perhaps this should be addressed in another PR so we can avoid more nasty surprises.

@sopa301
Copy link
Contributor Author

sopa301 commented Feb 22, 2024

I've also looked at #1613 suggesting snapshot testing, but I have a few concerns. For example, there may be differences between systems that make snapshots unreliable.

Here's a sample report from dashboard #2137 (The relevant commit history is taken from Jor, testrepo-Delta):
image

And here's the locally built equivalent:
image

Perhaps this points to a deeper bug, but I've opted to stay away from this solution for now. If anyone has an idea of what's causing or how to fix this, do let me know!

.parent() // .line-content
.parent() // .code
.should('have.css', 'background-color')
.and('not.eq', 'rgb(255, 255, 255)') // #ffffff
Copy link
Member

Choose a reason for hiding this comment

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

I think the background color used is always consistently chosen, is it not possible to check for the exact color here instead of checking for not white?

Doing this would make the test case more robust, ensuring the merged group code is highlighted based on author's color and not all just green.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out! I went to look at how the colours are generated (in c-authorship.vue) and it turns out that the first 10 colours are consistently chosen, while the 11th onward is randomly generated. I'll amend the code since we're only testing the first two colours.

@sopa301 sopa301 marked this pull request as ready for review March 3, 2024 15:24
@sopa301 sopa301 requested a review from a team March 3, 2024 15:24
@sopa301 sopa301 requested review from ckcherry23 and removed request for a team March 8, 2024 03:23
@ckcherry23 ckcherry23 requested a review from a team March 9, 2024 12:14
Copy link
Member

@ckcherry23 ckcherry23 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for adding these tests!

Copy link
Contributor

@vvidday vvidday left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for providing context & great job on the comments in the test file describing assumptions & the navigation of parent elements!

@ckcherry23
Copy link
Member

@reposense/active-developers Please help us with a final review for this PR!

Copy link
Contributor

@jonasongg jonasongg left a comment

Choose a reason for hiding this comment

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

LGTM!

@ckcherry23 ckcherry23 merged commit eb13836 into reposense:master Apr 18, 2024
8 checks passed
Copy link
Contributor

The following links are for previewing this pull request:

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.

Test code highlighting in Code Panel
4 participants