Skip to content

Commit

Permalink
Add Input Test (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant authored Oct 23, 2023
1 parent 139ab8d commit 3feee84
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
133 changes: 133 additions & 0 deletions cypress/component/integration/Input.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import '../../../src/global.css';
import React from 'react';

Check failure on line 2 in cypress/component/integration/Input.cy.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

'React' is declared but its value is never read.

Check failure on line 2 in cypress/component/integration/Input.cy.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'React' is declared but its value is never read.

Check failure on line 2 in cypress/component/integration/Input.cy.tsx

View workflow job for this annotation

GitHub Actions / build / build (16.x)

'React' is declared but its value is never read.

Check failure on line 2 in cypress/component/integration/Input.cy.tsx

View workflow job for this annotation

GitHub Actions / build / build (18.x)

'React' is declared but its value is never read.

Check failure on line 2 in cypress/component/integration/Input.cy.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

'React' is declared but its value is never read.

Check failure on line 2 in cypress/component/integration/Input.cy.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'React' is declared but its value is never read.
import { Input } from '../../../src/components';
import { compareSnapshot } from '../../compareSnapshot';

describe('Component | Integration | Input', function () {
describe('Input', () => {
describe('regular input with placeholder', () => {
beforeEach(() => {
cy.mount(
<div className="theme-dark">
<Input placeholder={'placeholder'} />
</div>,
);
});

it('should render and have placeholder', () => {
cy.get('[data-testid="input-field"]')
.should('exist')
.and('have.attr', 'placeholder');
});

it('should focus on click', () => {
cy.get('[data-testid="input-field"]').click().should('be.focused');
});

it('should receive typed input', () => {
cy.get('[data-testid="input-field"]')
.type('typed content')
.should('have.value', 'typed content')
.clear()
.should('have.attr', 'placeholder');
});

it('should match snapshot', () => {
compareSnapshot(cy, 'regular-input-with-placeholder');
});
});

describe('regular input with placeholder and error', () => {
beforeEach(() => {
cy.mount(
<div className="theme-dark">
<Input placeholder={'placeholder'} error={'error'} />
</div>,
);
});

it('should render and have placeholder', () => {
cy.get('[data-testid="input-field"]')
.should('exist')
.and('have.attr', 'placeholder');
});

it('should display error message', () => {
cy.get('[data-testid="input-field-message"]').contains('error');
});

it('should match snapshot', () => {
compareSnapshot(cy, 'regular-input-with-placeholder-and-error');
});
});

describe('regular input with content and error', () => {
beforeEach(() => {
cy.mount(
<div className="theme-dark">
<Input
placeholder={'placeholder'}
value={'wrong content'}
error={'error'}
/>
</div>,
);
});

it('should render and have placeholder', () => {
cy.get('[data-testid="input-field"]')
.should('exist')
.and('have.attr', 'placeholder');
});

it('should wrong content displayed', () => {
cy.get('[data-testid="input-field"]')
.should('exist')
.and('have.value', 'wrong content');
});

it('should display error message', () => {
cy.get('[data-testid="input-field-message"]').contains('error');
});

it('should match snapshot', () => {
compareSnapshot(cy, 'regular-input-with-content-and-error');
});
});

describe('regular input with placeholder and warning', () => {
beforeEach(() => {
cy.mount(
<div className="theme-dark">
<Input placeholder={'placeholder'} warning={'warning'} />
</div>,
);
});

it('should render placeholder and warning', () => {
cy.get('[data-testid="input-field"]')
.should('exist')
.and('have.attr', 'placeholder');
cy.get('[data-testid="input-field-message"]').contains('warning');
});

it('should receive typed input and render warning', () => {
cy.get('[data-testid="input-field"]')
.type('typed content')
.should('have.value', 'typed content');
cy.get('[data-testid="input-field-message"]').contains('warning');
});

it('should render warning with no content', () => {
cy.get('[data-testid="input-field"]')
.clear()
.should('have.attr', 'placeholder');

cy.get('[data-testid="input-field-message"]').should('exist');
});
it('should match snapshot', () => {
compareSnapshot(cy, 'regular-input-with-placeholder-and-warning');
});
});
});
});

0 comments on commit 3feee84

Please sign in to comment.