Skip to content

Commit

Permalink
Merge pull request #510 from Normanwqn/project-visibility
Browse files Browse the repository at this point in the history
Icon to indicate whether a project is published
  • Loading branch information
james-perretta authored Apr 22, 2024
2 parents f390314 + 41091bb commit 1ba1153
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
<div id="single-project-component">
<div class="project-wrapper entity">
<router-link :to="`/web/project/${project.pk}`" class="project-name name info">
{{project.name}}
<div class="project-name-container">
<span class="left-text">{{project.name}}</span>
<span class="right-text tool-icon">
<i class="fa fa-eye" aria-hidden="true" v-if="project.visible_to_students"></i>
<i class="fa fa-eye-slash" aria-hidden="true" v-else></i>
</span>
</div>
</router-link>

<div class="toolbox">
Expand Down
8 changes: 7 additions & 1 deletion src/components/course_view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
<router-link class="project-name info name"
:class="{'round-bottom-corners': !d_globals.user_roles.is_admin}"
:to="`/web/project/${project.pk}`">
{{project.name}}
<div class="project-name-container">
<span class="left-text">{{project.name}}</span>
<span class="right-text tool-icon" v-if="!d_globals.user_roles.is_student">
<i class="fa fa-eye" aria-hidden="true" v-if="project.visible_to_students"></i>
<i class="fa fa-eye-slash" aria-hidden="true" v-else></i>
</span>
</div>
</router-link>
<div class="toolbox" v-if="d_globals.user_roles.is_admin">
<router-link :to="`/web/project_admin/${project.pk}`"
Expand Down
14 changes: 14 additions & 0 deletions src/styles/components/entity_with_toolbox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ $border-radius: 3px;
border-bottom-right-radius: $border-radius;
}

.project-name-container {
display: flex;
justify-content: space-between;
//padding: 0 .25rem;
}

.left-text {
text-align: left;
}

.right-text {
text-align: right;
}

.name {
color: black;
font-size: 1.25rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,19 @@ describe('SingleProject.vue', () => {
let api_errors = <APIErrors> 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);

});
});
35 changes: 35 additions & 0 deletions tests/test_components/test_course_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,39 @@ describe('CourseView tests', () => {
expect(wrapper.findAll('.project').length).toEqual(0);
expect(wrapper.find('#no-projects-message').exists()).toBe(true);
});

test('correct visibility icon is shown for each project', async () => {
project1.visible_to_students = true;
project2.visible_to_students = false;

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(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);
});
});

0 comments on commit 1ba1153

Please sign in to comment.