Skip to content

Commit

Permalink
resolved comments and fixed test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruv036 committed Oct 12, 2023
1 parent a50c7b1 commit 00d0917
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
35 changes: 25 additions & 10 deletions __test__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const puppeteer = require('puppeteer');
const timeout = 25000;
const checkDialog = require('../js/index');

describe('Dummy Test ', () => {
beforeAll(async () => {
Expand All @@ -25,15 +24,31 @@ describe('Dummy Test ', () => {
);
});

describe('index function test case', () => {
test('should show dialog if open in phone', () => {
const regexp = /android|iphone|kindle|ipad/i; // for Mobile phone
const result = checkDialog(regexp);
expect(result).toBe('true');
describe('Test index function ', () => {
beforeAll(async () => {
browser = await puppeteer.launch({
headless: 'new',
});
page = await browser.newPage();
await page.goto('https://www.realdevsquad.com/', {
waitUntil: 'domcontentloaded',
});
});
test(`don't show dialog if not open in phone`, () => {
const regexp = /Windows|macOS|/i; // for PC
const result = checkDialog(regexp);
expect(result).toBe('false');

afterAll(async () => {
await browser.close();
});

test(
'Dialog close',
async () => {
let dialogOpened = false;
page.on('dialog', async (dialog) => {
dialogOpened = true;
await dialog.dismiss();
});
expect(dialogOpened).toBe(false);
},
timeout,
);
});
13 changes: 8 additions & 5 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ let memberSection = document.getElementById('members');
let regexp = /android|iphone|kindle|ipad/i;
isOpenInPhone(regexp);

export function isOpenInPhone(type) {
function isOpenInPhone(type) {
let details = navigator.userAgent;
let isMobileDevice = type.test(details);

if (isMobileDevice) {
openDialog();
document.getElementById('okayBt').addEventListener('click', openApp);
document.getElementById('okayBt').addEventListener('click', openRDSApp);
document.getElementById('cancleBt').addEventListener('click', closeDialog);
return true;
} else {
Expand All @@ -43,7 +43,7 @@ function openRDSApp() {
var flag = false;
var appScheme = 'app://realdevsquad.com';
var fallbackURL =
'https://play.google.com/store/apps/details?id=com.github.android'; // It will replace with app playstore url
'https://play.google.com/store/apps/details?id=com.github.android'; // For demo. It will replace with app playstore url

var userAgent = navigator.userAgent || navigator.vendor || window.opera;
if (/android/i.test(userAgent)) {
Expand All @@ -66,10 +66,10 @@ function openRDSApp() {
document.body.removeChild(iframe);
window.location.href = fallbackURL;
}
}, 1000); // Adjust the delay as needed
}, 1000);
} else {
// If the user is not on an Android device, provide a fallback action
window.location.href = fallbackURL; // Replace with your fallback URL
window.location.href = fallbackURL;
}
}

Expand Down Expand Up @@ -162,3 +162,6 @@ modalTriggers.forEach((trigger) => {
});
});
});
module.exports = {
isOpenInPhone,
};

0 comments on commit 00d0917

Please sign in to comment.