Skip to content

Commit

Permalink
test: test scenarios without user agents
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahdayan committed Jun 24, 2022
1 parent b1f9435 commit 18e7694
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/autocomplete-core/src/__tests__/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ describe('metadata', () => {
expect(document.head).toMatchInlineSnapshot(`<head />`);
});

test('does not enable metadata with a window but no navigator', async () => {
createPlayground(createAutocomplete, {
environment: {
...createEnvironmentWithUserAgent(),
navigator: undefined,
},
});

await defer(noop, 0);

expect(document.head).toMatchInlineSnapshot(`<head />`);
});

test("does not enable metadata when navigator is different from browser's (React Native)", async () => {
createPlayground(createAutocomplete, {
environment: createEnvironmentWithUserAgent(),
});

await defer(noop, 0);

expect(document.head).toMatchInlineSnapshot(`<head />`);
});

test('enables metadata with Algolia Crawler user agents', async () => {
createPlayground(createAutocomplete, {
environment: algoliaCrawlerEnvironment,
Expand Down Expand Up @@ -158,7 +181,7 @@ describe('metadata', () => {
});
});

function createEnvironmentWithUserAgent(userAgent: string) {
function createEnvironmentWithUserAgent(userAgent?: string) {
return {
...global,
navigator: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,8 @@ describe('isSamsung', () => {
});
});
});

test('returns false with an empty user agent', () => {
expect(isSamsung('')).toEqual(false);
});
});

0 comments on commit 18e7694

Please sign in to comment.