Skip to content

Commit

Permalink
✅ Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trickypr committed Mar 31, 2024
1 parent cfc56fa commit 7dde88a
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 5 deletions.
9 changes: 4 additions & 5 deletions apps/content/src/tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { manageTests } from './manager.js'
import { urlBox } from './tests/urlBox.test.js'

async function tests() {}
async function tests() {
await urlBox()
}

await manageTests(tests)

if (module.hot) {
module.hot.dispose(() => window.location.reload())
}
82 changes: 82 additions & 0 deletions apps/content/src/tests/tests/urlBox.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { test } from 'zora'

import { getFastAutocomplete } from '../../browser/components/urlBox.js'

export async function urlBox() {
test('Fast autocomplete', (test) => {
test.test('URL: google.com', (test) => {
const result = getFastAutocomplete('google.com')
test.ok(result, 'result exists')
test.ok(result.length > 0, 'result has length')
test.equal(result[0]?.display, 'https://google.com', 'title is correct')
test.equal(result[0]?.url, 'https://google.com', 'url is correct')
test.equal(result[1]?.display, 'google.com', 'title is correct')
test.equal(
result[1]?.url,
'https://duckduckgo.com/?q=google.com',
'url is correct',
)
})

test.test('URL: https://google.com', (test) => {
const result = getFastAutocomplete('https://google.com')
test.ok(result, 'result exists')
test.ok(result.length > 0, 'result has length')
test.equal(result[0]?.display, 'https://google.com', 'title is correct')
test.equal(result[0]?.url, 'https://google.com', 'url is correct')
test.equal(result[1]?.display, 'https://google.com', 'title is correct')
test.equal(
result[1]?.url,
'https://duckduckgo.com/?q=https://google.com',
'url is correct',
)
})

test.test('URL: google.com/test', (test) => {
const result = getFastAutocomplete('google.com/test')
test.ok(result, 'result exists')
test.ok(result.length > 0, 'result has length')
test.equal(
result[0]?.display,
'https://google.com/test',
'title is correct',
)
test.equal(result[0]?.url, 'https://google.com/test', 'url is correct')
test.equal(result[1]?.display, 'google.com/test', 'title is correct')
test.equal(
result[1]?.url,
'https://duckduckgo.com/?q=google.com/test',
'url is correct',
)
})

test.test('URLProvider: https://abc.notarealurl/test', (test) => {
const result = getFastAutocomplete('https://abc.notarealurl/test')
test.ok(result, 'result exists')
test.equal(result.length, 1, 'result has length')
test.equal(
result[0]?.display,
'https://abc.notarealurl/test',
'title is correct',
)
test.equal(
result[0]?.url,
'https://duckduckgo.com/?q=https://abc.notarealurl/test',
'url is correct',
)
})

test.test('URLProvider: about:blank', (test) => {
const result = getFastAutocomplete('about:blank')
test.eq(result.length, 2, 'There should be 2 result')
test.eq(result[0]?.display, 'about:blank', 'The title should be correct')
test.eq(result[0]?.url, 'about:blank', 'The url should be correct')
test.eq(result[1]?.display, 'about:blank', 'The title should be correct')
test.eq(
result[1]?.url,
'https://duckduckgo.com/?q=about:blank',
'The url should be correct',
)
})
})
}

0 comments on commit 7dde88a

Please sign in to comment.