forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: increase test coverage (nodejs#6122)
* fix: missing `.test` * test: dateIsBetween * test: getNodeApiLink * test: getNodeJsChangelog.test.mjs * test: react-client * build(test): remove `--passWithNotTests`
- Loading branch information
1 parent
a88030e
commit 6eda91b
Showing
10 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,52 @@ | ||
import { render } from '@testing-library/react'; | ||
|
||
import { NotificationProvider } from '@/providers/notificationProvider'; | ||
|
||
import useNotification from '../useNotification'; | ||
|
||
describe('useNotification', () => { | ||
it('should return the notification dispatch function', () => { | ||
// Arrange | ||
const TestComponent = () => { | ||
const notificationDispatch = useNotification(); | ||
return ( | ||
<div> | ||
{notificationDispatch ? 'Dispatch available' : 'Dispatch unavailable'} | ||
</div> | ||
); | ||
}; | ||
|
||
// Act | ||
const { getByText } = render( | ||
<NotificationProvider> | ||
<TestComponent /> | ||
</NotificationProvider> | ||
); | ||
|
||
// Assert | ||
const result = getByText('Dispatch available'); | ||
expect(result).toBeInTheDocument(); | ||
}); | ||
|
||
it('should return null outside NotificationProvider', () => { | ||
// Arrange | ||
const TestComponent = () => { | ||
const notificationDispatch = useNotification(); | ||
return ( | ||
<div> | ||
{notificationDispatch ? 'Dispatch available' : 'Dispatch unavailable'} | ||
</div> | ||
); | ||
}; | ||
|
||
// Act | ||
const { queryByText } = render(<TestComponent />); | ||
|
||
// Assert | ||
const result = queryByText((content, element) => { | ||
return element.textContent === 'Dispatch unavailable'; | ||
}); | ||
|
||
expect(result).toBeNull(); | ||
}); | ||
}); |
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,30 @@ | ||
import { dateIsBetween } from '../dateIsBetween'; | ||
|
||
describe('dateIsBetween', () => { | ||
it('returns true when the current date is between start and end dates', () => { | ||
const startDate = '2022-01-01T00:00:00.000Z'; | ||
const endDate = '2069-01-01T00:00:00.000Z'; | ||
|
||
const result = dateIsBetween(startDate, endDate); | ||
|
||
expect(result).toBe(true); | ||
}); | ||
|
||
it('returns false when the current date is not between start and end dates', () => { | ||
const startDate = '2010-01-01T00:00:00.000Z'; | ||
const endDate = '2020-01-01T00:00:00.000Z'; | ||
|
||
const result = dateIsBetween(startDate, endDate); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
|
||
it('returns false when either start or end date is invalid', () => { | ||
const invalidStartDate = 'Invalid Start Date'; | ||
const validEndDate = '2024-01-01T00:00:00.000Z'; | ||
|
||
const result = dateIsBetween(invalidStartDate, validEndDate); | ||
|
||
expect(result).toBe(false); | ||
}); | ||
}); |
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,39 @@ | ||
import { getNodeApiLink } from '../getNodeApiLink'; | ||
|
||
describe('getNodeApiLink', () => { | ||
it('returns the correct API link for versions >=0.3.1 and <0.5.1', () => { | ||
const version = '0.4.0'; | ||
const expectedLink = `https://nodejs.org/docs/${version}/api/`; | ||
|
||
const result = getNodeApiLink(version); | ||
|
||
expect(result).toBe(expectedLink); | ||
}); | ||
|
||
it('returns the correct API link for versions >=0.1.14 and <0.3.1', () => { | ||
const version = '0.2.0'; | ||
const expectedLink = `https://nodejs.org/docs/${version}/api.html`; | ||
|
||
const result = getNodeApiLink(version); | ||
|
||
expect(result).toBe(expectedLink); | ||
}); | ||
|
||
it('returns the correct API link for versions >=1.0.0 and <4.0.0', () => { | ||
const version = '2.3.0'; | ||
const expectedLink = `https://iojs.org/dist/${version}/docs/api/`; | ||
|
||
const result = getNodeApiLink(version); | ||
|
||
expect(result).toBe(expectedLink); | ||
}); | ||
|
||
it('returns the correct API link for other versions', () => { | ||
const version = '5.0.0'; | ||
const expectedLink = `https://nodejs.org/dist/${version}/docs/api/`; | ||
|
||
const result = getNodeApiLink(version); | ||
|
||
expect(result).toBe(expectedLink); | ||
}); | ||
}); |
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,51 @@ | ||
import { getNodejsChangelog } from '../getNodeJsChangelog'; | ||
|
||
describe('getNodejsChangelog', () => { | ||
it('returns the correct changelog URL for major version >= 4', () => { | ||
const version = '14.2.0'; | ||
const expectedUrl = | ||
'https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V14.md#14.2.0'; | ||
|
||
const result = getNodejsChangelog(version); | ||
|
||
expect(result).toBe(expectedUrl); | ||
}); | ||
|
||
it('returns the correct changelog URL for major version >= 1', () => { | ||
const version = '1.8.3'; | ||
const expectedUrl = | ||
'https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_IOJS.md#1.8.3'; | ||
|
||
const result = getNodejsChangelog(version); | ||
|
||
expect(result).toBe(expectedUrl); | ||
}); | ||
|
||
it('returns the correct changelog URL for minor version 12 or 10', () => { | ||
const version1 = '6.12.0'; | ||
const expectedUrl1 = | ||
'https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V6.md#6.12.0'; | ||
|
||
const result1 = getNodejsChangelog(version1); | ||
|
||
expect(result1).toBe(expectedUrl1); | ||
|
||
const version2 = '8.10.0'; | ||
const expectedUrl2 = | ||
'https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V8.md#8.10.0'; | ||
|
||
const result2 = getNodejsChangelog(version2); | ||
|
||
expect(result2).toBe(expectedUrl2); | ||
}); | ||
|
||
it('returns the correct changelog URL for other versions', () => { | ||
const version = '0.12.7'; | ||
const expectedUrl = | ||
'https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V012.md#0.12.7'; | ||
|
||
const result = getNodejsChangelog(version); | ||
|
||
expect(result).toBe(expectedUrl); | ||
}); | ||
}); |
File renamed without changes.
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