Skip to content
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

Fix activity test #40

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 54 additions & 178 deletions app/trip/[id]/__test__/mock.ts
Original file line number Diff line number Diff line change
@@ -1,187 +1,63 @@
import { TripDetailsDocument } from '@generated/api'

// activities are created within specific date ranges without spanning across multiple days.
// // activities are created within specific date ranges without spanning across multiple days.
export const tripDetailsMock1 = [
{
request: {
query: TripDetailsDocument,
variables: {
id: 'trip-uuid-1'
}
},
result: {
data: {
tripsCollection: {
edges: [
{
node: {
id: 'trip-uuid-1',
image_url: null,
title: 'Tokyo',
date_from: '2024-01-01T00:00:00+09:00',
date_to: '2024-01-10T00:00:00+09:00',
invitationsCollection: {
edges: [
{
node: {
users: {
id: 'user-id',
profile_picture_url: 'profile-picture-url'
}
}
}
]
},
trip_tagsCollection: {
edges: [
{
node: {
tags: {
id: '1',
name: 'Tag 1'
}
}
}
]
},
activityCollection: {
edges: [
{
node: {
address: 'Shibuya',
time_from: '2024-01-01T10:00:00+09:00',
time_to: '2024-01-01T11:00:00+09:00',
title: 'Activity 1',
id: 'abc1'
}
},
{
node: {
address: 'Asakusa',
time_from: '2024-01-02T10:00:00+09:00',
time_to: '2024-01-02T11:00:00+09:00',
title: 'Activity 2',
id: 'abc2'
}
},
{
node: {
address: 'Shinjuku',
time_from: '2024-01-03T11:00:00+09:00',
time_to: '2024-01-03T12:00:00+09:00',
title: 'Activity 3',
id: 'abc3'
}
},
{
node: {
address: 'Yoyogi',
time_from: '2024-01-03T14:00:00+09:00',
time_to: '2024-01-03T18:00:00+09:00',
title: 'Activity 4',
id: 'abc4'
}
}
]
}
}
}
]
}
}
}
address: 'Shibuya',
time_from: '2024-01-01T10:00:00+09:00',
time_to: '2024-01-01T11:00:00+09:00',
title: 'Activity 1',
id: 'abc1'
},
{
address: 'Asakusa',
time_from: '2024-01-02T10:00:00+09:00',
time_to: '2024-01-02T11:00:00+09:00',
title: 'Activity 2',
id: 'abc2'
},
{
address: 'Shinjuku',
time_from: '2024-01-03T11:00:00+09:00',
time_to: '2024-01-03T12:00:00+09:00',
title: 'Activity 3',
id: 'abc3'
},
{
address: 'Yoyogi',
time_from: '2024-01-03T14:00:00+09:00',
time_to: '2024-01-03T18:00:00+09:00',
title: 'Activity 4',
id: 'abc4'
}
]

