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

Add @testing-library/react and component tests #465

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
95 changes: 95 additions & 0 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"@babel/preset-react": "7.10.4",
"@babel/preset-typescript": "7.10.4",
"@babel/runtime": "7.11.2",
"@reduxjs/toolkit": "2.2.1",
"@testing-library/react": "12.1.2",
"@types/react": "16.9.49",
"@types/react-bootstrap": "0.32.29",
"@types/react-custom-scrollbars": "4.0.10",
Expand All @@ -67,7 +69,6 @@
"style-loader": "1.2.1",
"typescript": "4.6.4",
"webpack": "4.44.2",
"webpack-cli": "3.3.12",
"@testing-library/react": "12.1.2"
"webpack-cli": "3.3.12"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,113 @@ exports[`TeamSidebar should render when show is false 1`] = `<div />`;

exports[`TeamSidebar should render when show is true 1`] = `
<div>
<div
data-testid="mocked-sidebar-buttons"
/>
<div>
<a
href="https://gitlab.com"
rel="noopener noreferrer"
style="color: rgba(51, 51, 51, 0.6); display: block; margin-bottom: 10px; width: 100%;"
target="_blank"
>
<i
class="fa fa-gitlab fa-lg"
/>
</a>
<a
style="color: rgba(51, 51, 51, 0.6); display: block; margin-bottom: 10px; width: 100%;"
>
<svg
height="13"
viewBox="0 0 16 16"
width="13"
xmlns="http://www.w3.org/2000/svg"
>
<path
clip-rule="evenodd"
d="M10.34 1.22a.75.75 0 0 0-1.06 0L7.53 2.97 7 3.5l.53.53 1.75 1.75a.75.75 0 1 0 1.06-1.06l-.47-.47h.63c.69 0 1.25.56 1.25 1.25v4.614a2.501 2.501 0 1 0 1.5 0V5.5a2.75 2.75 0 0 0-2.75-2.75h-.63l.47-.47a.75.75 0 0 0 0-1.06ZM13.5 12.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Zm-9 0a1 1 0 1 1-2 0 1 1 0 0 1 2 0Zm1.5 0a2.5 2.5 0 1 1-3.25-2.386V5.886a2.501 2.501 0 1 1 1.5 0v4.228A2.501 2.501 0 0 1 6 12.5Zm-1.5-9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"
fill="rgba(51,51,51,0.6)"
fill-rule="evenodd"
/>
</svg>
<span
style="margin-left: 2px;"
>
0
</span>
</a>
<a
style="color: rgba(51, 51, 51, 0.6); display: block; margin-bottom: 10px; width: 100%;"
>
<svg
height="13"
viewBox="0 0 16 16"
width="13"
xmlns="http://www.w3.org/2000/svg"
>
<path
clip-rule="evenodd"
d="M9 2.5a1 1 0 1 1-2 0 1 1 0 0 1 2 0Zm1.45-.5a2.5 2.5 0 0 0-4.9 0H3a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V3a1 1 0 0 0-1-1h-2.55ZM8 5H5.5V3.5h-2v11h9v-11h-2V5H8ZM5 7.75A.75.75 0 0 1 5.75 7h4.5a.75.75 0 0 1 0 1.5h-4.5A.75.75 0 0 1 5 7.75Zm.75 1.75a.75.75 0 0 0 0 1.5h4.5a.75.75 0 0 0 0-1.5h-4.5Z"
fill="rgba(51,51,51,0.6)"
fill-rule="evenodd"
/>
</svg>
<span
style="margin-left: 2px;"
>
0
</span>
</a>
<a
style="color: rgba(51, 51, 51, 0.6); display: block; margin-bottom: 10px; width: 100%;"
>
<svg
height="13"
viewBox="0 0 16 16"
width="13"
xmlns="http://www.w3.org/2000/svg"
>
<path
clip-rule="evenodd"
d="M3 2.5h6a.5.5 0 0 1 .5.5v10a.5.5 0 0 1-.5.5H3a.5.5 0 0 1-.5-.5V3a.5.5 0 0 1 .5-.5ZM1 3a2 2 0 0 1 2-2h6a2 2 0 0 1 1.97 1.658l2.913 1.516a1.75 1.75 0 0 1 .744 2.36l-3.878 7.45a.753.753 0 0 1-.098.145c-.36.526-.965.871-1.651.871H3a2 2 0 0 1-2-2V3Zm10 7.254 2.297-4.413a.25.25 0 0 0-.106-.337L11 4.364v5.89Z"
fill="rgba(51,51,51,0.6)"
fill-rule="evenodd"
/>
</svg>
<span
style="margin-left: 2px;"
>
0
</span>
</a>
<a
style="color: rgba(51, 51, 51, 0.6); display: block; margin-bottom: 10px; width: 100%;"
>
<svg
height="13"
viewBox="0 0 16 16"
width="13"
xmlns="http://www.w3.org/2000/svg"
>
<path
clip-rule="evenodd"
d="M3 13.5a.5.5 0 0 1-.5-.5V3a.5.5 0 0 1 .5-.5h9.25a.75.75 0 0 0 0-1.5H3a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V9.75a.75.75 0 0 0-1.5 0V13a.5.5 0 0 1-.5.5H3Zm12.78-8.82a.75.75 0 0 0-1.06-1.06L9.162 9.177 7.289 7.241a.75.75 0 1 0-1.078 1.043l2.403 2.484a.75.75 0 0 0 1.07.01L15.78 4.68Z"
fill="rgba(51,51,51,0.6)"
fill-rule="evenodd"
/>
</svg>
<span
style="margin-left: 2px;"
>
0
</span>
</a>
<a
href="#"
style="color: rgba(51, 51, 51, 0.6); display: block; margin-bottom: 10px; width: 100%;"
>
<i
class="fa fa-refresh fa-spin"
/>
</a>
</div>
</div>
`;
46 changes: 37 additions & 9 deletions webapp/src/components/team_sidebar/team_sidebar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React from 'react';

