From 41091bb4d2ea6fdff8d961519a790cce201230e3 Mon Sep 17 00:00:00 2001 From: normanqw Date: Sat, 20 Apr 2024 15:19:18 -0400 Subject: [PATCH] Added more visibility tests --- .../test_single_project.ts | 15 +++++++++++++++ tests/test_components/test_course_view.ts | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/test_components/test_course_admin/test_manage_projects/test_single_project.ts b/tests/test_components/test_course_admin/test_manage_projects/test_single_project.ts index ad0e878d1..0171f5598 100644 --- a/tests/test_components/test_course_admin/test_manage_projects/test_single_project.ts +++ b/tests/test_components/test_course_admin/test_manage_projects/test_single_project.ts @@ -157,4 +157,19 @@ describe('SingleProject.vue', () => { let api_errors = wrapper.findComponent({ref: 'api_errors'}).vm; expect(api_errors.d_api_errors.length).toBe(1); }); + + test('Visibility icons toggle based on project visibility to students', async () => { + // Test when the project is visible to students + wrapper.setProps({ project: make_project(course_1.pk, {visible_to_students: true})}); + await wrapper.vm.$nextTick(); + expect(wrapper.find('.fa-eye').exists()).toBe(true); + expect(wrapper.find('.fa-eye-slash').exists()).toBe(false); + + // Update the project to not visible and check for correct icons + wrapper.setProps({ project: make_project(course_1.pk, {visible_to_students: false} )}); + await wrapper.vm.$nextTick(); + expect(wrapper.find('.fa-eye').exists()).toBe(false); + expect(wrapper.find('.fa-eye-slash').exists()).toBe(true); + + }); }); diff --git a/tests/test_components/test_course_view.ts b/tests/test_components/test_course_view.ts index d00061cda..27b4572c6 100644 --- a/tests/test_components/test_course_view.ts +++ b/tests/test_components/test_course_view.ts @@ -124,4 +124,22 @@ describe('CourseView tests', () => { expect(wrapper.findAll('.fa-eye').length).toEqual(1); expect(wrapper.findAll('.fa-eye-slash').length).toEqual(1); }); + + test('student cannot see the eye icon', async () => { + user_roles_stub.returns( + Promise.resolve(data_ut.make_user_roles({is_student: true})) + ); + + wrapper = mount(CourseView, { + stubs: ['router-link', 'router-view'], + mocks: { + $route + } + }); + expect(await wait_for_load(wrapper)).toBe(true); + + expect(wrapper.findAll('.project').length).toEqual(2); + expect(wrapper.findAll('.fa-eye').length).toEqual(0); + expect(wrapper.findAll('.fa-eye-slash').length).toEqual(0); + }); });