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

4367 filter card #32

Merged
merged 16 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ declare global {
component: React.ReactNode,
options?: MountOptions,
): Cypress.Chainable<MountReturn>;

realHover(): Chainable<Subject>;
}
}
}
12 changes: 6 additions & 6 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// put e2e + CT common commands here

import 'cypress-real-events';
// @ts-expect-error // @see error 2306 https://github.com/microsoft/TypeScript/blob/3fcd1b51a1e6b16d007b368229af03455c7d5794/src/compiler/diagnosticMessages.json#L1635
import registerCypressGrep from '@cypress/grep'
registerCypressGrep()
import registerCypressGrep from '@cypress/grep';
registerCypressGrep();

Cypress.Commands.add('getByCy', (selector, ...args) =>
cy.get(`[data-cy="${selector}"]`, ...args),
)
);

Cypress.Commands.add('getByCyLike', (selector, ...args) =>
cy.get(`[data-cy*=${selector}]`, ...args),
)
);

Cypress.Commands.add('getByClassLike', (selector, ...args) =>
cy.get(`[class*=${selector}]`, ...args),
)
);
4 changes: 2 additions & 2 deletions cypress/support/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const cyGrep = require('@cypress/grep/src/plugin')
const cyGrep = require('@cypress/grep/src/plugin');

/**
* The collection of plugins to use with Cypress
Expand All @@ -13,5 +13,5 @@ export default function plugins(
// add plugins here
// ...cyDataSession(on, config), // example
...cyGrep(config),
}
};
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@typescript-eslint/parser": "6.7.2",
"@vitejs/plugin-react": "4.1.0",
"cypress": "13.2.0",
"cypress-real-events": "^1.10.3",
"eslint": "8.50.0",
"eslint-config-prettier": "9.0.0",
"eslint-config-react-app": "7.0.1",
Expand Down
5 changes: 4 additions & 1 deletion src/assets/db.icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,17 @@ function Save({ fill, width, height }: IconProps) {
);
}

function Arrow({ fill, width, height }: IconProps) {
function Arrow({ fill, width, height, onClick }: IconProps) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width={width}
height={height}
fill="none"
viewBox="0 0 20 20"
onClick={onClick}
className="icon"
data-cy="arrow"
>
<g clipPath="url(#clip0_3054_218)">
<path
Expand Down
2 changes: 1 addition & 1 deletion src/components/BaseCard/BaseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as S from './styles';

const BaseCard = ({ children, ...styleProps }: BaseCardProps) => {
return (
<S.BaseCard {...styleProps} className="base-card">
<S.BaseCard {...styleProps} className="base-card" data-cy="base-card">
{children}
</S.BaseCard>
);
Expand Down
56 changes: 56 additions & 0 deletions src/components/FilterCard/FilterCard.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import FilterCard from './FilterCard';
import GlobalStyle from '@styles/global';

describe('<FilterCard />', () => {
beforeEach(() => {
const filterCardPropsMock = {
filter: 'JavaScript',
onClick: cy.stub().as('onClickMock'),
};

cy.mount(
<>
<GlobalStyle />
<FilterCard {...filterCardPropsMock} />
</>,
);
});

it('should render base card with align-items: center', () => {
cy.getByCy('base-card').should('have.css', 'align-items', 'center');
});

it('should render base card with justify-content: space-between', () => {
cy.getByCy('base-card').should(
'have.css',
'justify-content',
'space-between',
);
});

it('should arrow be cursor pointer when hover it', () => {
cy.getByCy('arrow').realHover();
cy.getByCy('arrow').should('have.css', 'cursor', 'pointer');
});

it('should text container has diplay: flex', () => {
cy.getByCy('text-container').should('have.css', 'display', 'flex');
});

it('should text container has flex-direction: column', () => {
cy.getByCy('text-container').should('have.css', 'flex-direction', 'column');
});

it('should text container has align-items: flex-start', () => {
cy.getByCy('text-container').should(
'have.css',
'align-items',
'flex-start',
);
});

it('should onClick be called when click on arrow', () => {
cy.getByCy('arrow').click();
cy.get('@onClickMock').should('be.called');
});
});
39 changes: 39 additions & 0 deletions src/components/FilterCard/FilterCard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { render, screen } from '@testing-library/react';
import { jest } from '@jest/globals';

import FilterCard from '@components/FilterCard';

const filterCardPropsMock = {
filter: 'JavaScript',
onClick: jest.fn(),
};

describe('<FilterCard />', () => {
beforeEach(() => {
render(<FilterCard {...filterCardPropsMock} />);
});

it('should be defined', () => {
screen.getByTestId('filter-card');
});

it('should render base card', () => {
screen.getByTestId('base-card');
});

it('should render text container', () => {
screen.getByTestId('text-container');
});

it('should render text "Vagas"', () => {
screen.getByText('Vagas');
});

it(`should render text "${filterCardPropsMock.filter}"`, () => {
screen.getByText(filterCardPropsMock.filter);
});

it('should render arrow icon', () => {
screen.getByTestId('arrow');
});
});
26 changes: 26 additions & 0 deletions src/components/FilterCard/FilterCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import BaseCard from '@components/BaseCard';
import Text from '@components/Text';
import { Arrow } from '@assets/db.icons';

import * as S from './styles';

type FilterCardProps = {
filter: string;
onClick: () => void;
};

const FilterCard = ({ filter, onClick }: FilterCardProps) => {
return (
<S.FilterCard className="filter-card" data-cy="filter-card">
<BaseCard padding="xmedium" borderColor="white">
<div className="text-container" data-cy="text-container">
<Text label="Vagas" fontColor="gray" fontSize="xsmall" />
<Text label={filter} fontSize="medium" />
</div>
<Arrow fill="purple-dark" width={24} height={24} onClick={onClick} />
</BaseCard>
</S.FilterCard>
);
};

export default FilterCard;
1 change: 1 addition & 0 deletions src/components/FilterCard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './FilterCard';
18 changes: 18 additions & 0 deletions src/components/FilterCard/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import styled from 'styled-components';

export const FilterCard = styled.div`
.base-card {
align-items: center;
justify-content: space-between;

.icon:hover {
cursor: pointer;
}
}

.text-container {
display: flex;
flex-direction: column;
align-items: flex-start;
}
`;
6 changes: 5 additions & 1 deletion src/components/Text/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import * as S from './styles';

const Text = (props: TextProps) => {
return <S.Text {...props}>{props.label}</S.Text>;
return (
<S.Text {...props} className="text" data-cy="text">
{props.label}
</S.Text>
);
};

export default Text;
2 changes: 1 addition & 1 deletion src/types/BaseCardProps.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type BaseCardProps = {
padding?: 'large' | 'xmedium' | 'small';
borderColor?: 'purple';
borderColor?: 'purple' | 'white';
backgroundColor?: 'purple' | 'white';
children: React.ReactNode;
};
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4518,6 +4518,11 @@ csstype@^3.1.2:
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b"
integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==

cypress-real-events@^1.10.3:
version "1.10.3"
resolved "https://registry.yarnpkg.com/cypress-real-events/-/cypress-real-events-1.10.3.tgz#e2e949ea509cc4306df6c238de1a9982d67360e5"
integrity sha512-YN3fn+CJIAM638sE6uMvv2/n3PsWowdd0rOiN6ZoyezNAMyENfuQHvccLKZpN+apGfQZYetCml6QXLYgDid2fg==

[email protected]:
version "13.2.0"
resolved "https://registry.yarnpkg.com/cypress/-/cypress-13.2.0.tgz#10f73d06a0764764ffbb903a31e96e2118dcfc1d"
Expand Down