Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LuXDAmore committed Sep 29, 2020
1 parent fb9395b commit c6f75e0
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 68 deletions.
13 changes: 13 additions & 0 deletions example/graphql/graphql.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query country( $code: ID! ) {
country( code: $code ) {
name
native
capital
emoji
currency
languages {
code
name
}
}
}
7 changes: 7 additions & 0 deletions example/graphql/graphql.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"query": "query country($code: ID!) {\n country(code: $code) {\n name\n native\n capital\n emoji\n currency\n languages {\n code\n name\n }\n }\n }",
"variables": {
"code": "IT"
},
"operationName": "country"
}
4 changes: 2 additions & 2 deletions example/graphql/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import * as USERS from './users.json';
import * as GRAPHQL from './graphql.json';

export { USERS };
export { GRAPHQL };
16 changes: 0 additions & 16 deletions example/graphql/users.gql

This file was deleted.

7 changes: 0 additions & 7 deletions example/graphql/users.json

This file was deleted.

11 changes: 6 additions & 5 deletions example/nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { resolve } from 'path';
import * as PACKAGE from '../package.json';

import { USERS } from './graphql';
import { GRAPHQL } from './graphql';

const meta = [
{
Expand Down Expand Up @@ -43,11 +43,12 @@ export default {
},
// GraphQL
{
endpoint: 'https://api.graph.cool/simple/v1/ciyz901en4j590185wkmexyex',
endpoint: 'https://countries.trevorblades.com/',
method: 'post',
field: 'users',
pathToData: 'data.allUsers',
body: USERS,
field: 'graphql',
pathToData: 'data.country',
emptyValue: {},
body: GRAPHQL,
},
],
},
Expand Down
31 changes: 18 additions & 13 deletions example/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,34 @@
<h3>
<strong>Total number of comments preloaded:</strong>
</h3>
<p>
<em class="number" v-text="$store.state.comments.items.length" />
<p v-if="$store.state.comments && $store.state.comments.items && $store.state.comments.items.length">
<em
class="number"
v-text="$store.state.comments.items.length"
/>
</p>
</section>
<section class="posts">
<h3>
<strong>Total number of posts preloaded:</strong>
</h3>
<p>
<em class="number" v-text="$store.state.posts.items.length" />
<p v-if="$store.state.posts && $store.state.posts.items && $store.state.posts.items.length">
<em
class="number"
v-text="$store.state.posts.items.length"
/>
</p>
</section>
<section class="users">
<section class="graphql">
<h3>
<strong>Total number of users preloaded:</strong>
<strong>Total number graphql data preloaded:</strong>
</h3>
<p>
<em class="number" v-text="$store.state.users.items.length" />
</p>
<code v-if="$store.state.graphql && $store.state.graphql.data">
<pre
class="number"
v-text="$store.state.graphql.data"
/>
</code>
</section>
</main>
</template>

<script>
export default {};
</script>
13 changes: 7 additions & 6 deletions example/store/build-data.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Import the generated data
const getFile = () => import(
'~/apis-to-file/data.json'
).then(
Expand All @@ -12,23 +13,23 @@ export const actions = {

let preloadedComments = []
, preloadedPosts = []
, preloadedUsers = []
, preloadedGraphQl = []
;

try {

const {
comments,
posts,
users,
graphql,
} = await getFile();

if( comments )
preloadedComments = comments;
if( posts )
preloadedPosts = posts;
if( users )
preloadedUsers = users;
if( graphql )
preloadedGraphQl = graphql;

} catch( e ) {

Expand Down Expand Up @@ -57,8 +58,8 @@ export const actions = {
);

commit(
'users/SET_ITEMS',
preloadedUsers,
'graphql/SET_ITEMS',
preloadedGraphQl,
{
root: true,
}
Expand Down
4 changes: 1 addition & 3 deletions example/store/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ export const mutations = {
items,
) {

state.items = Object.freeze(
items,
);
state.items = items;

},
};
8 changes: 3 additions & 5 deletions example/store/users.js → example/store/graphql.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
export const state = () => (
{
items: [],
data: {},
}
);

export const mutations = {
SET_ITEMS(
state,
items,
value,
) {

state.items = Object.freeze(
items,
);
state.data = value;

},
};
4 changes: 1 addition & 3 deletions example/store/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ export const mutations = {
items,
) {

state.items = Object.freeze(
items,
);
state.items = items;

},
};
24 changes: 16 additions & 8 deletions test/module.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Test utils
import {
setup,
get,
} from '@nuxtjs/module-test-utils';

// Dom
import { JSDOM } from 'jsdom';

// Nuxt config
Expand All @@ -11,8 +14,8 @@ const BASE_URL = '/';

config.dev = false;
config.router.base = BASE_URL;
config.server.host = 'localhost';

// Tests
describe(
'module',
() => {
Expand All @@ -31,7 +34,7 @@ describe(
);

},
60000
90000
);

afterAll(
Expand Down Expand Up @@ -73,7 +76,7 @@ describe(
)
, { window } = new JSDOM(
html
).window
)
, element = window.document.querySelector(
selector
)
Expand Down Expand Up @@ -118,7 +121,7 @@ describe(
);

test(
'comments',
'posts',
async() => {

await getElement(
Expand All @@ -130,12 +133,17 @@ describe(
);

test(
'users',
'graphql',
async() => {

await getElement(
'.users',
10,
const html = await get(
BASE_URL
);

expect(
html
).toContain(
'Italy'
);

}
Expand Down

0 comments on commit c6f75e0

Please sign in to comment.