-
Notifications
You must be signed in to change notification settings - Fork 4
Simo6529/wave gallery view #1779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
62c6312
wip
simo6529 250c9d8
wip
simo6529 07e6c27
wip
simo6529 8130cd8
wip
simo6529 325846a
Merge branch 'main' into simo6529/wave-gallery-view
simo6529 1c0c0b7
Merge branch 'main' into simo6529/wave-gallery-view
simo6529 2497242
wip
simo6529 8b72fa2
Merge branch 'main' into simo6529/wave-gallery-view
simo6529 c809aa2
wip
simo6529 685f3b7
Merge branch 'main' into simo6529/wave-gallery-view
simo6529 96100de
wip
simo6529 6b99ef0
wip
simo6529 59ae58e
wip
simo6529 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
57 changes: 36 additions & 21 deletions
57
__tests__/components/brain/my-stream/tabs/MyStreamWaveTabs.test.tsx
This file contains hidden or 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,50 +1,65 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import React from 'react'; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import React from "react"; | ||
|
|
||
| const registerRef = jest.fn(); | ||
|
|
||
| jest.mock('@/components/brain/my-stream/layout/LayoutContext', () => ({ | ||
| jest.mock("@/components/brain/my-stream/layout/LayoutContext", () => ({ | ||
| useLayout: () => ({ registerRef }), | ||
| })); | ||
|
|
||
| jest.mock('@/hooks/useWave', () => ({ | ||
| jest.mock("@/hooks/useWave", () => ({ | ||
| useWave: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('@/components/brain/my-stream/tabs/MyStreamWaveTabsMeme', () => ({ | ||
| jest.mock("@/components/brain/my-stream/tabs/MyStreamWaveTabsMeme", () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="meme" />, | ||
| })); | ||
|
|
||
| jest.mock('@/components/brain/my-stream/tabs/MyStreamWaveTabsDefault', () => ({ | ||
| jest.mock("@/components/brain/my-stream/tabs/MyStreamWaveTabsDefault", () => ({ | ||
| __esModule: true, | ||
| default: () => <div data-testid="default" />, | ||
| })); | ||
|
|
||
| import { MyStreamWaveTabs } from '@/components/brain/my-stream/tabs/MyStreamWaveTabs'; | ||
| import type { ApiWave } from '@/generated/models/ApiWave'; | ||
| const { useWave } = require('@/hooks/useWave'); | ||
| import { MyStreamWaveTabs } from "@/components/brain/my-stream/tabs/MyStreamWaveTabs"; | ||
| import type { ApiWave } from "@/generated/models/ApiWave"; | ||
| const { useWave } = require("@/hooks/useWave"); | ||
|
|
||
| describe('MyStreamWaveTabs', () => { | ||
| const wave: ApiWave = { id: 'w1', name: 'Wave 1' } as ApiWave; | ||
| describe("MyStreamWaveTabs", () => { | ||
| const wave: ApiWave = { id: "w1", name: "Wave 1" } as ApiWave; | ||
| const mockToggleViewMode = jest.fn(); | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('renders meme tabs when wave is a memes wave and registers ref', () => { | ||
| it("renders meme tabs when wave is a memes wave and registers ref", () => { | ||
| (useWave as jest.Mock).mockReturnValue({ isMemesWave: true }); | ||
| render(<MyStreamWaveTabs wave={wave} />); | ||
| const container = document.getElementById('tabs-container'); | ||
| expect(screen.getByTestId('meme')).toBeInTheDocument(); | ||
| expect(screen.queryByTestId('default')).toBeNull(); | ||
| expect(registerRef).toHaveBeenCalledWith('tabs', container); | ||
| render( | ||
| <MyStreamWaveTabs | ||
| wave={wave} | ||
| viewMode="chat" | ||
| onToggleViewMode={mockToggleViewMode} | ||
| showGalleryToggle={false} | ||
| /> | ||
| ); | ||
| const container = document.getElementById("tabs-container"); | ||
| expect(screen.getByTestId("meme")).toBeInTheDocument(); | ||
| expect(screen.queryByTestId("default")).toBeNull(); | ||
| expect(registerRef).toHaveBeenCalledWith("tabs", container); | ||
| }); | ||
|
|
||
| it('renders default tabs when wave is not a memes wave', () => { | ||
| it("renders default tabs when wave is not a memes wave", () => { | ||
| (useWave as jest.Mock).mockReturnValue({ isMemesWave: false }); | ||
| render(<MyStreamWaveTabs wave={wave} />); | ||
| expect(screen.getByTestId('default')).toBeInTheDocument(); | ||
| expect(screen.queryByTestId('meme')).toBeNull(); | ||
| render( | ||
| <MyStreamWaveTabs | ||
| wave={wave} | ||
| viewMode="chat" | ||
| onToggleViewMode={mockToggleViewMode} | ||
| showGalleryToggle={true} | ||
| /> | ||
| ); | ||
| expect(screen.getByTestId("default")).toBeInTheDocument(); | ||
| expect(screen.queryByTestId("meme")).toBeNull(); | ||
| }); | ||
| }); |
66 changes: 40 additions & 26 deletions
66
__tests__/components/brain/my-stream/tabs/MyStreamWaveTabsDefault.test.tsx
This file contains hidden or 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,65 +1,79 @@ | ||
| import { render, screen, fireEvent } from '@testing-library/react'; | ||
| import React from 'react'; | ||
| import MyStreamWaveTabsDefault from '@/components/brain/my-stream/tabs/MyStreamWaveTabsDefault'; | ||
| import { SidebarProvider } from '@/hooks/useSidebarState'; | ||
| import { render, screen, fireEvent } from "@testing-library/react"; | ||
| import React from "react"; | ||
| import MyStreamWaveTabsDefault from "@/components/brain/my-stream/tabs/MyStreamWaveTabsDefault"; | ||
| import { SidebarProvider } from "@/hooks/useSidebarState"; | ||
|
|
||
| const mockPush = jest.fn(); | ||
| const mockUseBreakpoint = jest.fn(() => 'LG'); | ||
| const mockUseBreakpoint = jest.fn(() => "LG"); | ||
|
|
||
| jest.mock('next/navigation', () => ({ | ||
| jest.mock("next/navigation", () => ({ | ||
| useRouter: () => ({ push: mockPush, replace: jest.fn(), back: jest.fn() }), | ||
| useSearchParams: () => new URLSearchParams('wave=w1'), | ||
| usePathname: () => '/waves', | ||
| useSearchParams: () => new URLSearchParams("wave=w1"), | ||
| usePathname: () => "/waves", | ||
| })); | ||
|
|
||
| jest.mock('react-use', () => { | ||
| const actual = jest.requireActual('react-use'); | ||
| jest.mock("react-use", () => { | ||
| const actual = jest.requireActual("react-use"); | ||
| return { | ||
| __esModule: true, | ||
| ...actual, | ||
| createBreakpoint: () => (...args: any[]) => mockUseBreakpoint(...args), | ||
| createBreakpoint: | ||
| () => | ||
| (...args: any[]) => | ||
| mockUseBreakpoint(...args), | ||
| }; | ||
| }); | ||
|
|
||
| const useContentTab = jest.fn(); | ||
|
|
||
| jest.mock('@/components/brain/my-stream/MyStreamWaveDesktopTabs', () => ({ | ||
| jest.mock("@/components/brain/my-stream/MyStreamWaveDesktopTabs", () => ({ | ||
| __esModule: true, | ||
| default: ({ activeTab, setActiveTab }: any) => ( | ||
| <div> | ||
| <span data-testid="active">{activeTab}</span> | ||
| <button onClick={() => setActiveTab('NEW')}>change</button> | ||
| <button onClick={() => setActiveTab("NEW")}>change</button> | ||
| </div> | ||
| ) | ||
| ), | ||
| })); | ||
|
|
||
| jest.mock('@/components/brain/ContentTabContext', () => ({ | ||
| useContentTab: (...args: any[]) => useContentTab(...args) | ||
| jest.mock("@/components/brain/ContentTabContext", () => ({ | ||
| useContentTab: (...args: any[]) => useContentTab(...args), | ||
| })); | ||
|
|
||
| describe('MyStreamWaveTabsDefault', () => { | ||
| describe("MyStreamWaveTabsDefault", () => { | ||
| const mockToggleViewMode = jest.fn(); | ||
|
|
||
| beforeEach(() => { | ||
| mockPush.mockClear(); | ||
| mockUseBreakpoint.mockReturnValue('LG'); | ||
| mockUseBreakpoint.mockReturnValue("LG"); | ||
| useContentTab.mockReset(); | ||
| mockToggleViewMode.mockClear(); | ||
| }); | ||
|
|
||
| it('passes active tab and handles tab change', () => { | ||
| it("passes active tab and handles tab change", () => { | ||
| const setActiveContentTab = jest.fn(); | ||
| useContentTab.mockReturnValue({ activeContentTab: 'CHAT', setActiveContentTab }); | ||
| useContentTab.mockReturnValue({ | ||
| activeContentTab: "CHAT", | ||
| setActiveContentTab, | ||
| }); | ||
| const wave = { | ||
| id: 'w1', | ||
| name: 'Wave', | ||
| id: "w1", | ||
| name: "Wave", | ||
| picture: null, | ||
| contributors_overview: [], | ||
| } as any; | ||
| render( | ||
| <SidebarProvider> | ||
| <MyStreamWaveTabsDefault wave={wave} /> | ||
| <MyStreamWaveTabsDefault | ||
| wave={wave} | ||
| viewMode="chat" | ||
| onToggleViewMode={mockToggleViewMode} | ||
| showGalleryToggle={true} | ||
| /> | ||
| </SidebarProvider> | ||
| ); | ||
| expect(screen.getByTestId('active')).toHaveTextContent('CHAT'); | ||
| fireEvent.click(screen.getByText('change')); | ||
| expect(setActiveContentTab).toHaveBeenCalledWith('NEW'); | ||
| expect(screen.getByTestId("active")).toHaveTextContent("CHAT"); | ||
| fireEvent.click(screen.getByText("change")); | ||
| expect(setActiveContentTab).toHaveBeenCalledWith("NEW"); | ||
| }); | ||
| }); |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.