Skip to content

Commit f9fb86d

Browse files
authored
test: add third party service test (#440)
1 parent abed912 commit f9fb86d

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

test/steps/IframeWidget.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,22 @@ export class IframeWidget {
138138
const value = await this._widgetIframe.$eval('input[name="receiver"]', (el) => el.value);
139139
return value;
140140
}
141+
142+
async getServiceNameInAuthorizationSettings() {
143+
await this.waitFor('.AuthorizeSettingsSection_serviceName');
144+
const text = await this._widgetIframe.$eval('.AuthorizeSettingsSection_serviceName', (el) => el.innerText);
145+
return text;
146+
}
147+
148+
async getContactFilters() {
149+
await this.waitFor('.ContactSourceFilter_filterIconContainer');
150+
await this._widgetIframe.click('.ContactSourceFilter_filterIconContainer');
151+
const text = await this._widgetIframe.$eval('.ContactSourceFilter_contactSourceList', (el) => el.innerText);
152+
return text;
153+
}
154+
155+
async getContactNames() {
156+
const texts = await this._widgetIframe.$$eval('.ContactItem_contactName', els => els.map(el => el.textContent));
157+
return texts;
158+
}
141159
}

test/widget.test.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if (!hasUserLoginInfo) {
1010
}
1111
const conditionalDescribe = !hasUserLoginInfo ? describe.skip : describe;
1212

13-
conditionalDescribe('Index page test', () => {
13+
conditionalDescribe('widget page test', () => {
1414
let widgetIframe;
1515

1616
beforeAll(async () => {
@@ -76,4 +76,60 @@ conditionalDescribe('Index page test', () => {
7676
const headerLabel = await widgetIframe.getHeaderLabel();
7777
expect(headerLabel).toEqual('Calling');
7878
});
79+
80+
it('should register service successfully', async () => {
81+
await widgetIframe.clickNavigationButton('More Menu');
82+
await widgetIframe.clickDropdownNavigationMenu('Settings');
83+
await page.evaluate(() => {
84+
const iframe = document.querySelector("#rc-widget-adapter-frame").contentWindow;
85+
window.addEventListener('message', function (e) {
86+
var data = e.data;
87+
if (data && data.type === 'rc-post-message-request') {
88+
if (data.path === '/contacts') {
89+
const contacts = [{
90+
id: '123456',
91+
name: 'TestService Name',
92+
type: 'TestService',
93+
phoneNumbers: [{
94+
phoneNumber: '+1234567890',
95+
phoneType: 'direct',
96+
}],
97+
company: 'CompanyName',
98+
jobTitle: 'Engineer',
99+
emails: ['[email protected]'],
100+
deleted: false,
101+
}];
102+
iframe.postMessage({
103+
type: 'rc-post-message-response',
104+
responseId: data.requestId,
105+
response: {
106+
data: contacts,
107+
nextPage: null,
108+
syncTimestamp: Date.now()
109+
},
110+
}, '*');
111+
}
112+
}
113+
});
114+
iframe.postMessage({
115+
type: 'rc-adapter-register-third-party-service',
116+
service: {
117+
name: 'TestService',
118+
authorizationPath: '/authorize',
119+
authorizedTitle: 'Unauthorize',
120+
unauthorizedTitle: 'Authorize',
121+
contactsPath: '/contacts',
122+
authorized: true,
123+
},
124+
}, '*');
125+
});
126+
const serviceName = await widgetIframe.getServiceNameInAuthorizationSettings();
127+
expect(serviceName).toEqual('TestService');
128+
await widgetIframe.clickNavigationButton('More Menu');
129+
await widgetIframe.clickDropdownNavigationMenu('Contacts');
130+
const contactsFilters = await widgetIframe.getContactFilters();
131+
expect(contactsFilters).toEqual(expect.stringContaining('TestService'));
132+
const contacts = await widgetIframe.getContactNames();
133+
expect(contacts).toEqual(expect.arrayContaining(['TestService Name']));
134+
});
79135
});

0 commit comments

Comments
 (0)