-
Notifications
You must be signed in to change notification settings - Fork 7
test: add partial challenge tests #1279
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
Open
igorntwari
wants to merge
25
commits into
dev
Choose a base branch
from
test/challenge-card
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
ba5cb3c
test: add partial challenge tests
igorntwari f867447
test: add full challenge tests
igorntwari 6db1bea
Merge branch 'dev' into test/challenge-card
igorntwari 53af166
fix: add missing data-tesid
igorntwari 025a803
fix: rename state variable
igorntwari 098d751
fix: node version
igorntwari aca13f7
fix: renamve node version
igorntwari 1290fea
fix: add clearclearImmediate
igorntwari 4d68ac9
fix: downgrade node version
igorntwari 1a58301
feat: add button test
igorntwari 2584ba8
fix: clearImediate function
igorntwari f982b0d
refactor: remove duplicate mocks
igorntwari 0fca9c8
refactor: remove extra duplicates
igorntwari 25f4082
refactor: remove unnecessary codes
igorntwari c92c11d
test: challenge card
igorntwari c408ff4
Merge branch 'dev' into test/challenge-card
igorntwari 0c24ca0
feat: install need packages
igorntwari dff4c97
feat: add more reliable test
igorntwari eee7016
refactor: remove deleted file
igorntwari c525fba
fix: remove deleted test files
igorntwari f76dfd0
Merge branch 'dev' into test/challenge-card
igorntwari 8a9bdb3
refactor: add proper props naming
igorntwari 27a6acf
refactor: add proper testid and fix linting issues
igorntwari f98e70d
Merge branch 'dev' into test/challenge-card
igorntwari 4adffb1
refactor: add proper type coerciaon
igorntwari 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
igorntwari marked this conversation as resolved.
Show resolved
Hide resolved
|
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { ChallengeCardProps } from "@/components/cards/challenge/Challenge"; | ||
import { mockCertificateData, mockCourse, mockFormat, mockLearningModule, mockRatingCriteria } from "./course"; | ||
import { mockCommunity, mockMetadata } from "./community"; | ||
import { reward } from "./reward"; | ||
import { GRADING_CRITERIA, TEAM_FORMATION } from "@/constants/challengeInfo"; | ||
import { colors } from "./colors"; | ||
|
||
const mockReward = { | ||
id: "123456789", | ||
ref: "ref123", | ||
created_at: new Date("2024-01-29T08:00:00Z"), | ||
updated_at: new Date("2024-01-29T08:30:00Z"), | ||
challenge: "Challenge Name", | ||
type: "SUBMISSION", | ||
community: "Community Name", | ||
token: "Token ID", | ||
stable: true, | ||
amount: 100, | ||
timestamp: 1643424000, | ||
}; | ||
|
||
export const mockChallengeCardProps: ChallengeCardProps = { | ||
data: { | ||
id: "challenge", | ||
ref: "challenge ref", | ||
created_at: new Date("2022-05-01T12:00:00Z"), | ||
updated_at: new Date("2022-05-01T12:00:00Z"), | ||
hint: "Hint", | ||
name: "challenge name", | ||
format: mockFormat, | ||
description: "challenge description", | ||
course: mockCourse, | ||
type: "course", | ||
isTeamChallenge: false, | ||
objectives: ["objectives 1", "Objectives 2", "Objectives 3", "Objectives 4"], | ||
threshold: 8, | ||
community: mockCommunity, | ||
reviewTime: 9, | ||
metadata: mockMetadata, | ||
level: 58, | ||
courses: [mockCourse], | ||
learningModules: [mockLearningModule], | ||
expiresAt: "2025", | ||
reward: reward, | ||
certificateIcon: "certificate", | ||
certificateData: mockCertificateData, | ||
ratingCriteria: [mockRatingCriteria], | ||
timestamp: 6, | ||
maxPoints: 299, | ||
minPoints: 9, | ||
rewards: [reward], | ||
feedbacks: {}, | ||
feedbackInfo: [{}], | ||
bestSubmissions: [{}], | ||
teamLimit: 5, | ||
isHackathon: false, | ||
additionalInfo: { | ||
[TEAM_FORMATION]: { | ||
type: "teamFormation", | ||
text: "Form your team details here", | ||
}, | ||
[GRADING_CRITERIA]: { type: "teamFormation", text: "Sample grading criteria text" }, | ||
}, | ||
}, | ||
community: { | ||
id: "ew-43", | ||
ref: "community/ref", | ||
created_at: new Date("2022-05-01T12:00:00Z"), | ||
updated_at: new Date("2022-05-01T12:00:00Z"), | ||
summary: "this is the summary", | ||
icon: "/public/fav-icons/favicon-16x16.png", | ||
name: "aeternity", | ||
image: "/public/img/Ape_Unit_Logo_White.png", | ||
colors: colors, | ||
slug: "ae", | ||
active: true, | ||
description: "this is a aeternity community", | ||
metadata: mockMetadata, | ||
timestamp: 182044800000, | ||
rewards: [mockReward], | ||
reward: mockReward, | ||
courses: 3, | ||
duration: 4, | ||
can_mint_certificates: true, | ||
challenges: 3, | ||
}, | ||
isCourseEnd: true, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { ConfirmTeamInvitationProps } from "@/components/cards/challenge/ConfirmTeamInvitation"; | ||
import { KYCSTATUS } from "@/store/feature/kyc.slice"; | ||
|
||
|
||
export const mockConfirmTeamInvitation : ConfirmTeamInvitationProps = { | ||
index: 1, | ||
title: "ConfirmTeamInvitation", | ||
text: "welcome to our team", | ||
invite: { | ||
created_at: "2023-20", | ||
id : "2", | ||
ref: "ref-2", | ||
status: "pending", | ||
team_ref: "team-blue", | ||
timestamp:2300, | ||
updated_at: "23h39", | ||
user: { | ||
id: 'user123', | ||
ref: 'ref456', | ||
created_at: new Date('2024-01-01'), | ||
firstName: 'John', | ||
displayName: 'JohnnyDoe', | ||
uid: 'uid789', | ||
joined: '2024-02-14', | ||
disabled: false, | ||
reputation: 100, | ||
username: 'john_doe', | ||
lastName: 'Doe', | ||
emailVerified: true, | ||
email: '[email protected]', | ||
avatar: 'http://example.com/avatar.jpg', | ||
metadata: { | ||
reputation: { | ||
id: 'reputation123', | ||
total: 150, | ||
list: ['communityA', 'communityB'], | ||
community: { | ||
id: 'community123', | ||
ref: 'ref456', | ||
created_at: new Date('2024-01-01'), | ||
updated_at: new Date('2024-01-02'), | ||
summary: 'A brief summary of the community.', | ||
icon: 'http://example.com/icon.png', | ||
name: 'Example Community', | ||
image: 'http://example.com/community-image.jpg', | ||
colors: { | ||
textAccent:"#green", | ||
text:"#green", | ||
accent:"#green", | ||
primary:"#green", | ||
secondary:"#green", | ||
highlight:"#green", | ||
muted:"#green", | ||
cover: { | ||
text: "#red", | ||
accent: "#red", | ||
primary: "#red", | ||
background: "#red", | ||
} | ||
}, | ||
slug: 'example-community', | ||
active: true, | ||
description: 'A detailed description of the community.', | ||
metadata: { | ||
invite_id: 'invite123', | ||
submissions: 5, | ||
bestSubmissions: ['submission1', 'submission2'], | ||
feedbacks: 10, | ||
name: 'Example Certificate', | ||
issuedOn: '2024-01-01', | ||
image: 'http://example.com/certificate-image.jpg', | ||
title: 'Certificate of Achievement', | ||
description: 'A detailed description of the certificate.', | ||
narrative: 'Narrative about the achievement.', | ||
recipientName: 'John Doe', | ||
issuerName: 'Example Organization', | ||
comment: 'Congratulations on your achievement!', | ||
linkToWork: 'http://example.com/work', | ||
team: { | ||
members: ['John Doe', 'Jane Doe'], | ||
name: 'Team Example', | ||
}, | ||
reward: { | ||
id: 'reward123', | ||
name: 'Special Reward', | ||
description: 'A special reward for community members.', | ||
}, | ||
courses: 5, | ||
challenges: 10, | ||
duration: 30, // Duration in days | ||
items: ['item1', 'item2'], // Assuming items can be represented as strings | ||
challenge: { | ||
id: 'challenge1', | ||
title: 'First Challenge', | ||
description: 'Description of the first challenge.', | ||
}, | ||
submission: { | ||
id: 'submission1', | ||
title: 'First Submission', | ||
content: 'Content of the first submission.', | ||
}, | ||
can_mint_certificates: true, | ||
}, | ||
score: 75, | ||
}, | ||
}, | ||
discordConnected: true, | ||
isKycVerified: false, | ||
feedbacks: { | ||
score: 5, | ||
comment: 'Great service!', | ||
}, | ||
discord: { | ||
connected: true, | ||
}, | ||
kycStatus: KYCSTATUS.PENDING, | ||
referrals: [ | ||
{ | ||
referrerId: 'ref123', | ||
referredId: 'ref456', | ||
reward: 50, | ||
}, | ||
], | ||
}, | ||
igorntwari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
user_id: "45", | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { screen } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
import Badges from "@/components/cards/challenge/Badges"; | ||
import { renderWithRedux } from "@__mocks__/renderWithRedux"; | ||
import { challenge } from "@__mocks__/fixtures/challenge"; | ||
|
||
jest.mock("next/router", () => ({ | ||
useRouter: () => ({ | ||
push: jest.fn(), | ||
events: { | ||
on: jest.fn(), | ||
off: jest.fn(), | ||
emit: jest.fn(), | ||
}, | ||
isFallback: false, | ||
pathname: "mocked-pathname", | ||
}), | ||
})); | ||
|
||
describe("Badge-card", () => { | ||
it("should render the level badge in cards", () => { | ||
const levelChallenge = { ...challenge, level: 2, isTeamChallenge: false }; | ||
igorntwari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
renderWithRedux(<Badges challenge={levelChallenge} />); | ||
const badges = screen.getAllByTestId('tag'); | ||
expect(badges.length).toBe(1); | ||
expect(badges[0]).toHaveTextContent('course.challenge.level-2'); | ||
}); | ||
|
||
it("should render the team challenge badge", () => { | ||
const teamChallenge = { ...challenge, level: 0, isTeamChallenge: true, isHackathon: false }; | ||
renderWithRedux(<Badges challenge={teamChallenge} />); | ||
const badges = screen.getAllByTestId('tag'); | ||
expect(badges.length).toBe(1); | ||
expect(badges[0]).toHaveTextContent('Team challenge'); | ||
}); | ||
|
||
it("should render the Hackathon badge", () => { | ||
const hackathonChallenge = { ...challenge, level: 0, isTeamChallenge: true, isHackathon: true }; | ||
renderWithRedux(<Badges challenge={hackathonChallenge} />); | ||
const badges = screen.getAllByTestId('tag'); | ||
expect(badges.length).toBe(1); | ||
expect(badges[0]).toHaveTextContent('Hackathon challenge'); | ||
}); | ||
|
||
it("should render nothing when there is no level or team challenge", () => { | ||
const noChallenge = { ...challenge, level: 0, isTeamChallenge: false }; | ||
renderWithRedux(<Badges challenge={noChallenge} />); | ||
const badges = screen.queryByTestId('tag'); | ||
expect(badges).toBeNull(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import ChallengeCard from "@/components/cards/challenge/Challenge"; | ||
import "@testing-library/jest-dom"; | ||
import { screen } from "@testing-library/react"; | ||
import { renderWithRedux } from "@__mocks__/renderWithRedux"; | ||
import { mockChallengeCardProps } from "@__mocks__/fixtures/challengcard"; | ||
|
||
jest.mock("next/router", () => ({ | ||
useRouter: () => ({ | ||
push: jest.fn(), | ||
events: { | ||
on: jest.fn(), | ||
off: jest.fn(), | ||
emit: jest.fn(), | ||
}, | ||
isFallback: false, | ||
pathname: "mocked-pathname", | ||
}), | ||
})); | ||
|
||
jest.mock("next-i18next", () => ({ | ||
useTranslation: () => ({ | ||
t: (key: string) => { | ||
const translations: { [key: string]: string } = { | ||
"communities.overview.challenge.deadline": "Deadline:", | ||
"communities.overview.challenge.take.challenge": "Take Challenge", | ||
"communities.overview.challenge.see.challenge": "See Challenge", | ||
"communities.overview.challenge.unlock.certificate": "Unlock Certificate", | ||
"communities.overview.challenge.participate": "Participate", | ||
}; | ||
return translations[key] || key; | ||
}, | ||
}), | ||
})); | ||
igorntwari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
describe("ChallengeCard", () => { | ||
it("should render the ChallengeCard", () => { | ||
renderWithRedux(<ChallengeCard {...mockChallengeCardProps} />); | ||
const challengeCard = screen.getByTestId("challenge-card"); | ||
expect(challengeCard).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display the challenge name", () => { | ||
renderWithRedux(<ChallengeCard {...mockChallengeCardProps} />); | ||
const challengeName = screen.getByText(mockChallengeCardProps.data.name); | ||
expect(challengeName).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display the challenge description", () => { | ||
renderWithRedux(<ChallengeCard {...mockChallengeCardProps} />); | ||
const description = screen.getByText(mockChallengeCardProps.data.description); | ||
expect(description).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display the correct number of learning materials", () => { | ||
renderWithRedux(<ChallengeCard {...mockChallengeCardProps} />); | ||
const learningMaterialsText = screen.getByText( | ||
`${mockChallengeCardProps.data.learningModules.length + mockChallengeCardProps.data.courses.length} Learning materials included` | ||
); | ||
expect(learningMaterialsText).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display the reward certificate", () => { | ||
renderWithRedux(<ChallengeCard {...mockChallengeCardProps} />); | ||
const rewardCertificate = screen.getByText("Unlock Certificate"); | ||
expect(rewardCertificate).toBeInTheDocument(); | ||
}); | ||
|
||
it("should link to the correct challenge page", () => { | ||
renderWithRedux(<ChallengeCard {...mockChallengeCardProps} />); | ||
const link = screen.getByRole('link'); | ||
expect(link).toHaveAttribute('href', `/communities/${mockChallengeCardProps.community.slug}/challenges/${mockChallengeCardProps.data.id}`); | ||
}); | ||
}); |
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.