Skip to content

Commit d3330c8

Browse files
committed
ufal/discojuice-not-popped-up (#515)
* Use cookie to popup discojuice login. * Added Cookie Service into tests * Close discojuice if it is popped up * Do not import commands in the constants file. * commands must be imported in the e2e.ts
1 parent 302bccd commit d3330c8

File tree

6 files changed

+46
-7
lines changed

6 files changed

+46
-7
lines changed

cypress/support/commands.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ Cypress.Commands.add('login', login);
118118
* @param password password to login as
119119
*/
120120
function loginViaForm(email: string, password: string): void {
121+
cy.wait(500);
122+
cy.get('.discojuice_close').should('exist').click();
121123
// Enter email
122124
cy.get('ds-log-in [data-test="email"]').type(email);
123125
// Enter password
@@ -226,12 +228,6 @@ export const loginProcess = {
226228
};
227229

228230
export const createItemProcess = {
229-
typeCollectionName() {
230-
cy.get('.modal-body input[type = "search"]').type(TEST_COLLECTION_NAME);
231-
},
232-
selectCollection() {
233-
cy.get('.modal-body .scrollable-menu button[title = "' + TEST_COLLECTION_NAME + '"]').eq(0).click();
234-
},
235231
checkLocalHasCMDIVisibility() {
236232
cy.get('#traditionalpageone form div[role = "group"] label[for = "local_hasCMDI"]').should('be.visible');
237233
},

src/aai/aai.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
case 'local':
9696
// DiscoJuice.UI.setScreen(opts.localauth);
9797
// jQuery('input#login').focus();
98+
// Use cookie to toggle discojuice popup.
99+
setCookie('SHOW_DISCOJUICE_POPUP', false, 1)
98100
window.location = window.location.origin + (namespace === '' ? namespace : '/' + namespace) + "/login?redirectUrl=" + window.location.href;
99101
break;
100102
//case 'saml':
@@ -118,6 +120,15 @@
118120
return djc;
119121
} //if jQuery(selector)
120122
};
123+
124+
// Set a cookie
125+
function setCookie(name, value, daysToExpire) {
126+
var expirationDate = new Date();
127+
expirationDate.setDate(expirationDate.getDate() + daysToExpire);
128+
129+
var cookieString = name + '=' + value + ';expires=' + expirationDate.toUTCString() + ';path=/';
130+
document.cookie = cookieString;
131+
}
121132
}
122133

