Skip to content

Commit 24ee341

Browse files
authored
Merge branch 'master' into fix/part1-dependabot/npm_and_yarn/types/lodash-4.14.187
2 parents 30f8c2f + 5ab3189 commit 24ee341

File tree

5 files changed

+387
-114
lines changed

5 files changed

+387
-114
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: init-preview-db
2+
on:
3+
pull_request:
4+
types:
5+
- closed
6+
paths:
7+
- '**.prisma'
8+
jobs:
9+
ssh-and-update-preview-db:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: appleboy/ssh-action@master
13+
with:
14+
host: ${{ secrets.PREVIEW_DB_HOST }}
15+
username: ${{ secrets.PREVIEW_DB_USERNAME }}
16+
password: ${{ secrets.PREVIEW_DB_PW }}
17+
script: |
18+
cd c0d3-app
19+
git pull origin master
20+
yarn --ignore-engines
21+
yarn db:init --force

__tests__/pages/admin/lessons/[lessonSlug]/[pageName]/lessons.test.js

Lines changed: 153 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,20 @@ import dummyAlertData from '../../../../../../__dummy__/alertData'
1010
import getExercisesData from '../../../../../../__dummy__/getExercisesData'
1111
import '@testing-library/jest-dom'
1212
import GET_APP from '../../../../../../graphql/queries/getApp'
13+
import { MODULES } from '../../../../../../graphql/queries/modules'
14+
import { CHALLENGES } from '../../../../../../graphql/queries/challenges'
15+
import ADD_CHALLENGE from '../../../../../../graphql/queries/createChallenge'
1316
import GET_EXERCISES from '../../../../../../graphql/queries/getExercises'
1417
import REMOVE_EXERCISE_FLAG from '../../../../../../graphql/queries/removeExerciseFlag'
1518
import DELETE_EXERCISE from '../../../../../../graphql/queries/deleteExercise'
1619
import { MockedProvider } from '@apollo/client/testing'
17-
import { gql } from '@apollo/client'
1820
import userEvent from '@testing-library/user-event'
1921
import UPDATE_LESSON from '../../../../../../graphql/queries/updateLesson'
2022

2123
// Imported to be able to use expect(...).toBeInTheDocument()
2224
import '@testing-library/jest-dom'
2325
import { AddModuleDocument } from '../../../../../../graphql'
2426

25-
const MODULES = gql`
26-
query {
27-
modules {
28-
id
29-
name
30-
content
31-
lesson {
32-
id
33-
}
34-
order
35-
}
36-
}
37-
`
38-
3927
const modules = [
4028
{
4129
id: 1,
@@ -236,13 +224,44 @@ const unflagExerciseMock = {
236224
}
237225
}
238226

227+
const challenges = dummyLessonData.find(e => e.slug === 'js1').challenges
228+
const challengesQueryMock = {
229+
request: { query: CHALLENGES, variables: {} },
230+
result: {
231+
data: {
232+
challenges
233+
}
234+
}
235+
}
236+
237+
const addChallengeQueryMock = {
238+
request: {
239+
query: ADD_CHALLENGE,
240+
variables: {
241+
content: 'Write an app that delete assets',
242+
lessonId: 2,
243+
name: 'Asset deletion',
244+
order: 1,
245+
description: 'Write an app that delete assets',
246+
title: 'Asset deletion'
247+
}
248+
},
249+
result: {
250+
data: {
251+
createChallenge: dummyLessonData[0]
252+
}
253+
}
254+
}
255+
239256
const mocks = [
240257
getAppQueryMock,
241258
getAppQueryMock,
242259
getAppQueryMock,
243260
modulesQueryMock,
244261
updateLessonMutationMock,
245262
addModuleMock,
263+
challengesQueryMock,
264+
addChallengeQueryMock,
246265
getExercisesMock
247266
]
248267

@@ -251,6 +270,8 @@ const mocksWithError = [
251270
modulesQueryMock,
252271
updateLessonMutationMockWithError,
253272
addModuleMock,
273+
challengesQueryMock,
274+
addChallengeQueryMock,
254275
getExercisesMock
255276
]
256277

@@ -260,7 +281,9 @@ const mocksWithRefetchExercises = [
260281
getAppQueryMock,
261282
getExerciseWithRefetchMock,
262283
deleteExerciseMock,
263-
unflagExerciseMock
284+
unflagExerciseMock,
285+
challengesQueryMock,
286+
addChallengeQueryMock
264287
]
265288

266289
const useRouter = jest.spyOn(require('next/router'), 'useRouter')
@@ -460,6 +483,119 @@ describe('modules', () => {
460483
})
461484
})
462485

