-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11833 from EshaanAgg/vtl
Introduce Vue Testing Library
- Loading branch information
Showing
13 changed files
with
400 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 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 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
39 changes: 39 additions & 0 deletions
39
kolibri/core/assets/src/views/ExamReport/__tests__/AttemptIconDiff.spec.js
This file contains 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,39 @@ | ||
import { render, screen } from '@testing-library/vue'; | ||
import '@testing-library/jest-dom'; | ||
import VueRouter from 'vue-router'; | ||
import { themeTokens } from 'kolibri-design-system/lib/styles/theme'; | ||
import AttemptIconDiff from '../AttemptIconDiff.vue'; | ||
|
||
const successThemeColor = themeTokens().correct; | ||
|
||
// Helper function to render the component with some default props | ||
const renderComponent = props => { | ||
return render(AttemptIconDiff, { | ||
props: { | ||
correct: 1, | ||
diff: 1, | ||
...props, | ||
}, | ||
routes: new VueRouter(), | ||
}); | ||
}; | ||
|
||
describe('AttemptIconDiff', () => { | ||
test('renders KIcon with correct styles when correct and diff conditions are met', () => { | ||
renderComponent(); | ||
|
||
const kIcon = screen.getByTestId('correct-icon'); | ||
expect(kIcon).toBeInTheDocument(); | ||
expect(kIcon).toHaveStyle({ fill: successThemeColor }); | ||
}); | ||
|
||
test('does not render KIcon when correct condition is not met', () => { | ||
renderComponent({ correct: 0 }); | ||
expect(screen.queryByTestId('correct-icon')).not.toBeInTheDocument(); | ||
}); | ||
|
||
test('does not render KIcon when diff condition is not met', () => { | ||
renderComponent({ diff: 0 }); | ||
expect(screen.queryByTestId('k-icon')).not.toBeInTheDocument(); | ||
}); | ||
}); |
75 changes: 75 additions & 0 deletions
75
kolibri/core/assets/src/views/ExamReport/__tests__/AttemptTextDiff.spec.js
This file contains 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,75 @@ | ||
import { render, screen } from '@testing-library/vue'; | ||
import '@testing-library/jest-dom'; | ||
import VueRouter from 'vue-router'; | ||
import AttemptTextDiff from '../AttemptTextDiff.vue'; | ||
|
||
const renderComponent = props => { | ||
return render(AttemptTextDiff, { | ||
routes: new VueRouter(), | ||
props, | ||
store: { | ||
getters: { | ||
currentUserId: () => 'mockUser1', | ||
}, | ||
}, | ||
}); | ||
}; | ||
|
||
const testCases = [ | ||
{ | ||
caseName: 'Second Person Perspective: Answer Improved', | ||
correct: 1, | ||
diff: 1, | ||
userId: 'mockUser1', | ||
expectedMessage: 'You improved your incorrect answer from the previous attempt', | ||
}, | ||
{ | ||
caseName: 'Second Person Perspective: Incorrect Answer', | ||
correct: 0, | ||
diff: 0, | ||
userId: 'mockUser1', | ||
expectedMessage: 'You also answered this incorrectly on the previous attempt', | ||
}, | ||
{ | ||
caseName: 'Second Person Perspective: Correct Answer', | ||
correct: 0, | ||
diff: -1, | ||
userId: 'mockUser1', | ||
expectedMessage: 'You answered this correctly on the previous attempt', | ||
}, | ||
{ | ||
caseName: 'Third Person Perspective: Answer Improved', | ||
correct: 1, | ||
diff: 1, | ||
userId: 'mockUser2', | ||
expectedMessage: 'Learner improved their incorrect answer from the previous attempt', | ||
}, | ||
{ | ||
caseName: 'Third Person Perspective: Incorrect Answer', | ||
correct: 0, | ||
diff: 0, | ||
userId: 'mockUser2', | ||
expectedMessage: 'Learner also answered this incorrectly on the previous attempt', | ||
}, | ||
{ | ||
caseName: 'Third Person Perspective: Correct Answer', | ||
correct: 0, | ||
diff: -1, | ||
userId: 'mockUser2', | ||
expectedMessage: 'Learner answered this correctly on the previous attempt', | ||
}, | ||
]; | ||
|
||
describe('AttemptTextDiff', () => { | ||
testCases.forEach(({ caseName, correct, diff, userId, expectedMessage }) => { | ||
test(caseName, () => { | ||
renderComponent({ correct, diff, userId }); | ||
expect(screen.getByText(expectedMessage)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
test('No text is shown when the props are invalid', () => { | ||
renderComponent({ correct: 1, diff: 0, userId: 'mockUser1' }); | ||
expect(screen.queryByTestId('attempt-text-diff')).not.toBeInTheDocument(); | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
kolibri/core/assets/src/views/ExamReport/__tests__/TriesOverview.spec.js
This file contains 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,68 @@ | ||
import { render, screen } from '@testing-library/vue'; | ||
import '@testing-library/jest-dom'; | ||
import VueRouter from 'vue-router'; | ||
import TriesOverview from '../TriesOverview.vue'; | ||
import * as tryValidatorModule from '../utils'; | ||
|
||
// Mock the tryValidator namespace as the same is used in the component | ||
// eslint-disable-next-line import/namespace | ||
tryValidatorModule.tryValidator = jest.fn(() => true); | ||
|
||
// Helper function to render the component with some default props | ||
const renderComponent = props => { | ||
const commonCoreStrings = { | ||
methods: { | ||
coreString: x => x, | ||
}, | ||
}; | ||
|
||
const defaultProps = { | ||
pastTries: [], | ||
totalQuestions: 20, | ||
suggestedTime: 240, | ||
...props, | ||
}; | ||
|
||
return render(TriesOverview, { | ||
props: { | ||
...defaultProps, | ||
...props, | ||
}, | ||
routes: new VueRouter(), | ||
mixins: [commonCoreStrings], | ||
}); | ||
}; | ||
|
||
describe('TriesOverview', () => { | ||
describe('Test the progress icon and label', () => { | ||
test('renders progress icon and completed label when there is a completed try', () => { | ||
renderComponent({ | ||
pastTries: [ | ||
{ | ||
id: '1', | ||
completion_timestamp: 100, | ||
}, | ||
], | ||
}); | ||
|
||
expect(screen.getByTestId('progress-icon-1')).toBeInTheDocument(); | ||
expect(screen.getByText('completedLabel')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders progress icon and in-progress label when there is an in-progress try', () => { | ||
renderComponent({ | ||
pastTries: [{ id: '2' }], | ||
}); | ||
|
||
expect(screen.getByTestId('progress-icon-0.5')).toBeInTheDocument(); | ||
expect(screen.getByText('inProgressLabel')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders progress icon and not started label when there are no past tries', () => { | ||
renderComponent(); | ||
|
||
expect(screen.getByTestId('progress-icon-0')).toBeInTheDocument(); | ||
expect(screen.getByText('notStartedLabel')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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 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 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 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.