123134
if (!window.aai) {

src/app/shared/log-in/container/log-in-container.component.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import { RouterMock } from '../../mocks/router.mock';
2323
import { createSuccessfulRemoteDataObject$ } from '../../remote-data.utils';
2424
import { ConfigurationProperty } from '../../../core/shared/configuration-property.model';
2525
import { ActivatedRoute, Router } from '@angular/router';
26+
import { CookieService } from '../../../core/services/cookie.service';
27+
import { CookieServiceMock } from '../../mocks/cookie.service.mock';
2628

2729
describe('LogInContainerComponent', () => {
2830

@@ -82,6 +84,7 @@ describe('LogInContainerComponent', () => {
8284
}
8385
} },
8486
{ provide: Router, useValue: new RouterMock() },
87+
{ provide: CookieService, useClass: CookieServiceMock },
8588
LogInContainerComponent
8689
],
8790
schemas: [

src/app/shared/log-in/log-in.component.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import { ConfigurationDataService } from '../../core/data/configuration-data.ser
2828
import { createSuccessfulRemoteDataObject$ } from '../remote-data.utils';
2929
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
3030
import { RouterStub } from '../testing/router.stub';
31+
import { CookieService } from '../../core/services/cookie.service';
32+
import { CookieServiceMock } from '../mocks/cookie.service.mock';
3133

3234
describe('LogInComponent', () => {
3335

@@ -99,6 +101,7 @@ describe('LogInComponent', () => {
99101
{ provide: ConfigurationDataService, useValue: configurationDataService },
100102
provideMockStore({ initialState }),
101103
{ provide: ThemeService, useValue: getMockThemeService() },
104+
{ provide: CookieService, useClass: CookieServiceMock },
102105
LogInComponent
103106
],
104107
schemas: [

src/app/shared/log-in/methods/password/log-in-password.component.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import { ActivatedRoute , Router} from '@angular/router';
2323
import { RouterMock } from '../../../mocks/router.mock';
2424
import { createSuccessfulRemoteDataObject$ } from '../../../remote-data.utils';
2525
import { ConfigurationProperty } from '../../../../core/shared/configuration-property.model';
26+
import { CookieService } from '../../../../core/services/cookie.service';
27+
import { CookieServiceMock } from '../../../mocks/cookie.service.mock';
2628

2729
describe('LogInPasswordComponent', () => {
2830
const uiUrl = 'localhost:4000';
@@ -99,6 +101,7 @@ describe('LogInPasswordComponent', () => {
99101
}
100102
} },
101103
{ provide: Router, useValue: new RouterMock() },
104+
{ provide: CookieService, useClass: CookieServiceMock },
102105
provideMockStore({ initialState }),
103106
],
104107
schemas: [

src/app/shared/log-in/methods/password/log-in-password.component.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import { ActivatedRoute , Router} from '@angular/router';
2525
import { getBaseUrl } from '../../../clarin-shared-util';
2626
import { ConfigurationProperty } from '../../../../core/shared/configuration-property.model';
2727
import { ConfigurationDataService } from '../../../../core/data/configuration-data.service';
28+
import { CookieService } from '../../../../core/services/cookie.service';
2829

30+
export const SHOW_DISCOJUICE_POPUP_CACHE_NAME = 'SHOW_DISCOJUICE_POPUP';
2931
/**
3032
* /users/sign-in
3133
* @class LogInPasswordComponent
@@ -101,6 +103,7 @@ export class LogInPasswordComponent implements OnInit {
101103
private route: ActivatedRoute,
102104
protected router: Router,
103105
protected configurationService: ConfigurationDataService,
106+
protected storage: CookieService,
104107
) {
105108
this.authMethod = injectedAuthMethodModel;
106109
}
@@ -110,6 +113,7 @@ export class LogInPasswordComponent implements OnInit {
110113
* @method ngOnInit
111114
*/
112115
public async ngOnInit() {
116+
this.initializeDiscoJuiceCache();
113117
this.redirectUrl = '';
114118
// set formGroup
115119
this.form = this.formBuilder.group({
@@ -171,10 +175,18 @@ export class LogInPasswordComponent implements OnInit {
171175
}
172176
}
173177

178+
179+
/**
180+
* Toggle Discojuice login. Show it every time except the case when the user click
181+
* on the `local` button in the discojuice box.
182+
* @private
183+
*/
174184
private toggleDiscojuiceLogin() {
175-
if (isEmpty(this.route.snapshot.queryParams?.redirectUrl)) {
185+
// Popup cache is set to false in the `aai.js` when the user clicks on `local` button
186+
if (this.storage.get(SHOW_DISCOJUICE_POPUP_CACHE_NAME) === true) {
176187
this.popUpDiscoJuiceLogin();
177188
}
189+
this.storage.set(SHOW_DISCOJUICE_POPUP_CACHE_NAME, true);
178190
}
179191

180192
/**
@@ -243,4 +255,15 @@ export class LogInPasswordComponent implements OnInit {
243255
document?.getElementById('clarin-signon-discojuice')?.click();
244256
}, 250);
245257
}
258+
259+
/**
260+
* Set SHOW_DISCOJUICE_POPUP_CACHE_NAME to true because the discojuice login must be popped up on init
261+
* if it is loaded for the first time.
262+
* @private
263+
*/
264+
private initializeDiscoJuiceCache() {
265+
if (isEmpty(this.storage.get(SHOW_DISCOJUICE_POPUP_CACHE_NAME))) {
266+
this.storage.set(SHOW_DISCOJUICE_POPUP_CACHE_NAME, true);
267+
}
268+
}
246269
}

0 commit comments

Comments
 (0)