Skip to content

Commit

Permalink
Add Password Test
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Oct 23, 2023
1 parent fc262a0 commit 55191d8
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 73 deletions.
103 changes: 90 additions & 13 deletions cypress/component/integration/Password.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,115 @@
import '../../../src/global.css';
import { Input } from '../../../src/components';
import { Password } from '../../../src/components';
import { compareSnapshot } from '../../compareSnapshot';

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

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

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

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

it('should hide typed input', () => {
cy.get('[data-testid="password-input"]')
.type('typed content')
.should('have.value', 'typed content');
cy.get('[data-testid="password-input"]').should('have.attr', 'type');
cy.get('[data-testid="password-input"]')
.invoke('attr', 'type')
.should('eq', 'password');
});

it('should show typed input', () => {
cy.get('[data-testid="password-input"]')
.type('typed content')
.should('have.value', 'typed content');

cy.get('[data-testid="password-icon"]').should('exist').click();

cy.get('[data-testid="password-input"]')
.invoke('attr', 'type')
.should('eq', 'text');
});

it('should show typed input', () => {
cy.get('[data-testid="password-input"]')
.type('typed content')
.should('have.value', 'typed content');

cy.get('[data-testid="password-icon"]').should('exist').click();

cy.get('[data-testid="password-input"]')
.invoke('attr', 'type')
.should('eq', 'text');
});

it('should match snapshot', () => {
compareSnapshot(cy, 'default-password');
});
});

describe('default password with error', () => {
beforeEach(() => {
cy.mount(
<div className="theme-dark">
<Password error={'error'} />
</div>,
);
});

it('should render', () => {
cy.get('[data-testid="password-input"]').should('exist');
});

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

describe('default password with warning', () => {
beforeEach(() => {
cy.mount(
<div className="theme-dark">
<Password warning={'warning'} />
</div>,
);
});

it('should render', () => {
cy.get('[data-testid="password-input"]').should('exist');
});

it('should display warning message', () => {
cy.get('[data-testid="input-field-message"]')
.should('exist')
.contains('warning');
});
it('should match snapshot', () => {
compareSnapshot(cy, 'regular-input-with-placeholder');
compareSnapshot(cy, 'default-password');
});
});
});
Expand Down
60 changes: 0 additions & 60 deletions src/components/Password/Password.test.tsx

This file was deleted.

0 comments on commit 55191d8

Please sign in to comment.