diff --git a/test/Element/DetailsPanel.js b/test/Element/DetailsPanel.js index ac6715fee441deab54612eb41be1ae2241c93ef8..c0aee2d5ad8c5e8c9f5f5f042e9c87bdc5da4222 100644 --- a/test/Element/DetailsPanel.js +++ b/test/Element/DetailsPanel.js @@ -2,7 +2,6 @@ import assert from 'assert' import axios from 'axios' import { shallowMount, createLocalVue, RouterLinkStub } from '@vue/test-utils' import { FakeAxios } from '~/test/testhelpers' -import { jobsSample } from '~/test/samples' import store from '~/test/store' import DetailsPanel from '~/vue/Element/DetailsPanel' import Modal from '~/vue/Modal' @@ -116,172 +115,6 @@ describe('Element/DetailsPanel.vue', () => { assert.strictEqual(store.history.length, 0) }) - it('loads the element if it lacks metadata or classifications', async () => { - mock.onGet('/element/elementid/').reply(200, { - id: 'elementid', - metadata: [], - classifications: [] - }) - store.state.elements.elements.elementid = { id: 'elementid' } - store.state.elements.transcriptions.elementid = { - ts1: { - id: 'ts1', - type: 'word', - text: 'lol' - } - } - - shallowMount(DetailsPanel, { - store, - localVue, - mocks: { - $route - }, - stubs: { - RouterLink: RouterLinkStub - }, - propsData: { - corpusId: 'corpusid', - hasMlClasses: false, - elementId: 'elementid' - } - }) - await Vue.nextTick() - await store.actionsCompleted() - - assert.deepStrictEqual(store.history, [ - { - action: 'elements/get', - payload: { - id: 'elementid' - } - }, - { - action: 'corpora/get', - payload: { - id: 'corpusid' - } - }, - { - mutation: 'elements/set', - payload: { - id: 'elementid', - metadata: [], - classifications: [] - } - } - ]) - }) - - it('allows deleting an element', async () => { - store.state.elements.elements.elementid = { - id: 'elementid', - name: 'Le Element', - type: 'element', - metadata: [], - classifications: [], - corpus: store.state.corpora.corpora.corpusid - } - mock.onGet('/element/elementid/transcriptions/').reply(200, { count: 0, results: [] }) - mock.onDelete('/element/elementid/').reply(204) - mock.onGet('/jobs/').reply(200, jobsSample) - - const wrapper = shallowMount(DetailsPanel, { - store, - localVue, - mocks: { - $route - }, - stubs: { - RouterLink: RouterLinkStub, - Modal - }, - propsData: { - corpusId: 'corpusid', - hasMlClasses: false, - elementId: 'elementid' - } - }) - await store.actionsCompleted() - await Vue.nextTick() - store.history = [] - - const deleteButton = wrapper.get('a.icon-trash') - const deleteModal = wrapper.get('.modal') - assert.ok(deleteButton.classes('has-text-danger')) - assert.strictEqual(deleteButton.attributes('title'), 'Delete this element') - // No modal displayed - assert.ok(!deleteModal.classes('is-active')) - - await deleteButton.trigger('click') - assert.ok(deleteModal.classes('is-active')) - assert.strictEqual(deleteModal.get('.modal-card-head p').text(), 'Delete Element type Le Element') - assert.strictEqual( - deleteModal.get('.modal-card-body').text().split('\n').map(line => line.trim()).join(' '), - 'Are you sure you want to delete the Element type Le Element ? ' + - 'Child elements will also be deleted recursively. ' + - 'This action is irreversible.' - ) - - const performDeleteButton = deleteModal.get('.button.is-danger') - await performDeleteButton.trigger('click') - await store.actionsCompleted() - - assert.deepStrictEqual(store.history, [ - { - action: 'elements/delete', - payload: { - id: 'elementid' - } - }, - { - mutation: 'elements/setTranscriptions', - payload: { - data: { - count: 0, - results: [] - }, - id: 'elementid' - } - }, - { - mutation: 'elements/remove', - payload: 'elementid' - }, - { - mutation: 'navigation/addToScheduledDeletion', - payload: 'elementid' - }, - { - mutation: 'notifications/notify', - payload: { - type: 'success', - text: 'Element deletion has been scheduled.' - } - }, - { - action: 'jobs/list', - payload: null - }, - { - mutation: 'jobs/setLoading', - payload: true - }, - { - mutation: 'elements/selectElement', - payload: null - }, - { - mutation: 'jobs/bulkSet', - payload: jobsSample - }, - { - mutation: 'jobs/setLoading', - payload: false - } - ]) - }) - it('forbids deleting an element without admin access', async () => { store.state.corpora.corpora.corpusid.rights = ['read', 'write'] store.state.elements.elements.elementid = { diff --git a/vue/Element/DetailsPanel.vue b/vue/Element/DetailsPanel.vue index 92a650ad1986d5475c16d6af3aa590dad835a75b..c33ebbec2ba674a4daeae8bbc150e36b6b0feb0a 100644 --- a/vue/Element/DetailsPanel.vue +++ b/vue/Element/DetailsPanel.vue @@ -40,7 +40,7 @@ </Modal> </div> - <div v-if="!retrievedDetails" class="loading-content loader"></div> + <div v-if="!element" class="loading-content loader"></div> <template v-else> <template v-if="elementType.folder === false"> <OrientationPanel :element-id="elementId" /> @@ -197,9 +197,6 @@ export default { this.element.classifications && this.element.classifications.find(c => c.ml_class.id === this.selectedNewClassification) }, - retrievedDetails () { - return this.element && 'metadata' in this.element && 'classifications' in this.element - }, classifications () { return (this.element && this.element.classifications) || [] }, @@ -282,7 +279,7 @@ export default { async handler (id) { if (!id) return // Prevent retrieving element details multiple times - if (!this.element || this.element.id !== id || !this.retrievedDetails) await this.$store.dispatch('elements/get', { id }) + if (this.element?.id !== id) await this.$store.dispatch('elements/get', { id }) } }, elementType: {