mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 03:57:52 +00:00
@@ -7,17 +7,24 @@ export const formatCampaigns = ({ campaigns }) => {
|
||||
return campaigns.map(item => {
|
||||
return {
|
||||
id: item.id,
|
||||
triggerOnlyDuringBusinessHours:
|
||||
item.trigger_only_during_business_hours || false,
|
||||
timeOnPage: item?.trigger_rules?.time_on_page,
|
||||
url: item?.trigger_rules?.url,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
// Find all campaigns that matches the current URL
|
||||
export const filterCampaigns = ({ campaigns, currentURL }) => {
|
||||
return campaigns.filter(
|
||||
item =>
|
||||
stripTrailingSlash({ URL: item.url }) ===
|
||||
stripTrailingSlash({ URL: currentURL })
|
||||
// Filter all campaigns based on current URL and business availability time
|
||||
export const filterCampaigns = ({
|
||||
campaigns,
|
||||
currentURL,
|
||||
isInBusinessHours,
|
||||
}) => {
|
||||
return campaigns.filter(item =>
|
||||
item.triggerOnlyDuringBusinessHours
|
||||
? isInBusinessHours
|
||||
: stripTrailingSlash({ URL: item.url }) ===
|
||||
stripTrailingSlash({ URL: currentURL })
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export default [
|
||||
{
|
||||
id: 1,
|
||||
trigger_only_during_business_hours: false,
|
||||
trigger_rules: {
|
||||
time_on_page: 3,
|
||||
url: 'https://www.chatwoot.com/pricing',
|
||||
@@ -8,6 +9,7 @@ export default [
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
trigger_only_during_business_hours: false,
|
||||
trigger_rules: {
|
||||
time_on_page: 6,
|
||||
url: 'https://www.chatwoot.com/about',
|
||||
@@ -3,8 +3,12 @@ import {
|
||||
formatCampaigns,
|
||||
filterCampaigns,
|
||||
} from '../campaignHelper';
|
||||
import campaigns from './camapginFixtures';
|
||||
describe('#Campagin Helper', () => {
|
||||
import campaigns from './campaignFixtures';
|
||||
|
||||
global.chatwootWebChannel = {
|
||||
workingHoursEnabled: false,
|
||||
};
|
||||
describe('#Campaigns Helper', () => {
|
||||
describe('stripTrailingSlash', () => {
|
||||
it('should return striped trailing slash if url with trailing slash is passed', () => {
|
||||
expect(
|
||||
@@ -14,15 +18,17 @@ describe('#Campagin Helper', () => {
|
||||
});
|
||||
|
||||
describe('formatCampaigns', () => {
|
||||
it('should return formated campaigns if camapgins are passed', () => {
|
||||
it('should return formatted campaigns if campaigns are passed', () => {
|
||||
expect(formatCampaigns({ campaigns })).toStrictEqual([
|
||||
{
|
||||
id: 1,
|
||||
timeOnPage: 3,
|
||||
triggerOnlyDuringBusinessHours: false,
|
||||
url: 'https://www.chatwoot.com/pricing',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
triggerOnlyDuringBusinessHours: false,
|
||||
timeOnPage: 6,
|
||||
url: 'https://www.chatwoot.com/about',
|
||||
},
|
||||
@@ -30,7 +36,7 @@ describe('#Campagin Helper', () => {
|
||||
});
|
||||
});
|
||||
describe('filterCampaigns', () => {
|
||||
it('should return filtered campaigns if formatted camapgins are passed', () => {
|
||||
it('should return filtered campaigns if formatted campaigns are passed', () => {
|
||||
expect(
|
||||
filterCampaigns({
|
||||
campaigns: [
|
||||
|
||||
Reference in New Issue
Block a user