-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fix and add test for
<ColoredBadgeFormat />
and `<DurationFor…
…mat />` components
- Loading branch information
Showing
4 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ColoredBadgeFormat } from './colored-badge-format' | ||
|
||
describe('<ColoredBadgeFormat />', () => { | ||
it('renders correctly with a value', () => { | ||
cy.mount(<ColoredBadgeFormat value="Test" />) | ||
cy.get('span').should('contain', 'Test') | ||
}) | ||
|
||
it('applies the correct color based on value', () => { | ||
cy.mount(<ColoredBadgeFormat value="Test" />) | ||
|
||
// Have bg-* class | ||
cy.get('span').should('have.css', 'background-color') | ||
// Have text-* class | ||
cy.get('span').should('have.css', 'color') | ||
}) | ||
|
||
it('does not render when value is empty', () => { | ||
cy.mount(<ColoredBadgeFormat value="" />) | ||
cy.get('span').should('not.exist') | ||
}) | ||
|
||
it('does not render when value is null', () => { | ||
cy.mount(<ColoredBadgeFormat value={null} />) | ||
cy.get('span').should('not.exist') | ||
}) | ||
|
||
it('applies additional className', () => { | ||
cy.mount(<ColoredBadgeFormat value="Test" className="extra-class" />) | ||
cy.get('span').should('have.class', 'extra-class') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { DurationFormat } from './duration-format' | ||
|
||
describe('<DurationFormat />', () => { | ||
it('renders 120s correctly', async () => { | ||
cy.mount(<DurationFormat value="120" />) | ||
cy.get('span').should('have.attr', 'title').and('match', /120/) | ||
cy.get('span').should('contain', '2 minutes') | ||
}) | ||
|
||
it('renders 12000s correctly', async () => { | ||
cy.mount(<DurationFormat value="12000" />) | ||
cy.get('span').should('have.attr', 'title').and('match', /12000/) | ||
cy.get('span').should('contain', '3 hours') | ||
}) | ||
|
||
it('renders 0s correctly', async () => { | ||
cy.mount(<DurationFormat value="0" />) | ||
cy.get('span').should('have.attr', 'title').and('match', /0/) | ||
cy.get('span').should('contain', 'a few seconds') | ||
}) | ||
|
||
it('renders -100s correctly', async () => { | ||
cy.mount(<DurationFormat value="-100" />) | ||
cy.get('span').should('contain', '2 minutes ago') | ||
}) | ||
|
||
it('handles invalid value gracefully', async () => { | ||
cy.mount(<DurationFormat value="invalid" />) | ||
cy.get('span') | ||
.should('have.attr', 'title') | ||
.and('match', /invalid/) | ||
cy.get('span').should('contain', 'invalid') | ||
}) | ||
|
||
it('renders with a title attribute', async () => { | ||
const testValue = '300' | ||
cy.mount(<DurationFormat value={testValue} />) | ||
cy.get('span').should('have.attr', 'title', testValue) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters