-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
142 additions
and
136 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 |
---|---|---|
@@ -1,137 +1,143 @@ | ||
import { act, fireEvent, render, screen } from '@testing-library/react'; | ||
import { mockGitHubCloudAccount, mockSettings } from '../__mocks__/state-mocks'; | ||
import { AppContext } from '../context/App'; | ||
import { GroupBy } from '../types'; | ||
import { mockGitHubNotifications } from '../utils/api/__mocks__/response-mocks'; | ||
import * as links from '../utils/links'; | ||
import { AccountNotifications } from './AccountNotifications'; | ||
|
||
jest.mock('./RepositoryNotifications', () => ({ | ||
RepositoryNotifications: () => <div>Repository Notifications</div>, | ||
import { act, fireEvent, render, screen } from "@testing-library/react"; | ||
import { mockGitHubCloudAccount, mockSettings } from "../__mocks__/state-mocks"; | ||
import { AppContext } from "../context/App"; | ||
import { GroupBy } from "../types"; | ||
import { mockGitHubNotifications } from "../utils/api/__mocks__/response-mocks"; | ||
import * as links from "../utils/links"; | ||
import { AccountNotifications } from "./AccountNotifications"; | ||
|
||
jest.mock("./RepositoryNotifications", () => ({ | ||
RepositoryNotifications: () => <div>Repository Notifications</div>, | ||
})); | ||
|
||
describe('components/AccountNotifications.tsx', () => { | ||
it('should render itself - group notifications by repositories', () => { | ||
const props = { | ||
account: mockGitHubCloudAccount, | ||
notifications: mockGitHubNotifications, | ||
showAccountHostname: true, | ||
error: null, | ||
}; | ||
|
||
const tree = render( | ||
<AppContext.Provider | ||
value={{ settings: { ...mockSettings, groupBy: GroupBy.REPOSITORY } }} | ||
> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render itself - group notifications by date', () => { | ||
const props = { | ||
account: mockGitHubCloudAccount, | ||
notifications: mockGitHubNotifications, | ||
showAccountHostname: true, | ||
error: null, | ||
}; | ||
|
||
const tree = render( | ||
<AppContext.Provider | ||
value={{ settings: { ...mockSettings, groupBy: GroupBy.DATE } }} | ||
> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render itself - no notifications', () => { | ||
const props = { | ||
account: mockGitHubCloudAccount, | ||
notifications: [], | ||
showAccountHostname: true, | ||
error: null, | ||
}; | ||
|
||
const tree = render( | ||
<AppContext.Provider value={{ settings: mockSettings }}> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render itself - account error', () => { | ||
const props = { | ||
account: mockGitHubCloudAccount, | ||
notifications: [], | ||
error: { | ||
title: 'Error title', | ||
descriptions: ['Error description'], | ||
emojis: ['🔥'], | ||
}, | ||
showAccountHostname: true, | ||
}; | ||
|
||
const tree = render( | ||
<AppContext.Provider value={{ settings: mockSettings }}> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('should open profile when clicked', async () => { | ||
const openAccountProfileMock = jest | ||
.spyOn(links, 'openAccountProfile') | ||
.mockImplementation(); | ||
|
||
const props = { | ||
account: mockGitHubCloudAccount, | ||
notifications: [], | ||
showAccountHostname: true, | ||
error: null, | ||
}; | ||
|
||
await act(async () => { | ||
render( | ||
<AppContext.Provider value={{ settings: mockSettings }}> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
}); | ||
|
||
fireEvent.click(screen.getByTitle('Open Profile')); | ||
|
||
expect(openAccountProfileMock).toHaveBeenCalledTimes(1); | ||
expect(openAccountProfileMock).toHaveBeenCalledWith(mockGitHubCloudAccount); | ||
}); | ||
|
||
it('should toggle account notifications visibility', async () => { | ||
const props = { | ||
account: mockGitHubCloudAccount, | ||
notifications: mockGitHubNotifications, | ||
showAccountHostname: true, | ||
error: null, | ||
}; | ||
|
||
await act(async () => { | ||
render( | ||
<AppContext.Provider value={{ settings: mockSettings }}> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
}); | ||
|
||
fireEvent.click(screen.getByTitle('Hide account notifications')); | ||
|
||
const tree = render( | ||
<AppContext.Provider value={{ settings: mockSettings }}> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
describe("components/AccountNotifications.tsx", () => { | ||
// The read emoji randomly rotates, but then the snapshots would never match | ||
// Have to make it consistent so the emojis are always the same | ||
beforeEach(() => { | ||
global.Math.random = jest.fn(() => 0.1); | ||
}); | ||
|
||
it("should render itself - group notifications by repositories", () => { | ||
const props = { | ||
account: mockGitHubCloudAccount, | ||
notifications: mockGitHubNotifications, | ||
showAccountHostname: true, | ||
error: null, | ||
}; | ||
|
||
const tree = render( | ||
<AppContext.Provider | ||
value={{ settings: { ...mockSettings, groupBy: GroupBy.REPOSITORY } }} | ||
> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it("should render itself - group notifications by date", () => { | ||
const props = { | ||
account: mockGitHubCloudAccount, | ||
notifications: mockGitHubNotifications, | ||
showAccountHostname: true, | ||
error: null, | ||
}; | ||
|
||
const tree = render( | ||
<AppContext.Provider | ||
value={{ settings: { ...mockSettings, groupBy: GroupBy.DATE } }} | ||
> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it("should render itself - no notifications", () => { | ||
const props = { | ||
account: mockGitHubCloudAccount, | ||
notifications: [], | ||
showAccountHostname: true, | ||
error: null, | ||
}; | ||
|
||
const tree = render( | ||
<AppContext.Provider value={{ settings: mockSettings }}> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it("should render itself - account error", () => { | ||
const props = { | ||
account: mockGitHubCloudAccount, | ||
notifications: [], | ||
error: { | ||
title: "Error title", | ||
descriptions: ["Error description"], | ||
emojis: ["🔥"], | ||
}, | ||
showAccountHostname: true, | ||
}; | ||
|
||
const tree = render( | ||
<AppContext.Provider value={{ settings: mockSettings }}> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it("should open profile when clicked", async () => { | ||
const openAccountProfileMock = jest | ||
.spyOn(links, "openAccountProfile") | ||
.mockImplementation(); | ||
|
||
const props = { | ||
account: mockGitHubCloudAccount, | ||
notifications: [], | ||
showAccountHostname: true, | ||
error: null, | ||
}; | ||
|
||
await act(async () => { | ||
render( | ||
<AppContext.Provider value={{ settings: mockSettings }}> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
}); | ||
|
||
fireEvent.click(screen.getByTitle("Open Profile")); | ||
|
||
expect(openAccountProfileMock).toHaveBeenCalledTimes(1); | ||
expect(openAccountProfileMock).toHaveBeenCalledWith(mockGitHubCloudAccount); | ||
}); | ||
|
||
it("should toggle account notifications visibility", async () => { | ||
const props = { | ||
account: mockGitHubCloudAccount, | ||
notifications: mockGitHubNotifications, | ||
showAccountHostname: true, | ||
error: null, | ||
}; | ||
|
||
await act(async () => { | ||
render( | ||
<AppContext.Provider value={{ settings: mockSettings }}> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
}); | ||
|
||
fireEvent.click(screen.getByTitle("Hide account notifications")); | ||
|
||
const tree = render( | ||
<AppContext.Provider value={{ settings: mockSettings }}> | ||
<AccountNotifications {...props} /> | ||
</AppContext.Provider>, | ||
); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
4 changes: 2 additions & 2 deletions
4
src/components/__snapshots__/AccountNotifications.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.