Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ const router = new VueRouter({
name: RouteNames.COMMUNITY_LIBRARY_SUBMISSION,
path: '/community-library/:channelId/:submissionId',
component: SubmissionDetailsModal,
props: route => ({
channelId: route.params.channelId,
submissionId: route.params.submissionId,
adminReview: true,
}),
props: true,
},
// Catch-all redirect to channels tab
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import VueRouter from 'vue-router';
import SubmissionDetailsModal from '../index.vue';
import {
AdminCommunityLibrarySubmission,
ChannelVersion,
CommunityLibrarySubmission,
} from 'shared/data/resources';

jest.mock('shared/data/resources', () => ({
AdminCommunityLibrarySubmission: { fetchModel: jest.fn() },
ChannelVersion: { fetchCollection: jest.fn() },
CommunityLibrarySubmission: {
fetchModel: jest.fn(),
fetchCollection: jest.fn(() => Promise.resolve({ results: [] })),
},
}));

const localVue = createLocalVue();
localVue.use(Vuex);
localVue.use(VueRouter);

const stubChannel = {
id: 'ch1',
name: 'Test',
thumbnail_url: null,
thumbnail_encoding: null,
description: '',
};
const stubSubmission = {
id: 'sub1',
channel_id: 'ch1',
channel_version: 1,
status: 'PENDING',
version_token: null,
};
const stubChannelVersion = { id: 'cv1' };

function makeStore(isAdmin) {
return new Vuex.Store({
getters: { isAdmin: () => isAdmin },
modules: {
channel: {
namespaced: true,
actions: { loadChannel: jest.fn(() => Promise.resolve(stubChannel)) },
},
errors: { namespaced: true, actions: { handleAxiosError: jest.fn() } },
},
});
}

describe('SubmissionDetailsModal', () => {
beforeEach(() => {
AdminCommunityLibrarySubmission.fetchModel.mockResolvedValue(stubSubmission);
CommunityLibrarySubmission.fetchModel.mockResolvedValue(stubSubmission);
ChannelVersion.fetchCollection.mockResolvedValue([stubChannelVersion]);
});

afterEach(() => jest.clearAllMocks());

it('uses AdminCommunityLibrarySubmission when user is admin', () => {
shallowMount(SubmissionDetailsModal, {
localVue,
store: makeStore(true),
router: new VueRouter(),
propsData: { channelId: 'ch1', submissionId: 'sub1' },
});
expect(AdminCommunityLibrarySubmission.fetchModel).toHaveBeenCalledWith('sub1');
});

it('uses CommunityLibrarySubmission when user is not admin', () => {
shallowMount(SubmissionDetailsModal, {
localVue,
store: makeStore(false),
router: new VueRouter(),
propsData: { channelId: 'ch1', submissionId: 'sub1' },
});
expect(CommunityLibrarySubmission.fetchModel).toHaveBeenCalledWith('sub1');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@
</div>
<div class="actions">
<KButton
v-if="adminReview && submission.status === CommunityLibraryStatus.PENDING"
v-if="isAdmin && submission.status === CommunityLibraryStatus.PENDING"
:text="reviewAction$()"
@click="showReviewSidePanel = true"
/>
<ChannelActionsDropdown
v-if="adminReview"
v-if="isAdmin"
primary
:channelId="channelId"
/>
Expand All @@ -105,7 +105,7 @@
:channelId="channelId"
/>
<ReviewSubmissionSidePanel
v-if="adminReview && showReviewSidePanel"
v-if="isAdmin && showReviewSidePanel"
:submissionId="submission.id"
:channel="channel"
@close="showReviewSidePanel = false"
Expand Down Expand Up @@ -143,10 +143,6 @@
import logging from 'shared/logging';

const props = defineProps({
adminReview: {
type: Boolean,
default: false,
},
channelId: {
type: String,
required: true,
Expand All @@ -163,6 +159,7 @@
const route = useRoute();
const router = useRouter();
const store = useStore();
const isAdmin = computed(() => store.getters.isAdmin);
const { windowBreakpoint } = useKResponsiveWindow();

const isModalOpen = computed({
Expand Down Expand Up @@ -206,7 +203,7 @@
} = useFetch({
asyncFetchFunc: async () => {
try {
const Resource = props.adminReview
const Resource = isAdmin.value
? AdminCommunityLibrarySubmission
: CommunityLibrarySubmission;
const submission = await Resource.fetchModel(props.submissionId);
Expand Down
Loading