486+
describe('challenges', () => {
487+
const useRouterChallenges = {
488+
...useRouterObj,
489+
asPath: 'c0d3.com/admin/lessons/js1/challenges',
490+
query: {
491+
...useRouterObj.query,
492+
pageName: 'challenges'
493+
}
494+
}
495+
496+
beforeAll(() => useRouter.mockImplementation(() => useRouterChallenges))
497+
498+
it('Should render challenges page', async () => {
499+
expect.assertions(1)
500+
501+
render(
502+
<MockedProvider mocks={mocks}>
503+
<LessonPage />
504+
</MockedProvider>
505+
)
506+
507+
// Used to make the queries resolve
508+
await act(() => new Promise(res => setTimeout(res, 0)))
509+
510+
expect(screen.getByText('Incremental Closure')).toBeInTheDocument()
511+
})
512+
513+
it('Should add a challenge', async () => {
514+
expect.assertions(1)
515+
516+
render(
517+
<MockedProvider mocks={mocks}>
518+
<LessonPage />
519+
</MockedProvider>
520+
)
521+
522+
// Used to make the queries resolve
523+
await act(() => new Promise(res => setTimeout(res, 0)))
524+
525+
// Will be changed to ADD NEW CHALLENGE in a subsequent PR
526+
await userEvent.click(screen.getByText('ADD NEW MODULE'))
527+
528+
// Challenge name
529+
await userEvent.type(screen.getByTestId('input0'), 'Asset deletion', {
530+
delay: 1
531+
})
532+
533+
// Challenge description
534+
await userEvent.type(
535+
screen.getByTestId('textbox'),
536+
'Write an app that delete assets',
537+
{
538+
delay: 1
539+
}
540+
)
541+
542+
// Challenge order
543+
await userEvent.type(screen.getByTestId('input2'), '1', {
544+
delay: 1
545+
})
546+
547+
const submit = screen.getByText('ADD CHALLENGE')
548+
549+
await userEvent.click(submit)
550+
551+
expect(
552+
await screen.findByText('Added the item successfully!')
553+
).toBeInTheDocument()
554+
})
555+
556+
it('Should set "add challenge" mode', async () => {
557+
expect.assertions(3)
558+
559+
render(
560+
<MockedProvider mocks={mocks}>
561+
<LessonPage />
562+
</MockedProvider>
563+
)
564+
565+
// Used to make the queries resolve
566+
await act(() => new Promise(res => setTimeout(res, 0)))
567+
568+
// Will be changed to ADD NEW CHALLENGE in a subsequent PR
569+
await userEvent.click(screen.getByText('ADD NEW MODULE'))
570+
571+
expect(screen.getByTestId('input0').value).toBe('')
572+
expect(screen.getByTestId('input2').value).toBe('')
573+
expect(screen.getByTestId('textbox').value).toBe('')
574+
})
575+
576+
it('Should switch to another challenge', async () => {
577+
expect.assertions(2)
578+
579+
render(
580+
<MockedProvider mocks={mocks}>
581+
<LessonPage />
582+
</MockedProvider>
583+
)
584+
585+
// Used to make the queries resolve
586+
await act(() => new Promise(res => setTimeout(res, 0)))
587+
588+
const selectedChallenge = challenges[0]
589+
590+
await userEvent.click(screen.getByText(selectedChallenge.title))
591+
592+
expect(screen.getByTestId('input0').value).toBe(selectedChallenge.title)
593+
expect(screen.getByTestId('textbox').value).toBe(
594+
selectedChallenge.description
595+
)
596+
})
597+
})
598+
463599
describe('introduction', () => {
464600
const useRouterIntroduction = {
465601
...useRouterObj,
@@ -639,7 +775,7 @@ describe('exercises', () => {
639775
expect((await screen.findAllByText('Email')).length).toBe(3)
640776
})
641777

642-
it('Should not render exercises if they are none', async () => {
778+
it('Should not render exercises if they are none flagged', async () => {
643779
expect.assertions(1)
644780

645781
const mocksOfMocks = mocks.slice(0, -1)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@primer/octicons-react": "17.9.0",
3939
"@prisma/client": "4",
4040
"@quixo3/prisma-session-store": "^3.1.10",
41-
"@sentry/nextjs": "^7.18.0",
41+
"@sentry/nextjs": "^7.19.0",
4242
"apollo-server-micro": "^2.26.1",
4343
"apollo3-cache-persist": "^0.14.1",
4444
"bcrypt": "5.0.0",
@@ -127,7 +127,7 @@
127127
"remark-toc": "^8.0.1",
128128
"sass-loader": "^10.2.1",
129129
"storybook-addon-next-router": "^4.0.1",
130-
"svgo": "^3.0.0",
130+
"svgo": "^3.0.1",
131131
"ts-node": "^10.9.1",
132132
"typescript": "^4.7.4"
133133
}

0 commit comments

Comments
 (0)