Skip to content

Commit 4bf9fba

Browse files
authored
Merge pull request #394 from pressbooks/dev
v2.4 release
2 parents 0428cb5 + 0b126d7 commit 4bf9fba

File tree

8 files changed

+82
-48
lines changed

8 files changed

+82
-48
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ VITE_ALGOLIA_API_READ_KEY=
33
VITE_ALGOLIA_INDEX=
44
VITE_ALGOLIA_INDEX_ALPHABETICAL_REPLICA=
55
VITE_ALGOLIA_INDEX_LAST_UPDATED_REPLICA=
6+
VITE_CLICK_COUNT_ENDPOINT=
67
VITE_HEADER_ADDITIONAL_TEXT=
78
VITE_USER_NODE_ENV=
89
VITE_APP_GA_MEASUREMENT_ID=

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ BrowserStack reports can be accessed in [App Live BrowserStack Dashboard](https:
6868
### Run E2E tests locally
6969
Tests can also be run locally as well using the instructions below:
7070
1. You can run local tests on **Chrome**, **Firefox** and **Edge**. Make sure you have at least one of those browsers installed on your local machine.
71-
1. Make sure that you have properly configured the Algolia indices to be used by your application. The Pressbooks internal team can find details [here](https://docs.google.com/document/d/1SNf7jIelkXwzzAxEbGSjEL59GMDeh3o3wH7myY3LfBM/edit?usp=sharing)
71+
1. Make sure that you have properly configured the Algolia indices to be used by your application. The Pressbooks internal team can find details [here](https://docs.google.com/document/d/1F82PSJKeufpKp8bGrDifjPxGo2x6tKD-HJpTsuadCeg/edit#heading=h.3j6ezaup0nca)
7272
1. The local server should already be running: `npm run dev` before tests are run locally.
7373
1. Tests can be run locally with the following command: `npm run test`. Cypress app will open, and you would choose in which browser do you want to run your tests
7474
1. You can run E2E tests on headless mode by running: `npm run test:ci`

e2e/integration/bookCards.spec.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Elements from '../support/elements';
2-
import {clickAccordionHeader, clickFilter, search} from '../support/common';
2+
import {clickAccordionHeader, clickFilter, clickPage, search} from '../support/common';
33
import helpers from '../../src/store/helpers';
44

55
describe('Book cards', function () {
@@ -70,7 +70,7 @@ describe('Book cards', function () {
7070
search('Nursing Pharmacology').then(()=>{
7171
cy.get(Elements.booksCards.editors)
7272
.first()
73-
.contains('Elizabeth Christman, MSN, RN, CNE and Kimberly Ernstmeyer, CNE, CHSE, APNP-BC');
73+
.should('include.text', 'Elizabeth Christman, MSN, RN, CNE and Kimberly Ernstmeyer');
7474
});
7575
});
7676
it('Search a book with description and check it is present in the book cards', () => {
@@ -183,9 +183,24 @@ describe('Book cards', function () {
183183
search('math');
184184

185185
cy.get(Elements.booksCards.cover)
186-
.eq(1).find('img')
186+
.eq(3).find('img')
187187
.should('have.attr', 'src')
188188
.should('include', '/assets/images/default-book-cover.jpg');
189189
});
190+
it('Lazy loading cover images', () => {
191+
clickPage(3);
192+
193+
cy.get(Elements.booksCards.cover)
194+
.eq(2).find('img')
195+
.should('have.attr', 'src')
196+
.should('include', '/assets/images/default-book-cover.jpg');
197+
198+
cy.get('[data-cy=storage-filter]').scrollIntoView()
199+
.wait(200);
200+
cy.get(Elements.booksCards.cover)
201+
.eq(2).find('img')
202+
.should('have.attr', 'src')
203+
.should('include', 'monarch.jpg');
204+
});
190205
});
191206
});

package-lock.json

Lines changed: 13 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pressbooks-directory",
3-
"version": "2.3.0",
3+
"version": "2.4.0",
44
"engines": {
55
"node": ">=15.14.0",
66
"npm": ">=7.0.0"
@@ -11,6 +11,7 @@
1111
"build:staging": "TAILWIND_MODE=build vite build --mode staging",
1212
"serve": "vite preview",
1313
"lint": "eslint ./src --ext .js --ext .vue",
14+
"lint:fix": "eslint ./src --ext .js --ext .vue --fix",
1415
"start": "npm run dev & wait-on tcp:3001 -v",
1516
"test": "cypress open",
1617
"test:ci": "cypress run --headless",
@@ -28,10 +29,10 @@
2829
"intro.js": "^3.4.0",
2930
"nprogress": "^0.2.0",
3031
"search-insights": "^2.0.0",
31-
"v-img-fallback": "^0.1.5",
3232
"vue": "^2.6.12",
3333
"vue-clamp": "^0.3.2",
3434
"vue-instantsearch": "^3.6.0",
35+
"vue-lazyload": "^1.3.3",
3536
"vue-router": "^3.5.1",
3637
"vue-select": "^3.11.2",
3738
"vue-tailwind": "^2.2.1",

src/components/PbBookCover.vue

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
<template>
2-
<img
3-
v-img-fallback="'/assets/images/default-book-cover.jpg'"
4-
class="w-full"
5-
:src="image"
2+
<div
3+
v-lazy-container="{ selector: 'img', error: defaulImg, loading: defaulImg }"
64
>
5+
<img
6+
class="w-full"
7+
:data-src="image"
8+
>
9+
</div>
710
</template>
811

912
<script>
10-
import { ImgFallback } from 'v-img-fallback';
1113
1214
export default {
1315
name: 'PbBookCover',
14-
directives: {
15-
ImgFallback
16-
},
1716
props: {
1817
image: {
1918
type: String,
2019
default: ''
2120
},
2221
},
22+
data() {
23+
return {
24+
defaulImg: '/assets/images/default-book-cover.jpg'
25+
};
26+
}
2327
};
2428
</script>

src/components/books/BookInfo.vue

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@
1414
target="_blank"
1515
rel="noopener"
1616
data-cy="book-title"
17-
@click="$emit('book-title-click')"
17+
@click="clickBook"
1818
>
1919
{{ item.name }}
2020
</a>
2121
</h2>
2222
<p class="leading-tight">
23-
<span data-cy="book-word-count">{{ item.wordCount | numberFormat }}</span> words | <span data-cy="book-size">{{ sizeInMb }}</span> MB | <span data-cy="h5p-count">{{ item.h5pActivities | numberFormat }}</span> H5P activities
23+
<span data-cy="book-word-count">{{ item.wordCount | numberFormat }}</span> words | <span data-cy="book-size">{{ sizeInMb }}</span> MB | <template v-if="hasH5PActivities">
24+
<a
25+
:href="item.url + 'h5p-listing'"
26+
class="text-pb-red underline"
27+
target="_blank"
28+
><span data-cy="h5p-count">{{ item.h5pActivities | numberFormat }}</span> H5P activities</a>
29+
</template>
30+
<template v-else>
31+
<span
32+
data-cy="h5p-count"
33+
>{{ item.h5pActivities | numberFormat }}</span> H5P activities
34+
</template>
2435
</p>
2536
</div>
2637
</template>
@@ -40,6 +51,25 @@ export default {
4051
const size = (parseInt(this.item.storageSize) / 1024) / 1024;
4152
4253
return size.toFixed(2);
54+
},
55+
hasH5PActivities() {
56+
return this.item.hasH5pActivities && this.item.h5pActivities > 0;
57+
}
58+
},
59+
methods: {
60+
clickBook() {
61+
this.$emit('book-title-click');
62+
const clickEndpoint = import.meta.env.VITE_CLICK_COUNT_ENDPOINT;
63+
if (clickEndpoint) {
64+
fetch(clickEndpoint,{
65+
mode: 'no-cors',
66+
method: 'POST',
67+
headers: {
68+
'Content-Type': 'application/json',
69+
},
70+
body: JSON.stringify({book_id:this.item.objectID}),
71+
});
72+
}
4373
}
4474
}
4575
};

src/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import App from './App.vue';
33
import InstantSearch from 'vue-instantsearch';
44
import VueSelect from 'vue-select';
55
import VueTailwind from 'vue-tailwind';
6+
import VueLazyload from 'vue-lazyload';
67
import router from './router';
78
import VueTailwindConfig from './vuetailwind.config';
89
import dayjs from 'dayjs';
@@ -14,6 +15,7 @@ import {store} from './store';
1415
Vue.component('VueSelect', VueSelect);
1516
Vue.use(InstantSearch);
1617
Vue.use(VueTailwind, VueTailwindConfig);
18+
Vue.use(VueLazyload);
1719
Vue.mixin(AlgoliaMixin);
1820
Vue.filter('numberFormat', (value, locale) => value.toLocaleString(locale || 'en'));
1921

0 commit comments

Comments
 (0)