Skip to content

Commit

Permalink
Fix build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Gill97 committed Jun 11, 2024
1 parent 91f74c3 commit 1e52be8
Show file tree
Hide file tree
Showing 13 changed files with 483 additions and 130 deletions.
427 changes: 392 additions & 35 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@khanacademy/kas": "github:openstax/raise-kas#7f1de183d58ff9b241a51062c307ea5e9ef0c3fe",
"@types/jest": "^29.5.12",
"bootstrap": "^5.3.3",
"formik": "^2.4.6",
"mathlive": "^0.98.6",
Expand All @@ -38,9 +39,9 @@
"@types/uuid": "^9.0.8",
"@vitejs/plugin-react": "^4.3.0",
"eslint": "^8.57.0",
"eslint-config-love": "^52.0.0",
"eslint-config-standard-with-typescript": "^43.0.1",
"msw": "^2.3.1",
"eslint-config-love": "^52.0.0",
"sass": "^1.76.0",
"stylelint": "^16.5.0",
"stylelint-config-standard": "^36.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/tests/ContentLoader.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { http, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import { render, screen, waitFor } from '@testing-library/react'
import { vi, test, expect } from 'vitest'
import { vi, test, expect, beforeAll, afterEach, afterAll } from 'vitest'

import { ContentLoader } from '../components/ContentLoader'

Expand Down
2 changes: 1 addition & 1 deletion src/tests/DropdownProblem.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fireEvent, render, screen, act } from '@testing-library/react'
import { DropdownProblem, buildClassName } from '../components/DropdownProblem'
import { vi, test } from 'vitest'
import { vi, test, expect} from 'vitest'


test('DropdownProblem renders with contentId', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/MoodleApi.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MoodleApi } from '../moodleapi'
import { setupServer } from 'msw/node'
import { http, HttpResponse } from 'msw'
import { vi, test, expect } from 'vitest'
import { vi, test, expect, beforeAll, afterEach, afterAll} from 'vitest'

