Skip to content

Commit

Permalink
🚨(frontend) fix CI probs
Browse files Browse the repository at this point in the history
The CI highlighted some issues with the tests.
This commit fixes the issues.
  • Loading branch information
AntoLC committed Apr 3, 2024
1 parent 2c7aa41 commit f1da52d
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/frontend/apps/impress/src/__tests__/pages.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('Page', () => {

expect(
screen.getByRole('button', {
name: /Create a new team/i,
name: /Create a new pad/i,
}),
).toBeInTheDocument();
});
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/apps/impress/src/features/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { ApplicationsMenu } from '@/features/header/ApplicationsMenu';

import { LanguagePicker } from '../language/';

import { default as IconImpress } from './assets/icon-impress.svg?url';
import { default as IconGouv } from './assets/icon-gouv.svg?url';
import { default as IconImpress } from './assets/icon-impress.svg?url';
import { default as IconMarianne } from './assets/icon-marianne.svg?url';
import IconMyAccount from './assets/icon-my-account.png';

Expand Down
15 changes: 14 additions & 1 deletion src/frontend/apps/impress/src/features/pads/pad/types.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
import { Access } from '@/features/members';
import { User } from '@/core/auth';

export interface Access {
id: string;
role: Role;
user: User;
abilities: {
delete: boolean;
get: boolean;
patch: boolean;
put: boolean;
set_role_to: Role[];
};
}

export enum Role {
MEMBER = 'member',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import fetchMock from 'fetch-mock';

import { Panel } from '@/features/teams';
import { AppWrapper } from '@/tests/utils';

import { TeamList } from '../components/PadList';
import { PadList } from '../components/PadList';
import { Panel } from '../components/Panel';

window.HTMLElement.prototype.scroll = function () {};

Expand All @@ -17,30 +17,30 @@ jest.mock('next/router', () => ({
}),
}));

describe('PanelTeams', () => {
describe('PanelPads', () => {
afterEach(() => {
fetchMock.restore();
});

it('renders with no team to display', async () => {
fetchMock.mock(`/api/teams/?page=1&ordering=-created_at`, {
it('renders with no pad to display', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
count: 0,
results: [],
});

render(<TeamList />, { wrapper: AppWrapper });
render(<PadList />, { wrapper: AppWrapper });

expect(screen.getByRole('status')).toBeInTheDocument();

expect(
await screen.findByText(
'Create your first team by clicking on the "Create a new team" button.',
'Create your first pad by clicking on the "Create a new pad" button.',
),
).toBeInTheDocument();
});

it('renders an empty team', async () => {
fetchMock.mock(`/api/teams/?page=1&ordering=-created_at`, {
it('renders an empty pad', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
count: 1,
results: [
{
Expand All @@ -51,17 +51,15 @@ describe('PanelTeams', () => {
],
});

render(<TeamList />, { wrapper: AppWrapper });
render(<PadList />, { wrapper: AppWrapper });

expect(screen.getByRole('status')).toBeInTheDocument();

expect(
await screen.findByLabelText('Empty teams icon'),
).toBeInTheDocument();
expect(await screen.findByLabelText('Empty pads icon')).toBeInTheDocument();
});

it('renders a team with only 1 member', async () => {
fetchMock.mock(`/api/teams/?page=1&ordering=-created_at`, {
it('renders a pad with only 1 member', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
count: 1,
results: [
{
Expand All @@ -77,22 +75,20 @@ describe('PanelTeams', () => {
],
});

render(<TeamList />, { wrapper: AppWrapper });
render(<PadList />, { wrapper: AppWrapper });

expect(screen.getByRole('status')).toBeInTheDocument();

expect(
await screen.findByLabelText('Empty teams icon'),
).toBeInTheDocument();
expect(await screen.findByLabelText('Empty pads icon')).toBeInTheDocument();
});

it('renders a non-empty team', async () => {
fetchMock.mock(`/api/teams/?page=1&ordering=-created_at`, {
it('renders a non-empty pad', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
count: 1,
results: [
{
id: '1',
name: 'Team 1',
name: 'Pad 1',
accesses: [
{
id: '1',
Expand All @@ -107,19 +103,19 @@ describe('PanelTeams', () => {
],
});

render(<TeamList />, { wrapper: AppWrapper });
render(<PadList />, { wrapper: AppWrapper });

expect(screen.getByRole('status')).toBeInTheDocument();

expect(await screen.findByLabelText('Teams icon')).toBeInTheDocument();
expect(await screen.findByLabelText('Pads icon')).toBeInTheDocument();
});

it('renders the error', async () => {
fetchMock.mock(`/api/teams/?page=1&ordering=-created_at`, {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
status: 500,
});

render(<TeamList />, { wrapper: AppWrapper });
render(<PadList />, { wrapper: AppWrapper });

expect(screen.getByRole('status')).toBeInTheDocument();

Expand All @@ -130,23 +126,23 @@ describe('PanelTeams', () => {
).toBeInTheDocument();
});

it('renders with team panel open', async () => {
fetchMock.mock(`/api/teams/?page=1&ordering=-created_at`, {
it('renders with pad panel open', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
count: 1,
results: [],
});

render(<Panel />, { wrapper: AppWrapper });

expect(
screen.getByRole('button', { name: 'Close the teams panel' }),
screen.getByRole('button', { name: 'Close the pads panel' }),
).toBeVisible();

expect(await screen.findByText('Recents')).toBeVisible();
});

it('closes and opens the team panel', async () => {
fetchMock.mock(`/api/teams/?page=1&ordering=-created_at`, {
it('closes and opens the pad panel', async () => {
fetchMock.mock(`/api/pads/?page=1&ordering=-created_at`, {
count: 1,
results: [],
});
Expand All @@ -157,15 +153,15 @@ describe('PanelTeams', () => {

await userEvent.click(
screen.getByRole('button', {
name: 'Close the teams panel',
name: 'Close the pads panel',
}),
);

expect(await screen.findByText('Recents')).not.toBeVisible();

await userEvent.click(
screen.getByRole('button', {
name: 'Open the teams panel',
name: 'Open the pads panel',
}),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const PadItem = ({ pad }: PadItemProps) => {
<Box $align="center" $direction="row" $gap="0.5rem">
{hasMembers ? (
<IconGroup
aria-label={t(`Teams icon`)}
aria-label={t(`Pads icon`)}
color={colorsTokens()['primary-500']}
{...commonProps}
style={{
Expand All @@ -77,7 +77,7 @@ export const PadItem = ({ pad }: PadItemProps) => {
/>
) : (
<IconNone
aria-label={t(`Empty teams icon`)}
aria-label={t(`Empty pads icon`)}
color={colorsTokens()['greyscale-500']}
{...commonProps}
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export const Panel = () => {
transition: ${transition};
`}
$height="inherit"
aria-label="Teams panel"
aria-label="Pads panel"
{...closedOverridingStyles}
>
<BoxButton
aria-label={
isOpen ? t('Close the teams panel') : t('Open the teams panel')
isOpen ? t('Close the pads panel') : t('Open the pads panel')
}
$color={colorsTokens()['primary-600']}
$css={`
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/packages/i18n/__tests__/translations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ describe('checks all the frontend translation are made', () => {
Object.keys(jsonimpress)
.filter((key) => key !== 'en')
.forEach((key) => {
const listKeysimpress = Object.keys(jsonimpress[key].translation).sort();
const listKeysimpress = Object.keys(
jsonimpress[key].translation,
).sort();
const missingKeys = listKeysCrowdin.filter(
(element) => !listKeysimpress.includes(element),
);
Expand Down

0 comments on commit f1da52d

Please sign in to comment.