Skip to content

Commit

Permalink
Fixed existing broken react-components tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmartin committed Jul 20, 2023
1 parent bc5345f commit 76482c7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 40 deletions.
3 changes: 3 additions & 0 deletions react-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
},
"modulePaths": [
"src/library"
],
"setupFiles": [
"./setup-jest-mock.js"
]
},
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions react-components/setup-jest-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// mock google tag manager
global.gtag = jest.fn();
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@ Enzyme.configure({adapter: new Adapter()})

// form uses Portal global
global.Portal = {
currentUser: {
isAdmin: false,
},
API_V1: {
EXTERNAL_RESEARCHER_REPORT_LEARNER_QUERY: 'http://query-test.concord.org'
}
}

describe('LearnerReportForm', () => {
const externalReports = [{url: 'url1', label: 'label1'}, {url: 'url2', label: 'label2'}]
const externalReports = [{url: 'url1', name: 'first', label: 'label1'}, {url: 'url2', name: 'second', label: 'label2'}]
const wrapper = Enzyme.shallow(
<LearnerReportForm externalReports={externalReports} />
)

it('renders all the report buttons', () => {
expect(wrapper.html()).toEqual(expect.stringContaining('Usage Report'))
expect(wrapper.html()).toEqual(expect.stringContaining('Details Report'))
expect(wrapper.html()).toEqual(expect.stringContaining('Arg Block Report'))
})

it('renders custom external report buttons', () => {
expect(wrapper.find(ExternalReportButton).length).toEqual(2)
expect(wrapper.find({reportUrl: 'url1', label: 'label1'}).length).toEqual(1)
Expand All @@ -37,7 +34,7 @@ describe('LearnerReportForm', () => {
it('renders filter forms', () => {
expect(wrapper.text()).toEqual(expect.stringContaining('Schools'))
expect(wrapper.text()).toEqual(expect.stringContaining('Teachers'))
expect(wrapper.text()).toEqual(expect.stringContaining('Runnables'))
expect(wrapper.text()).toEqual(expect.stringContaining('Resources'))
expect(wrapper.text()).toEqual(expect.stringContaining('Permission forms'))
expect(wrapper.find(Select).length).toEqual(4)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,54 +46,32 @@ describe('When I try to render a student roster', () => {
it("should render with default parameters", () => {
const studentRoster = Enzyme.shallow(<StudentRoster canEdit={true} students={students} otherStudents={otherStudents} />);
expect(studentRoster.html()).toBe(pack(`
<div class="header">
<div class="search">
<div class="select">
<select id="student_id_selector">
<option selected="" value="0">Select registered student ...</option>
<option value="3">Student 3 (s3)</option>
<option value="4">Student 4 (s4)</option>
</select>
</div>
<div>
<button disabled="">Add</button>
</div>
</div>
<div class="or">
or
</div>
<div>
<span class="link" role="link">Register &amp; Add New Student</span>
</div>
</div>
<table class="table">
<table class=\"table\">
<tbody>
<tr>
<th>Name</th>
<th>Username</th>
<th>Last Login</th>
<th>Assignments Started</th>
<th class="hide_in_print"></th>
<th class=\"hide_in_print\"></th>
</tr>
<tr>
<td>Student 1</td>
<td>s1</td>
<td>Last Tuesday</td>
<td>1</td>
<td class="hide_in_print">
<span class="link" role="link">Remove Student</span>
<span class="link" role="link">Change Password</span>
</td>
<td class=\"hide_in_print\">
<span class=\"link\" role=\"link\">Remove Student</span>
<span class=\"link\" role=\"link\">Change Password</span></td>
</tr>
<tr>
<td>Student 2</td>
<td>s2</td>
<td>Never</td>
<td>2</td>
<td class="hide_in_print">
<span class="link" role="link">Remove Student</span>
<span class="link" role="link">Change Password</span>
</td>
<td class=\"hide_in_print\">
<span class=\"link\" role=\"link\">Remove Student</span>
<span class=\"link\" role=\"link\">Change Password</span></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ Enzyme.configure({adapter: new Adapter()})

// form uses Portal global
global.Portal = {
currentUser: {
isAdmin: false,
},
API_V1: {
EXTERNAL_RESEARCHER_REPORT_LEARNER_QUERY: 'http://query-test.concord.org'
}
}

describe('UserReportForm', () => {
const externalReports = [{url: 'url1', label: 'label1'}, {url: 'url2', label: 'label2'}]
const externalReports = [{url: 'url1', name: 'first', label: 'label1'}, {url: 'url2', name: 'second', label: 'label2'}]
const wrapper = Enzyme.shallow(
<UserReportForm externalReports={externalReports} />
)
Expand All @@ -31,7 +34,7 @@ describe('UserReportForm', () => {
it('renders filter forms', () => {
expect(wrapper.text()).toEqual(expect.stringContaining('Teachers'))
expect(wrapper.text()).toEqual(expect.stringContaining('Cohorts'))
expect(wrapper.text()).toEqual(expect.stringContaining('Runnables'))
expect(wrapper.text()).toEqual(expect.stringContaining('Resources'))
expect(wrapper.find(Select).length).toEqual(3)

expect(wrapper.text()).toEqual(expect.stringContaining('Earliest date'))
Expand Down

0 comments on commit 76482c7

Please sign in to comment.