// activities are created spanning across multiple days, such as from 2021/1/1 12:00 to 2021/1/2 10:00. and there is an empty date"
// // activities are created spanning across multiple days, such as from 2021/1/1 12:00 to 2021/1/2 10:00. and there is an empty date"
export const tripDetailsMock2 = [
{
request: {
query: TripDetailsDocument,
variables: {
id: 'trip-uuid-2'
}
},
result: {
data: {
tripsCollection: {
edges: [
{
node: {
id: 'trip-uuid-2',
image_url: null,
title: 'Tokyo',
date_from: '2024-01-01T00:00:00+09:00',
date_to: '2024-01-010T00:00:00+09:00',
invitationsCollection: {
edges: [
{
node: {
users: {
id: 'user-id',
profile_picture_url: 'profile-picture-url'
}
}
}
]
},
trip_tagsCollection: {
edges: [
{
node: {
tags: {
id: '1',
name: 'Tag 1'
}
}
}
]
},
activityCollection: {
edges: [
{
node: {
address: 'Shibuya',
time_from: '2021-01-01T10:00:00+09:00',
time_to: '2021-01-01T11:00:00+09:00',
title: 'Activity 1',
id: 'abc1'
}
},
{
node: {
address: 'Asakusa',
time_from: '2021-01-01T12:00:00+09:00',
time_to: '2021-01-03T11:00:00+09:00',
title: 'Activity 2',
id: 'abc2'
}
},
{
node: {
address: 'Shinjuku',
time_from: '2021-01-03T11:00:00+09:00',
time_to: '2021-01-03T12:00:00+09:00',
title: 'Activity 3',
id: 'abc3'
}
},
{
node: {
address: 'Yoyogi',
time_from: '2021-01-03T14:00:00+09:00',
time_to: '2021-01-04T08:00:00+09:00',
title: 'Activity 4',
id: 'abc4'
}
}
]
}
}
}
]
}
}
}
address: 'Shibuya',
time_from: '2021-01-01T10:00:00+09:00',
time_to: '2021-01-01T11:00:00+09:00',
title: 'Activity 1',
id: 'abc1'
},
{
address: 'Asakusa',
time_from: '2021-01-01T12:00:00+09:00',
time_to: '2021-01-03T11:00:00+09:00',
title: 'Activity 2',
id: 'abc2'
},
{
address: 'Shinjuku',
time_from: '2021-01-03T11:00:00+09:00',
time_to: '2021-01-03T12:00:00+09:00',
title: 'Activity 3',
id: 'abc3'
},
{
address: 'Yoyogi',
time_from: '2021-01-03T14:00:00+09:00',
time_to: '2021-01-04T08:00:00+09:00',
title: 'Activity 4',
id: 'abc4'
}
]
66 changes: 48 additions & 18 deletions app/trip/[id]/__test__/trip-details-tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { render, screen } from '@testing-library/react'
import user from '@testing-library/user-event'
import { TripDetailsTabs } from '../components'
import { tripDetailsMock1, tripDetailsMock2 } from './mock'
import {
useDeleteActivityMutation,
useTripsCollectionQuery
} from '@generated/api'

const mockedUseRouter = jest.fn()

Expand All @@ -11,21 +15,38 @@ jest.mock('next/navigation', () => ({
usePathname: jest.fn().mockReturnValue('/some-route')
}))

jest.mock('@apollo/client', () => ({
...jest.requireActual('@apollo/client'),
useQuery: jest.fn(),
useMutation: jest.fn()
}))

jest.mock('../../../../graphql-codegen/generated/api')

describe('TripDetails Tabs', () => {
describe('Activities without spanning across multiple days', () => {
beforeEach(() => {
;(useDeleteActivityMutation as jest.Mock).mockReturnValue([
jest.fn(), // mock mutation function
{ loading: false, error: null } // mock result object
])
;(useTripsCollectionQuery as jest.Mock).mockReturnValue({
refetch: jest.fn(), // mock refetch function
loading: false,
error: null,
data: undefined
})

render(
<TripDetailsTabs
activities={
tripDetailsMock1[0].result.data.tripsCollection.edges[0].node.activityCollection?.edges.map(
(activity) => ({
id: activity.node.id,
timeFrom: activity.node.time_from,
timeTo: activity.node.time_to,
title: activity.node.title,
address: activity.node.address
})
) || []
tripDetailsMock1.map((activity) => ({
id: activity.id,
timeFrom: activity.time_from,
timeTo: activity.time_to,
title: activity.title,
address: activity.address
})) || []
}
/>
)
Expand Down Expand Up @@ -60,18 +81,27 @@ describe('TripDetails Tabs', () => {

describe('Activities spanning across multiple days', () => {
beforeEach(() => {
;(useDeleteActivityMutation as jest.Mock).mockReturnValue([
jest.fn(), // mock mutation function
{ loading: false, error: null } // mock result object
])
;(useTripsCollectionQuery as jest.Mock).mockReturnValue({
refetch: jest.fn(), // mock refetch function
loading: false,
error: null,
data: undefined
})

render(
<TripDetailsTabs
activities={
tripDetailsMock2[0].result.data.tripsCollection.edges[0].node.activityCollection?.edges.map(
(activity) => ({
id: activity.node.id,
timeFrom: activity.node.time_from,
timeTo: activity.node.time_to,
title: activity.node.title,
address: activity.node.address
})
) || []
tripDetailsMock2.map((activity) => ({
id: activity.id,
timeFrom: activity.time_from,
timeTo: activity.time_to,
title: activity.title,
address: activity.address
})) || []
}
/>
)
Expand Down
6 changes: 3 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ const config: Config = {
clearMocks: true,

// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,
collectCoverage: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need coverage


// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,

// The directory where Jest should output its coverage files
coverageDirectory: 'coverage',
// coverageDirectory: 'coverage',

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: 'v8',
// coverageProvider: 'v8',

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
Expand Down
Loading