2021-05-17 16:08:35 +00:00
|
|
|
import {
|
|
|
|
formatCampaigns,
|
|
|
|
filterCampaigns,
|
2022-12-10 00:43:09 +00:00
|
|
|
isPatternMatchingWithURL,
|
2021-05-17 16:08:35 +00:00
|
|
|
} from '../campaignHelper';
|
2021-10-12 12:28:33 +00:00
|
|
|
import campaigns from './campaignFixtures';
|
|
|
|
|
|
|
|
global.chatwootWebChannel = {
|
|
|
|
workingHoursEnabled: false,
|
|
|
|
};
|
|
|
|
describe('#Campaigns Helper', () => {
|
2022-12-10 00:43:09 +00:00
|
|
|
describe('#isPatternMatchingWithURL', () => {
|
|
|
|
it('returns correct value if a valid URL is passed', () => {
|
2021-05-17 16:08:35 +00:00
|
|
|
expect(
|
2022-12-10 00:43:09 +00:00
|
|
|
isPatternMatchingWithURL(
|
|
|
|
'https://chatwoot.com/pricing*',
|
|
|
|
'https://chatwoot.com/pricing/'
|
|
|
|
)
|
|
|
|
).toBe(true);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
isPatternMatchingWithURL(
|
|
|
|
'https://*.chatwoot.com/pricing/',
|
|
|
|
'https://app.chatwoot.com/pricing/'
|
|
|
|
)
|
|
|
|
).toBe(true);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
isPatternMatchingWithURL(
|
|
|
|
'https://{*.}?chatwoot.com/pricing?test=true',
|
|
|
|
'https://app.chatwoot.com/pricing/?test=true'
|
|
|
|
)
|
|
|
|
).toBe(true);
|
|
|
|
|
|
|
|
expect(
|
|
|
|
isPatternMatchingWithURL(
|
|
|
|
'https://{*.}?chatwoot.com/pricing*\\?*',
|
|
|
|
'https://chatwoot.com/pricing/?test=true'
|
|
|
|
)
|
|
|
|
).toBe(true);
|
2021-05-17 16:08:35 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('formatCampaigns', () => {
|
2021-10-12 12:28:33 +00:00
|
|
|
it('should return formatted campaigns if campaigns are passed', () => {
|
2021-05-18 06:45:23 +00:00
|
|
|
expect(formatCampaigns({ campaigns })).toStrictEqual([
|
2021-05-17 16:08:35 +00:00
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
timeOnPage: 3,
|
2021-10-12 12:28:33 +00:00
|
|
|
triggerOnlyDuringBusinessHours: false,
|
2021-05-17 16:08:35 +00:00
|
|
|
url: 'https://www.chatwoot.com/pricing',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
2021-10-12 12:28:33 +00:00
|
|
|
triggerOnlyDuringBusinessHours: false,
|
2021-05-17 16:08:35 +00:00
|
|
|
timeOnPage: 6,
|
|
|
|
url: 'https://www.chatwoot.com/about',
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('filterCampaigns', () => {
|
2021-10-12 12:28:33 +00:00
|
|
|
it('should return filtered campaigns if formatted campaigns are passed', () => {
|
2021-05-17 16:08:35 +00:00
|
|
|
expect(
|
|
|
|
filterCampaigns({
|
2021-05-18 06:45:23 +00:00
|
|
|
campaigns: [
|
2021-05-17 16:08:35 +00:00
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
timeOnPage: 3,
|
|
|
|
url: 'https://www.chatwoot.com/pricing',
|
2021-11-22 18:02:17 +00:00
|
|
|
triggerOnlyDuringBusinessHours: false,
|
2021-05-17 16:08:35 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
timeOnPage: 6,
|
|
|
|
url: 'https://www.chatwoot.com/about',
|
2021-11-22 18:02:17 +00:00
|
|
|
triggerOnlyDuringBusinessHours: false,
|
2021-05-17 16:08:35 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
currentURL: 'https://www.chatwoot.com/about/',
|
|
|
|
})
|
|
|
|
).toStrictEqual([
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
timeOnPage: 6,
|
|
|
|
url: 'https://www.chatwoot.com/about',
|
2021-11-22 18:02:17 +00:00
|
|
|
triggerOnlyDuringBusinessHours: false,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
it('should return filtered campaigns if formatted campaigns are passed and business hours enabled', () => {
|
|
|
|
expect(
|
|
|
|
filterCampaigns({
|
|
|
|
campaigns: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
timeOnPage: 3,
|
|
|
|
url: 'https://www.chatwoot.com/pricing',
|
|
|
|
triggerOnlyDuringBusinessHours: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
timeOnPage: 6,
|
|
|
|
url: 'https://www.chatwoot.com/about',
|
|
|
|
triggerOnlyDuringBusinessHours: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
currentURL: 'https://www.chatwoot.com/about/',
|
|
|
|
isInBusinessHours: true,
|
|
|
|
})
|
|
|
|
).toStrictEqual([
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
timeOnPage: 6,
|
|
|
|
url: 'https://www.chatwoot.com/about',
|
|
|
|
triggerOnlyDuringBusinessHours: true,
|
2021-05-17 16:08:35 +00:00
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
2021-11-22 18:02:17 +00:00
|
|
|
it('should return empty campaigns if formatted campaigns are passed and business hours disabled', () => {
|
|
|
|
expect(
|
|
|
|
filterCampaigns({
|
|
|
|
campaigns: [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
timeOnPage: 3,
|
|
|
|
url: 'https://www.chatwoot.com/pricing',
|
|
|
|
triggerOnlyDuringBusinessHours: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
timeOnPage: 6,
|
|
|
|
url: 'https://www.chatwoot.com/about',
|
|
|
|
triggerOnlyDuringBusinessHours: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
currentURL: 'https://www.chatwoot.com/about/',
|
|
|
|
isInBusinessHours: false,
|
|
|
|
})
|
|
|
|
).toStrictEqual([]);
|
|
|
|
});
|
2021-05-17 16:08:35 +00:00
|
|
|
});
|
|
|
|
});
|