-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: update cypress setup - Config cypress to run component tests * feat: show date recency - implement tests for date recency - config update * chore: lockfile * fix: attempt fix failing test - update cypress config - update TypeTweet test file - add window.localStorage
- Loading branch information
Showing
13 changed files
with
1,067 additions
and
794 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
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,13 @@ | ||
import { mount } from 'cypress/react18' | ||
|
||
// Augment the Cypress namespace to include type definitions for | ||
// your custom command. | ||
// Alternatively, can be defined in cypress/support/component.d.ts | ||
// with a <reference path="./component" /> at the top of your spec. | ||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
mount: typeof mount | ||
} | ||
} | ||
} |
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,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0" /> | ||
<title>Components App</title> | ||
</head> | ||
<body> | ||
<div data-cy-root></div> | ||
</body> | ||
</html> |
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,42 @@ | ||
/* eslint-disable @typescript-eslint/no-namespace */ | ||
// *********************************************************** | ||
// This example support/component.ts is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands' | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') | ||
|
||
import { mount } from 'cypress/react18' | ||
// Ensure global app styles are loaded: | ||
import '../../src/index.css' | ||
|
||
// Augment the Cypress namespace to include type definitions for | ||
// your custom command. | ||
// Alternatively, can be defined in cypress/support/component.d.ts | ||
// with a <reference path="./component" /> at the top of your spec. | ||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
mount: typeof mount | ||
} | ||
} | ||
} | ||
|
||
Cypress.Commands.add('mount', mount) | ||
|
||
// Example use: | ||
// cy.mount(<MyComponent />) |
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
126 changes: 126 additions & 0 deletions
126
src/components/App/SideBar/Relevance/Episode/TypeTweet/TypeTweet.cy.tsx
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,126 @@ | ||
import { TypeTweet, Props } from '.' | ||
|
||
function unixTimestampInSeconds() { | ||
return Math.floor(Date.now() / 1000) | ||
} | ||
|
||
describe('TypeTweet', () => { | ||
const currentUnixTimestamp = unixTimestampInSeconds() | ||
|
||
it('should not render when date is false', () => { | ||
const props: Props = { | ||
text: 'Hello, world! This is a test tweet.', | ||
date: 0, | ||
name: 'Test User', | ||
twitterHandle: 'testuser', | ||
verified: false, | ||
} | ||
|
||
cy.mount( | ||
<div style={{ backgroundColor: 'black' }}> | ||
<TypeTweet {...props} /> | ||
</div>, | ||
) | ||
|
||
cy.get('[data-testid="date-text"]').should('not.be.visible') | ||
}) | ||
|
||
it('should display "15 seconds ago"', () => { | ||
const timeValueFromNow = Date.now() - 15 * 1000 | ||
const t = new Date(timeValueFromNow).getTime() / 1000 | ||
|
||
const props: Props = { | ||
text: 'Hello, world! This is a test tweet.', | ||
date: t, | ||
name: 'Test User', | ||
twitterHandle: 'testuser', | ||
verified: false, | ||
} | ||
|
||
cy.mount( | ||
<div style={{ backgroundColor: 'black' }}> | ||
<TypeTweet {...props} /> | ||
</div>, | ||
) | ||
|
||
cy.findByText('15 seconds ago').should('be.visible') | ||
}) | ||
|
||
it('should display "1 minute ago"', () => { | ||
const twoDaysAgo = currentUnixTimestamp - 60 | ||
|
||
const props: Props = { | ||
text: 'Hello, world! This is a test tweet.', | ||
date: twoDaysAgo, | ||
name: 'Test User', | ||
twitterHandle: 'testuser', | ||
verified: false, | ||
} | ||
|
||
cy.mount( | ||
<div style={{ backgroundColor: 'black' }}> | ||
<TypeTweet {...props} /> | ||
</div>, | ||
) | ||
|
||
cy.findByText('1 minute ago').should('be.visible') | ||
}) | ||
|
||
it('should display "25 mins ago"', () => { | ||
const timeFromNow = currentUnixTimestamp - 1500 | ||
|
||
const props: Props = { | ||
text: 'Hello, world! This is a test tweet.', | ||
date: timeFromNow, | ||
name: 'Test User', | ||
twitterHandle: 'testuser', | ||
verified: false, | ||
} | ||
|
||
cy.mount( | ||
<div style={{ backgroundColor: 'black' }}> | ||
<TypeTweet {...props} /> | ||
</div>, | ||
) | ||
}) | ||
|
||
it('should display "1 hour ago"', () => { | ||
const twoDaysAgo = currentUnixTimestamp - 3600 | ||
|
||
const props: Props = { | ||
text: 'Hello, world! This is a test tweet.', | ||
date: twoDaysAgo, | ||
name: 'Test User', | ||
twitterHandle: 'testuser', | ||
verified: false, | ||
} | ||
|
||
cy.mount( | ||
<div style={{ backgroundColor: 'black' }}> | ||
<TypeTweet {...props} /> | ||
</div>, | ||
) | ||
|
||
cy.findByText('1 hour ago').should('be.visible') | ||
}) | ||
|
||
it('should display "23 hours ago"', () => { | ||
const timeValueFromNow = unixTimestampInSeconds() - 82800 | ||
|
||
const props: Props = { | ||
text: 'Hello, world! This is a test tweet.', | ||
date: timeValueFromNow, | ||
name: 'Test User', | ||
twitterHandle: 'testuser', | ||
verified: false, | ||
} | ||
|
||
cy.mount( | ||
<div style={{ backgroundColor: 'black' }}> | ||
<TypeTweet {...props} /> | ||
</div>, | ||
) | ||
|
||
cy.findByText('23 hours ago').should('be.visible') | ||
}) | ||
}) |
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
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
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
Oops, something went wrong.