const server = setupServer(
http.post('http://moodle/lib/ajax/service.php', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/ProblemSetBlock.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen, fireEvent, act } from '@testing-library/react'
import { OS_RAISE_IB_EVENT_PREFIX, parseProblemSetBlock } from '../lib/blocks'
import { vi, test, expect } from 'vitest'
import { vi, test, expect, afterEach } from 'vitest'

import {
type BaseProblemProps,
Expand Down
2 changes: 1 addition & 1 deletion src/tests/SearchBlock.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, fireEvent, render, screen } from '@testing-library/react'
import { SearchBlock } from '../components/SearchBlock'
import { vi, describe, expect } from 'vitest'
import { vi, describe, expect, it } from 'vitest'

const mockStudentAndTeacherQueryResults = {
hits: {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/TooltipBlock.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import { TooltipBlock } from '../components/TooltipBlock'
import { mathifyElement } from '../lib/math'
import { vi, test } from 'vitest'
import { vi, test, expect } from 'vitest'

vi.mock('../lib/math.ts', () => ({
mathifyElement: vi.fn(async () => {})
Expand Down
2 changes: 1 addition & 1 deletion src/tests/UserInputBlock.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen, fireEvent, act } from '@testing-library/react'
import { UserInputBlock, MAX_CHARACTER_INPUT_BLOCK_LENGTH } from '../components/UserInputBlock'
import { parseUserInputBlock, OS_RAISE_IB_EVENT_PREFIX } from '../lib/blocks'
import { vi, test, expect } from 'vitest'
import { vi, test, expect, afterEach } from 'vitest'

import { ContentLoadedContext } from '../lib/contexts'
import { queueIbInputSubmittedV1Event } from '../lib/events'
Expand Down
2 changes: 1 addition & 1 deletion src/tests/content.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getVersionId } from '../lib/utils'
import { vi, test, expect } from 'vitest'
import { vi, test, expect, beforeEach, afterEach} from 'vitest'
vi.mock('../lib/env.ts', () => ({
default: {}
}))
Expand Down
160 changes: 80 additions & 80 deletions src/tests/events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
queueIbInputSubmittedV1Event
} from '../lib/events'
import { validate } from 'uuid'
import { vi } from 'vitest'
import { vi, beforeAll, afterAll, afterEach, test, expect } from 'vitest'
const server = setupServer(
http.post('http://localhost:8888/v1/events', () => {
return HttpResponse.json({
Expand Down Expand Up @@ -51,7 +51,7 @@ async function waitForRequest(method: string, url: string): Promise<Request> {

vi.mock('../lib/env.ts', () => ({
ENV: {
OS_RAISE_EVENTSAPI_URL_MAP: { localhost: 'http://localhost:8888' },
OS_RAISE_EVENTSAPI_URL_MAP: { 'localhost:3000': 'http://localhost:8888' },
EVENT_FLUSH_PERIOD: 1
}
}))
Expand Down Expand Up @@ -82,85 +82,85 @@ test('Simultaneous requests result in a single EventManager instance', async ()
expect(jsonData.length).toBe(2)
})

// test('Test queueContentLoadedV1Event', async () => {
// const pendingRequest = waitForRequest('POST', 'http://localhost:8888/v1/events')
// await queueContentLoadedV1Event(1, '1234', 'main')
// const req = await pendingRequest
// const jsonData = await req.json()
// expect(jsonData[0].content_id).toBe('1234')
// expect(jsonData[0].eventname).toBe('content_loaded_v1')
// expect(jsonData[0].variant).toBe('main')
// expect(validate(jsonData[0].impression_id as string)).toBe(true)
// expect(jsonData[0].course_id).toBe(1)
// })
test('Test queueContentLoadedV1Event', async () => {
const pendingRequest = waitForRequest('POST', 'http://localhost:8888/v1/events')
await queueContentLoadedV1Event(1, '1234', 'main')
const req = await pendingRequest
const jsonData = await req.json()
expect(jsonData[0].content_id).toBe('1234')
expect(jsonData[0].eventname).toBe('content_loaded_v1')
expect(jsonData[0].variant).toBe('main')
expect(validate(jsonData[0].impression_id as string)).toBe(true)
expect(jsonData[0].course_id).toBe(1)
})

// test('Test queueContentLoadFailedV1Event', async () => {
// const pendingRequest = waitForRequest('POST', 'http://localhost:8888/v1/events')
// await queueContentLoadFailedV1Event(1, '1234', 'error')
// const req = await pendingRequest
// const jsonData = await req.json()
// expect(jsonData[0].content_id).toBe('1234')
// expect(jsonData[0].eventname).toBe('content_load_failed_v1')
// expect(jsonData[0].error).toBe('error')
// expect(validate(jsonData[0].impression_id as string)).toBe(true)
// expect(jsonData[0].course_id).toBe(1)
// })
test('Test queueContentLoadFailedV1Event', async () => {
const pendingRequest = waitForRequest('POST', 'http://localhost:8888/v1/events')
await queueContentLoadFailedV1Event(1, '1234', 'error')
const req = await pendingRequest
const jsonData = await req.json()
expect(jsonData[0].content_id).toBe('1234')
expect(jsonData[0].eventname).toBe('content_load_failed_v1')
expect(jsonData[0].error).toBe('error')
expect(validate(jsonData[0].impression_id as string)).toBe(true)
expect(jsonData[0].course_id).toBe(1)
})

// test('Test queueIbPsetProblemAttemptedV1Event', async () => {
// const pendingRequest = waitForRequest('POST', 'http://localhost:8888/v1/events')
// await queueIbPsetProblemAttemptedV1Event(
// 1,
// '1234',
// 'variant',
// 'input',
// 'this is the response',
// true,
// 1,
// false,
// 'abcd1',
// 'efgh2'
// )
// const req = await pendingRequest
// const jsonData = await req.json()
// expect(jsonData[0].timestamp).toBe(1)
// expect(jsonData[0].content_id).toBe('1234')
// expect(jsonData[0].variant).toBe('variant')
// expect(jsonData[0].problem_type).toBe('input')
// expect(jsonData[0].response).toBe('this is the response')
// expect(jsonData[0].correct).toBe(true)
// expect(jsonData[0].attempt).toBe(1)
// expect(jsonData[0].final_attempt).toBe(false)
// expect(jsonData[0].pset_content_id).toBe('abcd1')
// expect(jsonData[0].pset_problem_content_id).toBe('efgh2')
// expect(jsonData[0].eventname).toBe('ib_pset_problem_attempted_v1')
// expect(validate(jsonData[0].impression_id as string)).toBe(true)
// expect(jsonData[0].course_id).toBe(1)
// })
test('Test queueIbPsetProblemAttemptedV1Event', async () => {
const pendingRequest = waitForRequest('POST', 'http://localhost:8888/v1/events')
await queueIbPsetProblemAttemptedV1Event(
1,
'1234',
'variant',
'input',
'this is the response',
true,
1,
false,
'abcd1',
'efgh2'
)
const req = await pendingRequest
const jsonData = await req.json()
expect(jsonData[0].timestamp).toBe(1)
expect(jsonData[0].content_id).toBe('1234')
expect(jsonData[0].variant).toBe('variant')
expect(jsonData[0].problem_type).toBe('input')
expect(jsonData[0].response).toBe('this is the response')
expect(jsonData[0].correct).toBe(true)
expect(jsonData[0].attempt).toBe(1)
expect(jsonData[0].final_attempt).toBe(false)
expect(jsonData[0].pset_content_id).toBe('abcd1')
expect(jsonData[0].pset_problem_content_id).toBe('efgh2')
expect(jsonData[0].eventname).toBe('ib_pset_problem_attempted_v1')
expect(validate(jsonData[0].impression_id as string)).toBe(true)
expect(jsonData[0].course_id).toBe(1)
})

// test('Test queueIbInputSubmittedV1Event', async () => {
// const pendingRequest = waitForRequest('POST', 'http://localhost:8888/v1/events')
// await queueIbInputSubmittedV1Event(
// 1,
// 'content-id',
// 'variant',
// 'this is the response',
// 'input-content-id'
// )
// const req = await pendingRequest
// const jsonData = await req.json()
// expect(jsonData[0].timestamp).toBe(1)
// expect(jsonData[0].content_id).toBe('content-id')
// expect(jsonData[0].variant).toBe('variant')
// expect(jsonData[0].response).toBe('this is the response')
// expect(jsonData[0].input_content_id).toBe('input-content-id')
// expect(jsonData[0].eventname).toBe('ib_input_submitted_v1')
// expect(validate(jsonData[0].impression_id as string)).toBe(true)
// expect(jsonData[0].course_id).toBe(1)
// })
test('Test queueIbInputSubmittedV1Event', async () => {
const pendingRequest = waitForRequest('POST', 'http://localhost:8888/v1/events')
await queueIbInputSubmittedV1Event(
1,
'content-id',
'variant',
'this is the response',
'input-content-id'
)
const req = await pendingRequest
const jsonData = await req.json()
expect(jsonData[0].timestamp).toBe(1)
expect(jsonData[0].content_id).toBe('content-id')
expect(jsonData[0].variant).toBe('variant')
expect(jsonData[0].response).toBe('this is the response')
expect(jsonData[0].input_content_id).toBe('input-content-id')
expect(jsonData[0].eventname).toBe('ib_input_submitted_v1')
expect(validate(jsonData[0].impression_id as string)).toBe(true)
expect(jsonData[0].course_id).toBe(1)
})

// test('Test timer resets itself after flushing', async () => {
// await queueContentLoadFailedV1Event(1, '1234', 'error')
// await waitForRequest('POST', 'http://localhost:8888/v1/events')
// await queueContentLoadFailedV1Event(1, '12345', 'error2')
// await waitForRequest('POST', 'http://localhost:8888/v1/events')
// })
test('Test timer resets itself after flushing', async () => {
await queueContentLoadFailedV1Event(1, '1234', 'error')
await waitForRequest('POST', 'http://localhost:8888/v1/events')
await queueContentLoadFailedV1Event(1, '12345', 'error2')
await waitForRequest('POST', 'http://localhost:8888/v1/events')
})
2 changes: 1 addition & 1 deletion src/tests/vitest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { vi } from 'vitest'

window.mathVirtualKeyboard = {
layouts: {}
}
} as any

vi.mock('mathlive', () => ({
MathfieldElement: {
Expand Down
5 changes: 0 additions & 5 deletions vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ export default defineConfig(({ mode }) => {
environment: 'jsdom',
setupFiles: './src/tests/vitest.setup.ts',
include: ['src/tests/*.test.{ts,tsx}'],
environmentOptions: {
jsdom: {
url: 'http://localhost/',
},
},
},

build: {
Expand Down

0 comments on commit 1e52be8

Please sign in to comment.