Skip to content

Commit 4badeec

Browse files
authored
Merge pull request #2558 from FAIRsharing/dev
Dev
2 parents c9ff1f3 + 9f4b6ff commit 4badeec

File tree

5 files changed

+136
-20
lines changed

5 files changed

+136
-20
lines changed

src/router/index.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ let routes = [
130130
},
131131

132132
/* VARIOUS REDIRECTIONS */
133+
{
134+
name: "fairassist",
135+
path: "/fairassist",
136+
redirect: () => {
137+
window.location.assign(
138+
[
139+
process.env.VUE_APP_API_HOSTNAME,
140+
"/search?fairsharingRegistry=FAIRassist",
141+
].join("")
142+
);
143+
},
144+
},
133145
{
134146
name: "article",
135147
path: "/article/:name",
@@ -450,11 +462,21 @@ let routes = [
450462
name: "New_content",
451463
path: "/create",
452464
component: NewRecord,
465+
props: { fairassistOnly: false },
466+
beforeEnter(to, from, next) {
467+
isLoggedIn(to, from, next, store);
468+
},
469+
},
470+
{
471+
name: "New_FAIRassist_content",
472+
path: "/create-fairassist",
473+
component: NewRecord,
474+
props: { fairassistOnly: true },
475+
/* istanbul ignore next */
453476
beforeEnter(to, from, next) {
454477
isLoggedIn(to, from, next, store);
455478
},
456479
},
457-
458480
/* Static pages */
459481
{
460482
name: "New",

src/store/editor.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -151,25 +151,28 @@ let editorStore = {
151151
let countries = await graphClient.executeQuery(countriesQuery);
152152
state.commit("setCountries", countries['searchCountries'])
153153
},
154-
async getRecordTypes(state){
154+
async getRecordTypes(state, fairassistOnly=false){
155155
let recordTypes = [];
156156
let data = await graphClient.executeQuery(typesQuery);
157157
const size = data['fairsharingRegistries'].records.length;
158158
let currentItem = 0;
159159
data['fairsharingRegistries'].records.forEach(function(type){
160-
currentItem += 1;
161-
recordTypes.push({
162-
header: type.name
163-
});
164-
type.recordTypes.forEach(function(subType){
165-
recordTypes.push({
166-
name: subType.name,
167-
group: type.name,
168-
id: subType.id,
169-
description: subType.description
170-
})
171-
});
172-
if (currentItem < size) recordTypes.push({ divider: true });
160+
if (fairassistOnly){
161+
if (type.name.toLowerCase() !== 'fairassist') return;
162+
}
163+
currentItem += 1;
164+
recordTypes.push({
165+
header: type.name
166+
});
167+
type.recordTypes.forEach(function(subType){
168+
recordTypes.push({
169+
name: subType.name,
170+
group: type.name,
171+
id: subType.id,
172+
description: subType.description
173+
})
174+
});
175+
if (currentItem < size) recordTypes.push({ divider: true });
173176
});
174177
state.commit("setRecordTypes", recordTypes);
175178
},

src/views/CreateRecord/NewRecord.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
<v-col cols="12">
1313
<v-card v-if="loaded">
1414
<v-card-title class="primary white--text">
15-
<h3 class="white--text">
15+
<h3
16+
v-if="fairassistOnly"
17+
class="white--text"
18+
>
19+
Creating a new FAIRassist record
20+
</h3>
21+
<h3
22+
v-else
23+
>
1624
Creating a new FAIRsharing record
1725
</h3>
1826
</v-card-title>
@@ -102,6 +110,9 @@
102110
export default {
103111
name: "NewRecordPage",
104112
components: {Loaders, BaseFields},
113+
props: {
114+
fairassistOnly: { type: Boolean, default: false }
115+
},
105116
data(){
106117
return {
107118
record: {},
@@ -147,7 +158,7 @@
147158
...mapActions("record", ["resetRecord"]),
148159
async getData(){
149160
await this.getCountries();
150-
await this.getRecordTypes();
161+
await this.getRecordTypes(this.fairassistOnly);
151162
await this.getTags();
152163
},
153164
async createRecord(){

tests/unit/router/routes.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ describe("Routes", () => {
205205
old_policies_institution: '/search?fairsharingRegistry=Policy&recordType=institution&page=1',
206206
old_policies_society: '/search?fairsharingRegistry=Policy&recordType=society&page=1',
207207
old_policies_journal_publisher: '/search?fairsharingRegistry=Policy&recordType=journal_publisher&page=1',
208-
old_policies_funder: '/search?fairsharingRegistry=Policy&recordType=funder&page=1'
208+
old_policies_funder: '/search?fairsharingRegistry=Policy&recordType=funder&page=1',
209+
fairassist: '/search?fairsharingRegistry=FAIRassist'
209210
}
210211

211212
// eslint-disable no-promise-executor-return
@@ -262,8 +263,6 @@ describe("Routes", () => {
262263
// eslint-enable no-promise-executor-return
263264
});
264265

265-
266-
267266
it("gets sitemap from the api", async () => {
268267
process.env.VUE_APP_API_ENDPOINT = 'https://api.fairsharing.org'
269268
let assignMock = jest.fn();
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { createLocalVue, shallowMount } from '@vue/test-utils'
2+
import sinon from "sinon";
3+
import VueRouter from "vue-router";
4+
import Vuetify from "vuetify"
5+
import Vuex from "vuex"
6+
7+
import GraphClient from "@/lib/GraphClient/GraphClient";
8+
import editorStore from "@/store/editor.js"
9+
import recordStore from "@/store/recordData.js"
10+
import userStore from "@/store/users.js"
11+
import NewRecord from "@/views/CreateRecord/NewRecord.vue"
12+
13+
const localVue = createLocalVue();
14+
localVue.use(Vuex);
15+
const vuetify = new Vuetify();
16+
17+
recordStore.state.newRecord = false;
18+
userStore.state.user().is_curator = false;
19+
userStore.state.user().credentials.token = 'a token';
20+
21+
const recordTypeData = {
22+
fairsharingRegistries: {
23+
records: [
24+
{
25+
id: 1,
26+
name: "Database"
27+
},
28+
{
29+
id: 2,
30+
name: "FAIRassist"
31+
},
32+
]
33+
}
34+
}
35+
36+
const $store = new Vuex.Store({
37+
modules: {
38+
editor: editorStore,
39+
record: recordStore,
40+
users: userStore
41+
}
42+
});
43+
44+
const $route = {
45+
path: "/create-fairassist"
46+
};
47+
const router = new VueRouter();
48+
const $router = {
49+
push: jest.fn(),
50+
currentRoute: {
51+
path: "/create-fairassist"
52+
}
53+
};
54+
55+
let wrapper;
56+
let graphStub;
57+
58+
describe('NewRecord', () => {
59+
60+
beforeAll(() => {
61+
graphStub = sinon.stub(GraphClient.prototype, "executeQuery");
62+
graphStub.withArgs(sinon.match.any).returns(recordTypeData);
63+
64+
wrapper = shallowMount(NewRecord, {
65+
localVue,
66+
vuetify,
67+
router,
68+
mocks: {$store, $route, $router},
69+
propsData: {
70+
fairassistOnly: true
71+
},
72+
});
73+
});
74+
75+
it("can be mounted", () => {
76+
expect(wrapper.vm.$options.name).toMatch("NewRecord");
77+
expect(wrapper.vm.$route.path).toEqual('/create-fairassist');
78+
expect(wrapper.vm.fairassistOnly).toBe(true);
79+
});
80+
81+
});

0 commit comments

Comments
 (0)