import {describe, expect, test, jest} from '@jest/globals';
import {describe, expect, test} from '@jest/globals';
import {render} from '@testing-library/react';
import {configureStore, createSlice} from '@reduxjs/toolkit';

import {Provider} from 'react-redux';

import TeamSidebar from './team_sidebar';

Expand Down Expand Up @@ -32,18 +35,43 @@ const mockTheme = {
codeTheme: 'solarized-dark',
};

jest.mock('../sidebar_buttons', () => ({
__esModule: true,
default: () => <div data-testid='mocked-sidebar-buttons'/>,
}));
const mockSlice = createSlice({
name: 'mock-reducer',
initialState: {
'plugins-com.github.manland.mattermost-plugin-gitlab': {
connected: true,
username: '',
clientId: '',
lhsData: {
reviews: [],
yourAssignedPrs: [],
yourAssignedIssues: [],
todos: [],
},
gitlabURL: '',
organization: '',
rhsPluginAction: () => true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why clientId is here exposed to the client. That's a bit concerning 😅 At least there's not a clientSecret which would be detrimental

If we are setting connected: true, then I think we should also set username and gitlabURL, since those will always be present when connected is true. No worries if it doesn't change the snapshot I suppose

Copy link
Author

Choose a reason for hiding this comment

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

@mickmister , I have set values to the gitlabURL and username and updated the snapshots.

Kindly take a look at it.

},
entities: {general: {config: {}}},
},
reducers: {},
});

const mockStore = configureStore({
reducer: mockSlice.reducer,
});

describe('TeamSidebar', () => {
test.each([true, false])('should render when show is %s', (show) => {
const {container} = render(
<TeamSidebar
show={show}
theme={mockTheme}
/>);
<Provider store={mockStore}>
<TeamSidebar
show={show}
theme={mockTheme}
/>
</Provider>,
);

expect(container).toMatchSnapshot();
});
});
Loading