All checks were successful
Deploy production / deploy (push) Successful in 1m10s
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { errorCopy, suggestPages } from './errors';
|
|
|
|
const hrefs = (path: string, owner = false) => suggestPages(path, owner).map((s) => s.href);
|
|
|
|
describe('errorCopy', () => {
|
|
it('has copy per status family', () => {
|
|
expect(errorCopy(404).tone).toBe('missing');
|
|
expect(errorCopy(403).title).toBe('Owner only');
|
|
expect(errorCopy(500).tone).toBe('broken');
|
|
expect(errorCopy(503).tone).toBe('down');
|
|
});
|
|
});
|
|
|
|
describe('suggestPages', () => {
|
|
it('suggests the parent tracker for a missing detail page', () => {
|
|
expect(hrefs('/trackers/cars/does-not-exist')[0]).toBe('/trackers/cars');
|
|
});
|
|
it('fixes typos in tracker names', () => {
|
|
expect(hrefs('/trackers/bokos')).toContain('/trackers/books');
|
|
expect(hrefs('/trakcers/trians')).toContain('/trackers/trains');
|
|
});
|
|
it('finds a tracker by name under the wrong section', () => {
|
|
expect(hrefs('/projects/planes')).toContain('/trackers/planes');
|
|
});
|
|
it('never suggests private trackers to visitors', () => {
|
|
expect(hrefs('/trackers/helth')).not.toContain('/trackers/health');
|
|
expect(hrefs('/trackers/helth', true)).toContain('/trackers/health');
|
|
});
|
|
it('ranks the tracker above the section it lives in', () => {
|
|
expect(hrefs('/trackers/carz')[0]).toBe('/trackers/cars');
|
|
expect(hrefs('/trackers/doesnotexist')).not.toContain('/trackers');
|
|
});
|
|
it('returns nothing for the home page or noise', () => {
|
|
expect(hrefs('/')).toEqual([]);
|
|
expect(hrefs('/zzqxj')).toEqual([]);
|
|
});
|
|
});
|