level_0
int64 0
10k
| index
int64 0
0
| repo_id
stringlengths 22
152
| file_path
stringlengths 41
203
| content
stringlengths 11
11.5M
|
---|---|---|---|---|
9,866 | 0 | petrpan-code/alibaba/ice/tests | petrpan-code/alibaba/ice/tests/integration/routes-generate.test.ts | import { expect, test, describe, afterAll } from 'vitest';
import { buildFixture, setupBrowser } from '../utils/build';
import { startFixture, setupStartBrowser } from '../utils/start';
import type { Page } from '../utils/browser';
import type Browser from '../utils/browser';
const example = 'routes-generate';
describe(`build ${example}`, () => {
let page: Page;
let browser: Browser;
test('open /', async () => {
await buildFixture(example);
const res = await setupBrowser({ example });
page = res.page;
browser = res.browser;
expect(await page.$$text('h1')).toStrictEqual(['Layout']);
expect(await page.$$text('h2')).toStrictEqual(['Home']);
});
test('define extra routes', async () => {
await page.push('/about-me.html');
expect(await page.$$text('h1')).toStrictEqual([]);
expect(await page.$$text('h2')).toStrictEqual(['About']);
await page.push('/product.html');
expect(await page.$$text('h1')).toStrictEqual(['Layout']);
expect(await page.$$text('h2')).toStrictEqual(['Products Page']);
});
test('page layout', async () => {
await page.push('/dashboard/a.html');
expect(await page.$$text('h1')).toStrictEqual(['Layout']);
expect(await page.$$text('h2')).toStrictEqual(['Dashboard']);
expect(await page.$$text('h3')).toStrictEqual(['A page']);
await page.push('/dashboard/b.html');
expect(await page.$$text('h1')).toStrictEqual(['Layout']);
expect(await page.$$text('h2')).toStrictEqual(['Dashboard']);
expect(await page.$$text('h3')).toStrictEqual(['B page']);
});
// TODO: dynamic-routes test
test.todo('dynamic routes', async () => {});
afterAll(async () => {
await browser.close();
});
});
describe(`start ${example}`, () => {
let page: Page;
let browser: Browser;
test('open /', async () => {
const { devServer, port } = await startFixture(example);
const res = await setupStartBrowser({ server: devServer, port });
page = res.page;
browser = res.browser;
expect(await page.$$text('h1')).toStrictEqual(['Layout']);
expect(await page.$$text('h2')).toStrictEqual(['Home']);
});
test('define extra routes', async () => {
await page.push('/about-me');
expect(await page.$$text('h1')).toStrictEqual([]);
expect(await page.$$text('h2')).toStrictEqual(['About']);
await page.push('/product');
expect(await page.$$text('h1')).toStrictEqual(['Layout']);
expect(await page.$$text('h2')).toStrictEqual(['Products Page']);
});
test('page layout', async () => {
await page.push('/dashboard/a');
expect(await page.$$text('h1')).toStrictEqual(['Layout']);
expect(await page.$$text('h2')).toStrictEqual(['Dashboard']);
expect(await page.$$text('h3')).toStrictEqual(['A page']);
await page.push('/dashboard/b');
expect(await page.$$text('h1')).toStrictEqual(['Layout']);
expect(await page.$$text('h2')).toStrictEqual(['Dashboard']);
expect(await page.$$text('h3')).toStrictEqual(['B page']);
});
test('dynamic routes layout', async () => {
await page.push('/detail/a');
expect(await page.$$text('h1')).toStrictEqual(['Layout']);
expect(await page.$$text('h2')).toStrictEqual(['Detail id: a']);
await page.push('/detail/b');
expect(await page.$$text('h1')).toStrictEqual(['Layout']);
expect(await page.$$text('h2')).toStrictEqual(['Detail id: b']);
});
afterAll(async () => {
await browser.close();
});
});
|
9,867 | 0 | petrpan-code/alibaba/ice/tests | petrpan-code/alibaba/ice/tests/integration/single-router.test.ts | import * as path from 'path';
import * as fs from 'fs';
import { expect, test, describe, afterAll } from 'vitest';
import { buildFixture } from '../utils/build';
const example = 'single-route';
describe(`build ${example}`, () => {
let sizeWithOptimize = 0;
let sizeWithoutOptimize = 0;
test('optimize router', async () => {
await buildFixture(example, {
config: 'optimization.config.mts',
});
const dataLoaderPath = path.join(__dirname, `../../examples/${example}/build/js/framework.js`);
sizeWithOptimize = fs.statSync(dataLoaderPath).size;
});
test('disable optimize router', async () => {
await buildFixture(example);
const dataLoaderPath = path.join(__dirname, `../../examples/${example}/build/js/framework.js`);
sizeWithoutOptimize = fs.statSync(dataLoaderPath).size;
});
afterAll(async () => {
expect(sizeWithOptimize).toBeLessThan(sizeWithoutOptimize);
expect(sizeWithoutOptimize - sizeWithOptimize).toBeGreaterThan(6 * 1024); // reduce more than 6kb after minify
});
});
|
9,868 | 0 | petrpan-code/alibaba/ice/tests | petrpan-code/alibaba/ice/tests/integration/with-antd-mobile.test.ts | import { expect, test, describe, afterAll } from 'vitest';
import { buildFixture, setupBrowser } from '../utils/build';
import type { Page } from '../utils/browser';
import type Browser from '../utils/browser';
const example = 'with-antd-mobile';
describe(`build ${example}`, () => {
let page: Page;
let browser: Browser;
test('open /', async () => {
await buildFixture(example);
const res = await setupBrowser({ example });
page = res.page;
browser = res.browser;
expect(await page.$$text('h2')).toStrictEqual(['Counter']);
});
afterAll(async () => {
await browser.close();
});
});
|
9,869 | 0 | petrpan-code/alibaba/ice/tests | petrpan-code/alibaba/ice/tests/integration/with-auth.test.ts | import { expect, test, describe, afterAll } from 'vitest';
import { buildFixture, setupBrowser } from '../utils/build';
import { startFixture, setupStartBrowser } from '../utils/start';
import type { Page } from '../utils/browser';
import type Browser from '../utils/browser';
const example = 'with-auth';
describe(`build ${example}`, () => {
let page: Page;
let browser: Browser;
test('open /', async () => {
await buildFixture(example);
const res = await setupBrowser({ example });
page = res.page;
browser = res.browser;
expect(await page.$$text('h1')).toStrictEqual(['Index']);
});
test('open /blog', async () => {
await page.push('/blog.html');
expect(await page.$$text('#no-auth')).toStrictEqual(['无权限访问']);
});
afterAll(async () => {
await browser.close();
});
});
describe(`start ${example}`, () => {
let page: Page;
let browser: Browser;
test('open /', async () => {
const { devServer, port } = await startFixture(example, {
mock: true,
force: true,
https: false,
analyzer: false,
open: false,
mode: 'start',
});
const res = await setupStartBrowser({ server: devServer, port });
page = res.page;
browser = res.browser;
expect(await page.$$text('h1')).toStrictEqual(['Index']);
});
test('open /blog', async () => {
await page.push('/blog');
expect(await page.$$text('#no-auth')).toStrictEqual(['无权限访问']);
});
afterAll(async () => {
await browser.close();
});
});
|
9,870 | 0 | petrpan-code/alibaba/ice/tests | petrpan-code/alibaba/ice/tests/integration/with-data-loader.test.ts | import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { expect, test, describe, afterAll } from 'vitest';
import { buildFixture } from '../utils/build';
import { startFixture, setupStartBrowser } from '../utils/start';
import type { Page } from '../utils/browser';
import type Browser from '../utils/browser';
// @ts-ignore
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const example = 'with-data-loader';
describe(`build ${example}`, () => {
test('data-loader build file', async () => {
await buildFixture(example);
const content = fs.readFileSync(path.join(__dirname, `../../examples/${example}/build/js/data-loader.js`), 'utf-8');
expect(content.includes('console.log("target, renderer:","web","client")')).toBe(true);
});
});
describe(`start ${example}`, () => {
let page: Page;
let browser: Browser;
test('should call data loader for each navigator', async () => {
const { devServer, port } = await startFixture(example, {
mock: true,
force: true,
https: false,
analyzer: false,
open: false,
mode: 'start',
});
const res = await setupStartBrowser({ server: devServer, port, defaultPath: '/blog1' });
page = res.page;
browser = res.browser;
const timeStampForRouter1 = (await page.$$text('#timestamp'))[0];
await page.push('/blog2');
await page.waitForNetworkIdle();
const timeStampForRouter2 = (await page.$$text('#timestamp'))[0];
await page.push('/blog1');
await page.waitForNetworkIdle();
const timeStampForRouter3 = (await page.$$text('#timestamp'))[0];
expect(timeStampForRouter2).not.toStrictEqual(timeStampForRouter1);
expect(timeStampForRouter3).not.toStrictEqual(timeStampForRouter1);
});
test('should work with deferred data loader', async () => {
await page.push('/with-defer-loader');
await page.waitForNetworkIdle();
const data = (await page.$$text('#itemId'))[0];
expect(data).toEqual('1233');
});
afterAll(async () => {
await browser.close();
});
});
|
9,871 | 0 | petrpan-code/alibaba/ice/tests | petrpan-code/alibaba/ice/tests/integration/with-i18n.test.ts | import * as path from 'path';
import glob from 'glob';
import { expect, test, describe, afterAll } from 'vitest';
import { buildFixture, setupBrowser } from '../utils/build';
import type { Page } from '../utils/browser';
import type Browser from '../utils/browser';
const example = 'with-i18n';
describe(`build ${example}`, () => {
let page: Page;
let browser: Browser;
test('generate html files with locales', async () => {
await buildFixture(example);
const res = await setupBrowser({ example, disableJS: false });
page = res.page;
browser = res.browser;
const distDir = path.join(__dirname, `../../examples/${example}/build`);
const htmlFiles = glob.sync('**/*.html', { cwd: distDir });
expect(htmlFiles).toEqual([
'blog.html',
'blog/a.html',
'en-US.html',
'en-US/blog.html',
'en-US/blog/a.html',
'index.html',
]);
});
test('visit / page and get the zh-CN locale page', async () => {
expect(await page.$$text('#button')).toStrictEqual(['普通按钮']);
});
test('visit /en-US page and get the en-US locale page', async () => {
await page.push('/en-US.html');
expect(await page.$$text('#button')).toStrictEqual(['Normal Button']);
});
afterAll(async () => {
await browser.close();
});
}); |
9,872 | 0 | petrpan-code/alibaba/ice/tests | petrpan-code/alibaba/ice/tests/integration/with-request.test.ts | import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { expect, test, describe } from 'vitest';
import { buildFixture } from '../utils/build';
// @ts-ignore
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const example = 'with-request';
describe(`build ${example}`, () => {
test('data-loader build file', async () => {
await buildFixture(example);
const content = fs.readFileSync(path.join(__dirname, `../../examples/${example}/build/js/data-loader.js`), 'utf-8');
expect(content.includes('react.element')).toBe(false);
});
});
|
9,873 | 0 | petrpan-code/alibaba/ice/tests | petrpan-code/alibaba/ice/tests/integration/with-ssg.test.ts | import { expect, test, describe, afterAll } from 'vitest';
import { startFixture, setupStartBrowser } from '../utils/start';
import type { Page } from '../utils/browser';
import type Browser from '../utils/browser';
const example = 'with-ssg';
describe(`start ${example}`, () => {
let page: Page;
let browser: Browser;
let serverPort;
test('open /', async () => {
const { devServer, port } = await startFixture(example, {
mock: true,
force: true,
https: false,
analyzer: false,
open: false,
mode: 'start',
});
serverPort = port;
const res = await setupStartBrowser({ server: devServer, port });
page = res.page;
browser = res.browser;
expect(await page.$$text('.price')).toStrictEqual(['99.99']);
});
test('disable hydrate', async () => {
const page = await browser.page(`http://127.0.0.1:${serverPort}`, '/', true);
expect(await page.$$text('.price')).toStrictEqual(['0.00']);
});
afterAll(async () => {
await browser.close();
});
});
|
9,874 | 0 | petrpan-code/alibaba/ice/tests | petrpan-code/alibaba/ice/tests/integration/with-store.test.ts | import * as path from 'path';
import * as fs from 'fs';
import { expect, test, describe, afterAll } from 'vitest';
import { buildFixture, setupBrowser } from '../utils/build';
import type { Page } from '../utils/browser';
import type Browser from '../utils/browser';
const example = 'with-store';
describe(`build ${example}`, () => {
let page: Page;
let browser: Browser;
test('open /', async () => {
await buildFixture(example);
const res = await setupBrowser({ example, disableJS: false });
page = res.page;
browser = res.browser;
await page.waitForFunction('document.getElementsByTagName(\'button\').length > 0');
expect(await page.$$text('#username')).toStrictEqual(['name: icejs']);
expect(await page.$$text('#count')).toStrictEqual(['0']);
const dataLoaderPath = path.join(__dirname, `../../examples/${example}/build/js/data-loader.js`);
// should not contain react
const dataLoaderContent = fs.readFileSync(dataLoaderPath, 'utf-8');
expect(dataLoaderContent.includes('createElement')).toBe(false);
// size of data loader should be less than 14kib
const stats = fs.statSync(dataLoaderPath);
expect(stats.size).toBeLessThan(1024 * 14);
});
afterAll(async () => {
await browser.close();
});
});
|
9,875 | 0 | petrpan-code/alibaba/ice/tests | petrpan-code/alibaba/ice/tests/integration/with-suspense-ssr.test.ts | import { expect, test, describe, afterAll } from 'vitest';
import { startFixture, setupStartBrowser } from '../utils/start';
import type { Page } from '../utils/browser';
import type Browser from '../utils/browser';
const example = 'with-suspense-ssr';
describe(`start ${example}`, () => {
let page: Page;
let browser: Browser;
let serverPort;
test('open /', async () => {
const { devServer, port } = await startFixture(example, {
mock: true,
force: true,
https: false,
analyzer: false,
open: false,
mode: 'start',
});
serverPort = port;
const res = await setupStartBrowser({ server: devServer, port });
page = res.page;
browser = res.browser;
expect(await page.$$text('h2')).toStrictEqual(['Home Page', 'Thanks for reading!']);
});
test('open /with-data-error', async () => {
const page = await browser.page(`http://127.0.0.1:${serverPort}`, '/with-data-error', false);
expect((await page.$$text('.comment')).length).toEqual(3);
});
test('open /with-data-error without hydrate', async () => {
const page = await browser.page(`http://127.0.0.1:${serverPort}`, '/with-data-error', true);
expect((await page.$$text('.comment')).length).toEqual(0);
});
test('open /with-render-error', async () => {
const page = await browser.page(`http://127.0.0.1:${serverPort}`, '/with-render-error', false);
expect((await page.$$text('.comment')).length).toEqual(3);
});
test('open /with-render-error without hydrate', async () => {
const page = await browser.page(`http://127.0.0.1:${serverPort}`, '/with-render-error', true);
expect((await page.$$text('.comment')).length).toEqual(0);
});
test('open /with-fallback', async () => {
const page = await browser.page(`http://127.0.0.1:${serverPort}`, '/with-fallback', false);
expect(await page.$$text('#fallback')).toStrictEqual(['Something went wrong.']);
});
afterAll(async () => {
await browser.close();
});
});
|
4 | 0 | petrpan-code/outline/outline/server | petrpan-code/outline/outline/server/utils/parseAttachmentIds.test.ts | import { expect } from "@jest/globals";
import { v4 as uuidv4 } from "uuid";
import env from "@server/env";
import parseAttachmentIds from "./parseAttachmentIds";
it("should return an empty array with no matches", () => {
expect(parseAttachmentIds(`some random text`).length).toBe(0);
});
it("should not return orphaned UUID's", () => {
const uuid = uuidv4();
expect(
parseAttachmentIds(`some random text with a uuid ${uuid}
`).length
).toBe(0);
});
it("should parse attachment ID from markdown", () => {
const uuid = uuidv4();
const results = parseAttachmentIds(
``
);
expect(results.length).toBe(1);
expect(results[0]).toBe(uuid);
});
it("should parse attachment ID from markdown with additional query params", () => {
const uuid = uuidv4();
const results = parseAttachmentIds(
``
);
expect(results.length).toBe(1);
expect(results[0]).toBe(uuid);
});
it("should parse attachment ID from markdown with fully qualified url", () => {
const uuid = uuidv4();
const results = parseAttachmentIds(
``
);
expect(results.length).toBe(1);
expect(results[0]).toBe(uuid);
});
it("should parse attachment ID from markdown with title", () => {
const uuid = uuidv4();
const results = parseAttachmentIds(
``
);
expect(results.length).toBe(1);
expect(results[0]).toBe(uuid);
});
it("should parse multiple attachment IDs from markdown", () => {
const uuid = uuidv4();
const uuid2 = uuidv4();
const results =
parseAttachmentIds(`
some text
`);
expect(results.length).toBe(2);
expect(results[0]).toBe(uuid);
expect(results[1]).toBe(uuid2);
});
it("should parse attachment ID from html", () => {
const uuid = uuidv4();
const results = parseAttachmentIds(
`<img src="/api/attachments.redirect?id=${uuid}" />`
);
expect(results.length).toBe(1);
expect(results[0]).toBe(uuid);
});
it("should parse attachment ID from html with fully qualified url", () => {
const uuid = uuidv4();
const results = parseAttachmentIds(
`<img src="${env.URL}/api/attachments.redirect?id=${uuid}" />`
);
expect(results.length).toBe(1);
expect(results[0]).toBe(uuid);
});
|
6 | 0 | petrpan-code/outline/outline/server | petrpan-code/outline/outline/server/utils/parseDocumentIds.test.ts | import parseDocumentIds from "./parseDocumentIds";
it("should not return non links", () => {
expect(parseDocumentIds(`# Header`).length).toBe(0);
});
it("should return an array of document ids", () => {
const result = parseDocumentIds(`# Header
[internal](http://app.getoutline.com/doc/test-456733)
More text
[internal](/doc/test-123456#heading-anchor)
`);
expect(result.length).toBe(2);
expect(result[0]).toBe("test-456733");
expect(result[1]).toBe("test-123456");
});
it("should return deeply nested link document ids", () => {
const result = parseDocumentIds(`# Header
[internal](http://app.getoutline.com/doc/test-456733)
More text
- one
- two
- three [internal](/doc/test-123456#heading-anchor)
`);
expect(result.length).toBe(2);
expect(result[0]).toBe("test-456733");
expect(result[1]).toBe("test-123456");
});
it("should not return duplicate document ids", () => {
expect(parseDocumentIds(`# Header`).length).toBe(0);
const result = parseDocumentIds(`# Header
[internal](/doc/test-456733)
[another link to the same doc](/doc/test-456733)
`);
expect(result.length).toBe(1);
expect(result[0]).toBe("test-456733");
});
it("should not return non document links", () => {
expect(parseDocumentIds(`[google](http://www.google.com)`).length).toBe(0);
});
it("should not return non document relative links", () => {
expect(parseDocumentIds(`[relative](/developers)`).length).toBe(0);
});
|
8 | 0 | petrpan-code/outline/outline/server | petrpan-code/outline/outline/server/utils/parseImages.test.ts | import parseImages from "./parseImages";
it("should not return non images", () => {
expect(parseImages(`# Header`).length).toBe(0);
});
it("should return an array of images", () => {
const result = parseImages(`# Header

`);
expect(result.length).toBe(1);
expect(result[0].alt).toBe("internal");
expect(result[0].src).toBe("/attachments/image.png");
});
it("should return deeply nested images", () => {
const result = parseImages(`# Header
- one
- two
- three 
`);
expect(result.length).toBe(1);
expect(result[0].alt).toBe("oh my");
expect(result[0].src).toBe("/attachments/image.png");
});
it("should not return non document links", () => {
expect(parseImages(`[google](http://www.google.com)`).length).toBe(0);
});
it("should not return non document relative links", () => {
expect(parseImages(`[relative](/developers)`).length).toBe(0);
});
|
69 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Abstract.test.ts | import Abstract from "./Abstract";
describe("Abstract", () => {
const match = Abstract.ENABLED[0];
const match2 = Abstract.ENABLED[1];
test("to be enabled on share subdomain link", () => {
expect(
"https://share.goabstract.com/aaec8bba-f473-4f64-96e7-bff41c70ff8a".match(
match
)
).toBeTruthy();
expect(
"https://share.abstract.com/aaec8bba-f473-4f64-96e7-bff41c70ff8a".match(
match
)
).toBeTruthy();
});
test("to be enabled on share link", () => {
expect(
"https://app.goabstract.com/share/aaec8bba-f473-4f64-96e7-bff41c70ff8a".match(
match2
)
).toBeTruthy();
expect(
"https://app.abstract.com/share/aaec8bba-f473-4f64-96e7-bff41c70ff8a".match(
match2
)
).toBeTruthy();
});
test("to be enabled on embed link", () => {
expect(
"https://app.goabstract.com/embed/aaec8bba-f473-4f64-96e7-bff41c70ff8a".match(
match2
)
).toBeTruthy();
expect(
"https://app.abstract.com/embed/aaec8bba-f473-4f64-96e7-bff41c70ff8a".match(
match2
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://sharedgoabstract.com/f473".match(match)).toBe(null);
expect("https://share.goabstractacom/f473".match(match)).toBe(null);
expect("https://app1goabstract.com/share/f473".match(match2)).toBe(null);
expect("https://app.goabstractacom/share/f473".match(match2)).toBe(null);
expect("https://abstract.com".match(match)).toBe(null);
expect("https://goabstract.com".match(match)).toBe(null);
expect("https://app.goabstract.com".match(match)).toBe(null);
expect("https://abstract.com/features".match(match)).toBe(null);
expect("https://app.abstract.com/home".match(match)).toBe(null);
expect("https://abstract.com/pricing".match(match)).toBe(null);
expect("https://goabstract.com/pricing".match(match)).toBe(null);
expect("https://www.goabstract.com/pricing".match(match)).toBe(null);
});
});
|
71 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Airtable.test.ts | import Airtable from "./Airtable";
describe("Airtable", () => {
const match = Airtable.ENABLED[0];
test("to be enabled on share link", () => {
expect("https://airtable.com/shrEoQs3erLnppMie".match(match)).toBeTruthy();
expect(
"https://airtable.com/shrEoQs3erLnppMie/tbl232i54yebXpr1J".match(match)
).toBeTruthy();
expect(
"https://airtable.com/app0lrLlMprqMbz11/shrEoQs3erLnppMie/tbl232i54yebXpr1J".match(
match
)
).toBeTruthy();
});
test("to be enabled on embed link", () => {
expect(
"https://airtable.com/embed/shrEoQs3erLnppMie".match(match)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://airtable.com".match(match)).toBe(null);
expect("https://airtable.com/features".match(match)).toBe(null);
expect("https://airtable.com/pricing".match(match)).toBe(null);
});
});
|
73 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Berrycast.test.ts | import Berrycast from "./Berrycast";
describe("Berrycast", () => {
Berrycast.ENABLED[0];
// TODO
test.todo("");
});
|
75 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Bilibili.test.ts | import Bilibili from "./Bilibili";
describe("Bilibili", () => {
const match = Bilibili.ENABLED[0];
test("to be enabled on video link", () => {
expect(
"https://www.bilibili.com/video/BV1CV411s7jd?spm_id_from=333.999.0.0".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://youtu.be".match(match)).toBe(null);
expect("https://bilibili.com".match(match)).toBe(null);
expect("https://www.bilibili.com".match(match)).toBe(null);
expect("https://www.bilibili.com/logout".match(match)).toBe(null);
expect("https://www.bilibili.com/feed/subscriptions".match(match)).toBe(
null
);
});
});
|
78 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Cawemo.test.ts | import Cawemo from "./Cawemo";
describe("Cawemo", () => {
const match = Cawemo.ENABLED[0];
test("to be enabled on embed link", () => {
expect(
"https://cawemo.com/embed/a82e9f22-e283-4253-8d11".match(match)
).toBeTruthy();
});
test("to be enabled on share link", () => {
expect(
"https://cawemo.com/embed/a82e9f22-e283-4253-8d11".match(match)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://cawemo.com/".match(match)).toBe(null);
expect("https://cawemo.com/diagrams".match(match)).toBe(null);
});
});
|
80 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/ClickUp.test.ts | import ClickUp from "./ClickUp";
describe("ClickUp", () => {
const match = ClickUp.ENABLED[0];
test("to be enabled on share link", () => {
expect(
"https://share.clickup.com/b/h/6-9310960-2/c9d837d74182317".match(match)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://share.clickup.com".match(match)).toBe(null);
expect("https://sharedclickup.com/a/b/c/d".match(match)).toBe(null);
expect("https://share.clickupdcom/a/b/c/d".match(match)).toBe(null);
expect("https://clickup.com/".match(match)).toBe(null);
expect("https://clickup.com/features".match(match)).toBe(null);
});
});
|
82 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Codepen.test.ts | import Codepen from "./Codepen";
describe("Codepen", () => {
const match = Codepen.ENABLED[0];
test("to be enabled on pen link", () => {
expect(
"https://codepen.io/chriscoyier/pen/gfdDu".match(match)
).toBeTruthy();
});
test("to be enabled on embed link", () => {
expect(
"https://codepen.io/chriscoyier/embed/gfdDu".match(match)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://codepen.io".match(match)).toBe(null);
expect("https://codepen.io/chriscoyier".match(match)).toBe(null);
});
});
|
84 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/DBDiagram.test.ts | import DBDiagram from "./DBDiagram";
describe("DBDiagram", () => {
DBDiagram.ENABLED[0];
// TODO
test.todo("");
});
|
86 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Descript.test.ts | import Descript from "./Descript";
describe("Descript", () => {
const match = Descript.ENABLED[0];
test("to not be enabled elsewhere", () => {
expect("https://shareddescript.com/view/c9d8".match(match)).toBe(null);
expect("https://share.descriptdcom/view/c9d8".match(match)).toBe(null);
});
});
|
88 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Diagrams.test.ts | import Diagrams from "./Diagrams";
describe("Diagrams", () => {
const match = Diagrams.ENABLED[0];
test("to be enabled on viewer link", () => {
expect(
"https://viewer.diagrams.net/?target=blank&nav=1#ABCDefgh_A12345-6789".match(
match
)
).toBeTruthy();
});
test("to not be enabled on the proxy path", () => {
expect("https://app.diagrams.net/proxy?url=malicious".match(match)).toBe(
null
);
});
test("to not be enabled elsewhere", () => {
expect("https://app.diagrams.net/#ABCDefgh_A12345-6789".match(match)).toBe(
null
);
});
});
|
90 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Figma.test.ts | import Figma from "./Figma";
describe("Figma", () => {
const match = Figma.ENABLED[0];
test("to be enabled on file link", () => {
expect(
"https://www.figma.com/file/LKQ4FJ4bTnCSjedbRpk931".match(match)
).toBeTruthy();
});
test("to be enabled on prototype link", () => {
expect(
"https://www.figma.com/proto/LKQ4FJ4bTnCSjedbRpk931".match(match)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://www.figma.com".match(match)).toBe(null);
expect("https://www.figma.com/features".match(match)).toBe(null);
expect(
"https://wwww.figmaacom/file/LKQ4FJ4bTnCSjedbRpk931".match(match)
).toBe(null);
expect(
"https://wwwwfigma.com/file/LKQ4FJ4bTnCSjedbRpk931".match(match)
).toBe(null);
});
});
|
92 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Framer.test.ts | import Framer from "./Framer";
describe("Framer", () => {
const match = Framer.ENABLED[0];
test("to be enabled on share link", () => {
expect("https://framer.cloud/PVwJO".match(match)).toBeTruthy();
});
test("to not be enabled on root", () => {
expect("https://framer.cloud".match(match)).toBe(null);
});
});
|
94 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Gist.test.ts | import Gist from "./Gist";
describe("Gist", () => {
const match = Gist.ENABLED[0];
test("to be enabled on gist link", () => {
expect(
"https://gist.github.com/wmertens/0b4fd66ca7055fd290ecc4b9d95271a9".match(
match
)
).toBeTruthy();
expect(
"https://gist.github.com/n3n/eb51ada6308b539d388c8ff97711adfa".match(
match
)
).toBeTruthy();
expect(
"https://gist.github.com/ShubhanjanMedhi-dev/900c9c14093611898a4a085938bb90d9".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect(
"https://gistigithub.com/n3n/eb51ada6308b539d388c8ff97711adfa".match(
match
)
).toBe(null);
expect(
"https://gist.githubbcom/n3n/eb51ada6308b539d388c8ff97711adfa".match(
match
)
).toBe(null);
expect("https://gist.github.com/tommoor".match(match)).toBe(null);
});
});
|
96 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Gliffy.test.ts | import Gliffy from "./Gliffy";
describe("Gliffy", () => {
const match = Gliffy.ENABLED[0];
test("to not be enabled elsewhere", () => {
expect("https://gotgliffy.com/go/share/c9d837d74182317".match(match)).toBe(
null
);
expect("https://go.gliffyycom/go/share/c9d837d74182317".match(match)).toBe(
null
);
});
});
|
98 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/GoogleCalendar.test.ts | import GoogleCalendar from "./GoogleCalendar";
describe("GoogleCalendar", () => {
const match = GoogleCalendar.ENABLED[0];
test("to be enabled on share link", () => {
expect(
"https://calendar.google.com/calendar/embed?src=tom%40outline.com&ctz=America%2FSao_Paulo".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://calendar.google.com/calendar".match(match)).toBe(null);
expect("https://calendar.google.com".match(match)).toBe(null);
expect("https://www.google.com".match(match)).toBe(null);
expect(
"https://calendarrgoogle.com/calendar/embed?src=tom%40outline.com&ctz=America%2FSao_Paulo".match(
match
)
).toBe(null);
expect(
"https://calendar.googleecom/calendar/embed?src=tom%40outline.com&ctz=America%2FSao_Paulo".match(
match
)
).toBe(null);
});
});
|
100 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/GoogleDocs.test.ts | import GoogleDocs from "./GoogleDocs";
describe("GoogleDocs", () => {
const match = GoogleDocs.ENABLED[0];
test("to be enabled on share link", () => {
expect(
"https://docs.google.com/document/d/e/2PACX-1vTdddHPoZ5M_47wmSHCoigRIt2cj_Pd-kgtaNQY6H0Jzn0_CVGbxC1GcK5IoNzU615lzguexFwxasAW/pubhtml".match(
match
)
).toBeTruthy();
expect(
"https://docs.google.com/document/d/e/2PACX-1vTdddHPoZ5M_47wmSHCoigRIt2cj_Pd-kgtaNQY6H0Jzn0_CVGbxC1GcK5IoNzU615lzguexFwxasAW/pub".match(
match
)
).toBeTruthy();
expect(
"https://docs.google.com/document/d/1SsDfWzFFTjZM2LanvpyUzjKhqVQpwpTMeiPeYxhVqOg/edit".match(
match
)
).toBeTruthy();
expect(
"https://docs.google.com/document/d/1SsDfWzFFTjZM2LanvpyUzjKhqVQpwpTMeiPeYxhVqOg/preview".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://docs.google.com/document".match(match)).toBe(null);
expect("https://docs.google.com".match(match)).toBe(null);
expect("https://www.google.com".match(match)).toBe(null);
expect(
"https://docssgoogle.com/document/d/e/2PACX-1vTdddHPoZ5M_47wmSHCoigRIt2cj_Pd-kgtaNQY6H0Jzn0_CVGbxC1GcK5IoNzU615lzguexFwxasAW/pubhtml".match(
match
)
).toBe(null);
expect(
"https://docs.googleecom/document/d/e/2PACX-1vTdddHPoZ5M_47wmSHCoigRIt2cj_Pd-kgtaNQY6H0Jzn0_CVGbxC1GcK5IoNzU615lzguexFwxasAW/pubhtml".match(
match
)
).toBe(null);
});
});
|
102 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/GoogleDrawings.test.ts | import GoogleDrawings from "./GoogleDrawings";
describe("GoogleDrawings", () => {
const match = GoogleDrawings.ENABLED[0];
test("to be enabled on share link", () => {
expect(
"https://docs.google.com/drawings/d/1zELtJ4HSCnjGCGSoCgqGe3F8p6o7R8Vjk8MDR6dKf-U/edit".match(
match
)
).toBeTruthy();
expect(
"https://docs.google.com/drawings/d/1zELtJ4HSCnjGCGSoCgqGe3F8p6o7R8Vjk8MDR6dKf-U/edit?usp=sharing".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect(
"https://docs.google.com/drawings/d/e/2PACF-1vRtzIzEWN6svSrIYZq-kq2XZEN6WaOFXHbPKRLXNOFRlxLIdJg0Vo6RfretGqs9SzD-fUazLeS594Kw/pub?w=960&h=720".match(
match
)
).toBe(null);
expect("https://docs.google.com/drawings".match(match)).toBe(null);
expect("https://docs.google.com".match(match)).toBe(null);
expect("https://www.google.com".match(match)).toBe(null);
expect(
"https://docssgoogle.com/drawings/d/1zDMtJ4HSCnjGCGSoCgqGe3F8p6o7R8Vjk8MDR6dKf-U/edit".match(
match
)
).toBe(null);
expect(
"https://docs.googleecom/drawings/d/1zDMtJ4HSCnjGCGSoCgqGe3F8p6o7R8Vjk8MDR6dKf-U/edit".match(
match
)
).toBe(null);
});
});
|
104 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/GoogleDrive.test.ts | import GoogleDrive from "./GoogleDrive";
describe("GoogleDrive", () => {
const match = GoogleDrive.ENABLED[0];
test("to be enabled on share link", () => {
expect(
"https://drive.google.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/view?usp=sharing".match(
match
)
).toBeTruthy();
expect(
"https://drive.google.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/preview?usp=sharing".match(
match
)
).toBeTruthy();
expect(
"https://drive.google.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/preview?usp=sharing&resourceKey=BG8k4dEt1p2gisnVdlaSpA".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://drive.google.com/file".match(match)).toBe(null);
expect("https://drive.google.com".match(match)).toBe(null);
expect("https://www.google.com".match(match)).toBe(null);
expect(
"https://driveegoogle.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/view?usp=sharing".match(
match
)
).toBe(null);
expect(
"https://drive.googleecom/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/view?usp=sharing".match(
match
)
).toBe(null);
});
});
|
106 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/GoogleForms.test.ts | import GoogleForms from "./GoogleForms";
describe("GoogleForms", () => {
const match = GoogleForms.ENABLED[0];
test("to be enabled on long-form share links", () => {
expect(
"https://docs.google.com/forms/d/e/1FAIpQLSetbCGiE8DhfVQZMtLE_CU2MwpSsrkXi690hkEDREOvMu8VYQ/viewform?usp=sf_link".match(
match
)
).toBeTruthy();
expect(
"https://docs.google.com/forms/d/e/1FAIpQLSetbCGiE8DhfVQZMtLE_CU2MwpSsrkXi690hkEDREOvMu8VYQ/viewform".match(
match
)
).toBeTruthy();
expect(
"https://docs.google.com/forms/d/e/1FAIpQLSetbCGiE8DhfVQZMtLE_CU2MwpSsrkXi690hkEDREOvMu8VYQ/viewform?embedded=true".match(
match
)
).toBeTruthy();
});
test("to be enabled on edit links", () => {
expect(
"https://docs.google.com/forms/d/1zG75dmHQGpomQlWB6VtRhWajNer7mKMjtApM_aRAJV8/edit".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://docs.google.com/forms".match(match)).toBe(null);
expect("https://docs.google.com/forms/d/".match(match)).toBe(null);
expect("https://docs.google.com".match(match)).toBe(null);
expect("https://www.google.com".match(match)).toBe(null);
expect(
"https://docssgoogle.com/forms/d/e/1FAIpQLSetbCGiE8DhfVQZMtLE_CU2MwpSsrkXi690hkEDREOvMu8VYQ/viewform?usp=sf_link".match(
match
)
).toBe(null);
expect(
"https://docs.googleecom/forms/d/e/1FAIpQLSetbCGiE8DhfVQZMtLE_CU2MwpSsrkXi690hkEDREOvMu8VYQ/viewform".match(
match
)
).toBe(null);
});
});
|
108 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/GoogleLookerStudio.test.ts | import GoogleLookerStudio from "./GoogleLookerStudio";
describe("GoogleLookerStudio", () => {
const match = GoogleLookerStudio.ENABLED[0];
test("to be enabled on share link", () => {
expect(
"https://lookerstudio.google.com/embed/reporting/aab01789-f3a2-4ff3-9cba-c4c94c4a92e8/page/7zFD".match(
match
)
).toBeTruthy();
expect(
"https://datastudio.google.com/embed/reporting/aab01789-f3a2-4ff3-9cba-c4c94c4a92e8/page/7zFD".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://lookerstudio.google.com/u/0/".match(match)).toBe(null);
expect("https://lookerstudio.google.com".match(match)).toBe(null);
expect("https://www.google.com".match(match)).toBe(null);
expect(
"https://lookerstudioogoogle.com/embed/reporting/aab01789-f3a2-4ff3-9cba-c4c94c4a92e8/page/7zFD".match(
match
)
).toBe(null);
expect(
"https://lookerstudio.googleecom/embed/reporting/aab01789-f3a2-4ff3-9cba-c4c94c4a92e8/page/7zFD".match(
match
)
).toBe(null);
});
});
|
110 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/GoogleMaps.test.ts | import GoogleMaps from "./GoogleMaps";
describe("GoogleMaps", () => {
const match = GoogleMaps.ENABLED[0];
test("to be enabled", () => {
expect(
"https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d50977.036904273686!2d174.74383592605594!3d-37.00825027293197!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x6d0d4fe87ef3d5bb%3A0xf00ef62249b7130!2sAuckland%20Airport!5e0!3m2!1sen!2snz!4v1691573100204!5m2!1sen!2snz".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://www.google.com/maps/embed".match(match)).toBe(null);
expect("https://goo.gl/maps/".match(match)).toBe(null);
});
});
|
112 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/GoogleSheets.test.ts | import GoogleSheets from "./GoogleSheets";
describe("GoogleSheets", () => {
const match = GoogleSheets.ENABLED[0];
test("to be enabled on share link", () => {
expect(
"https://docs.google.com/spreadsheets/d/e/2PACX-1vTdddHPoZ5M_47wmSHCoigRIt2cj_Pd-kgtaNQY6H0Jzn0_CVGbxC1GcK5IoNzU615lzguexFwxasAW/pub".match(
match
)
).toBeTruthy();
expect(
"https://docs.google.com/spreadsheets/d/e/2PACX-1vTdddHPoZ5M_47wmSHCoigR/edit".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://docs.google.com/spreadsheets".match(match)).toBe(null);
expect("https://docs.google.com".match(match)).toBe(null);
expect("https://www.google.com".match(match)).toBe(null);
expect(
"https://docssgoogle.com/spreadsheets/d/e/2PACX-1vTdddHPoZ5M_47wmSHCoigRIt2cj_Pd-kgtaNQY6H0Jzn0_CVGbxC1GcK5IoNzU615lzguexFwxasAW/pub".match(
match
)
).toBe(null);
expect(
"https://docs.googleecom/spreadsheets/d/e/2PACX-1vTdddHPoZ5M_47wmSHCoigRIt2cj_Pd-kgtaNQY6H0Jzn0_CVGbxC1GcK5IoNzU615lzguexFwxasAW/pub".match(
match
)
).toBe(null);
});
});
|
114 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/GoogleSlides.test.ts | import GoogleSlides from "./GoogleSlides";
describe("GoogleSlides", () => {
const match = GoogleSlides.ENABLED[0];
test("to be enabled on share link", () => {
expect(
"https://docs.google.com/presentation/d/e/2PACX-1vTdddHPoZ5M_47wmSHCoigRIt2cj_Pd-kgtaNQY6H0Jzn0_CVGbxC1GcK5IoNzU615lzguexFwxasAW/pub?start=false&loop=false&delayms=3000".match(
match
)
).toBeTruthy();
expect(
"https://docs.google.com/presentation/d/e/2PACX-1vTdddHPoZ5M_47wmSHCoigRIt2cj_Pd-kgtaNQY6H0Jzn0_CVGbxC1GcK5IoNzU615lzguexFwxasAW/pub".match(
match
)
).toBeTruthy();
expect(
"https://docs.google.com/presentation/d/e/2PACX-1vTdddHPoZ5M_47wmSHCoigR/edit".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://docs.google.com/presentation".match(match)).toBe(null);
expect("https://docs.google.com".match(match)).toBe(null);
expect("https://www.google.com".match(match)).toBe(null);
expect(
"https://docssgoogle.com/presentation/d/e/2PACX-1vTdddHPoZ5M_47wmSHCoigRIt2cj_Pd-kgtaNQY6H0Jzn0_CVGbxC1GcK5IoNzU615lzguexFwxasAW/pub?start=false&loop=false&delayms=3000".match(
match
)
).toBe(null);
expect(
"https://docs.googleecom/presentation/d/e/2PACX-1vTdddHPoZ5M_47wmSHCoigRIt2cj_Pd-kgtaNQY6H0Jzn0_CVGbxC1GcK5IoNzU615lzguexFwxasAW/pub?start=false&loop=false&delayms=3000".match(
match
)
).toBe(null);
});
});
|
116 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Grist.test.tsx | import Grist from "./Grist";
describe("Grist", () => {
const match = Grist.ENABLED[0];
test("to be enabled on share link", () => {
expect(
"https://templates.getgrist.com/doc/afterschool-program/p/2?embed=true".match(
match
)
).toBeTruthy();
expect(
"https://docs.getgrist.com/sg5V93LuAije/Untitled-document/p/22?embed=true".match(
match
)
).toBeTruthy();
expect(
"https://templates.getgrist.com/doc/afterschool-program".match(match)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
// Self hosted not yet supported
expect(
"http://grist.my.host.com/o/docs/doc/new~5cCkr6CtMArdA62ohSy5xB/p/1?embed=true".match(
match
)
).toBe(null);
expect(
"https://my.get.grist.com/doc/afterschool-program?embed=true".match(match)
).toBe(null);
});
});
|
118 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/InVision.test.ts | import InVision from "./InVision";
describe("InVision", () => {
const match = InVision.ENABLED[0];
test("to be enabled on shortlink", () => {
expect("https://invis.io/69PG07QYQTE".match(match)).toBeTruthy();
});
test("to be enabled on share", () => {
expect(
"https://projects.invisionapp.com/share/69PG07QYQTE".match(match)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://invis.io".match(match)).toBe(null);
expect("https://invisionapp.com".match(match)).toBe(null);
expect("https://projects.invisionapp.com".match(match)).toBe(null);
});
});
|
120 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Instagram.test.ts | import Instagram from "./Instagram";
describe("Instagram", () => {
const match = Instagram.ENABLED[0];
test("to be enabled on post link", () => {
expect(
"https://www.instagram.com/p/CrL74G6Bxgw/?utm_source=ig_web_copy_link".match(
match
)
).toBeTruthy();
});
test("to be enabled on reel link", () => {
expect(
"https://www.instagram.com/reel/Cxdyt_fMnwN/?utm_source=ig_web_copy_link".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://www.instagram.com".match(match)).toBe(null);
expect("https://www.instagram.com/reel/".match(match)).toBe(null);
expect("https://www.instagram.com/p/".match(match)).toBe(null);
});
});
|
122 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/JSFiddle.test.ts | import JSFiddle from "./JSFiddle";
describe("JSFiddle", () => {
const match = JSFiddle.ENABLED[0];
test("to not be enabled for invalid urls", () => {
expect("https://jsfiddleenet/go/share/c9d837d74182317".match(match)).toBe(
null
);
});
});
|
124 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Linkedin.test.ts | import Linkedin from "./Linkedin";
describe("Linkedin", () => {
const match = Linkedin.ENABLED[0];
test("to be enabled on post link", () => {
expect(
"https://www.linkedin.com/posts/github_highlight-your-expertise-with-github-certifications-activity-7117157514097352704-F4Mz?utm_source=share&utm_medium=member_desktop".match(
match
)
).toBeTruthy();
});
test("to be enabled on embed link", () => {
expect(
"https://www.linkedin.com/embed/feed/update/urn:li:share:7117157513422090241".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://www.linkedin.com/".match(match)).toBe(null);
expect("https://www.linkedin.com/posts/".match(match)).toBe(null);
expect("https://www.linkedin.com/embed/".match(match)).toBe(null);
expect("https://www.linkedin.com/embed/feed/update/".match(match)).toBe(
null
);
expect(
"https://www.linkedin.com/embed/feed/update/urn:li:".match(match)
).toBe(null);
expect(
"https://www.linkedin.com/embed/feed/update/urn:li:share:".match(match)
).toBe(null);
expect(
"https://www.linkedin.com/embed/feed/update/urn:li:ugcPost:".match(match)
).toBe(null);
});
});
|
126 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Loom.test.ts | import Loom from "./Loom";
describe("Loom", () => {
const match = Loom.ENABLED[0];
test("to be enabled on share link", () => {
expect(
"https://www.loom.com/share/55327cbb265743f39c2c442c029277e0".match(match)
).toBeTruthy();
expect(
"https://www.useloom.com/share/55327cbb265743f39c2c442c029277e0".match(
match
)
).toBeTruthy();
});
test("to be enabled on embed link", () => {
expect(
"https://www.loom.com/embed/55327cbb265743f39c2c442c029277e0".match(match)
).toBeTruthy();
expect(
"https://www.useloom.com/embed/55327cbb265743f39c2c442c029277e0".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://www.useloom.com".match(match)).toBe(null);
expect("https://www.useloom.com/features".match(match)).toBe(null);
expect(
"https://www.loommcom/share/55327cbb265743f39c2c442c029277e0".match(match)
).toBe(null);
});
});
|
128 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Lucidchart.test.ts | import Lucidchart from "./Lucidchart";
describe("Lucidchart", () => {
const match = Lucidchart.ENABLED[0];
test("to be enabled on view link", () => {
expect(
"https://www.lucidchart.com/documents/view/2f4a79cb-7637-433d-8ffb-27cce65a05e7".match(
match
)
).toBeTruthy();
});
test("to be enabled on root link", () => {
expect(
"https://lucidchart.com/documents/view/2f4a79cb-7637-433d-8ffb-27cce65a05e7".match(
match
)
).toBeTruthy();
});
test("to be enabled on app link", () => {
expect(
"https://app.lucidchart.com/documents/view/2f4a79cb-7637-433d-8ffb-27cce65a05e7".match(
match
)
).toBeTruthy();
});
test("to be enabled on visited link", () => {
expect(
"https://www.lucidchart.com/documents/view/2f4a79cb-7637-433d-8ffb-27cce65a05e7/0".match(
match
)
).toBeTruthy();
});
test("to be enabled on embedded link", () => {
expect(
"https://app.lucidchart.com/documents/embeddedchart/1af2bdfa-da7d-4ea1-aa1d-bec5677a9837".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://lucidchart.com".match(match)).toBe(null);
expect("https://app.lucidchart.com".match(match)).toBe(null);
expect("https://www.lucidchart.com".match(match)).toBe(null);
expect("https://www.lucidchart.com/features".match(match)).toBe(null);
expect("https://www.lucidchart.com/documents/view".match(match)).toBe(null);
});
});
|
130 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Marvel.test.ts | import Marvel from "./Marvel";
describe("Marvel", () => {
const match = Marvel.ENABLED[0];
test("to be enabled on share link", () => {
expect("https://marvelapp.com/75hj91".match(match)).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://marvelapp.com".match(match)).toBe(null);
expect("https://marvelapp.com/features".match(match)).toBe(null);
expect("https://marvelapppcom/75hj91".match(match)).toBe(null);
});
});
|
132 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Mindmeister.test.ts | import Mindmeister from "./Mindmeister";
describe("Mindmeister", () => {
const match = Mindmeister.ENABLED[0];
test("to be enabled on mm.tt link", () => {
expect("https://mm.tt/326377934".match(match)).toBeTruthy();
});
test("to be enabled on mm.tt link with token parameter", () => {
expect("https://mm.tt/326377934?t=r9NcnTRr18".match(match)).toBeTruthy();
});
test("to be enabled on embed link", () => {
expect(
"https://www.mindmeister.com/maps/public_map_shell/326377934/paper-digital-or-online-mind-mapping".match(
match
)
).toBeTruthy();
});
test("to be enabled on public link", () => {
expect(
"https://www.mindmeister.com/326377934/paper-digital-or-online-mind-mapping".match(
match
)
).toBeTruthy();
});
test("to be enabled without www", () => {
expect(
"https://mindmeister.com/326377934/paper-digital-or-online-mind-mapping".match(
match
)
).toBeTruthy();
});
test("to be enabled without slug", () => {
expect("https://mindmeister.com/326377934".match(match)).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://mindmeister.com".match(match)).toBe(null);
expect("https://www.mindmeister.com/pricing".match(match)).toBe(null);
expect("https://www.mmttt/326377934".match(match)).toBe(null);
expect(
"https://www.mindmeisterrcom/maps/public_map_shell/326377934/paper-digital-or-online-mind-mapping".match(
match
)
).toBe(null);
expect("https://wwwwmm.tt/326377934".match(match)).toBe(null);
expect(
"https://wwwwmindmeister.com/maps/public_map_shell/326377934/paper-digital-or-online-mind-mapping".match(
match
)
).toBe(null);
});
});
|
134 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Miro.test.ts | import Miro from "./Miro";
describe("Miro", () => {
const match = Miro.ENABLED[0];
test("to be enabled on old domain share link", () => {
expect(
"https://realtimeboard.com/app/board/o9J_k0fwiss=".match(match)
).toBeTruthy();
});
test("to be enabled on share link", () => {
expect("https://miro.com/app/board/o9J_k0fwiss=".match(match)).toBeTruthy();
});
test("to extract the domain as part of the match for later use", () => {
expect(
"https://realtimeboard.com/app/board/o9J_k0fwiss=".match(match)?.[1]
).toBe("realtimeboard");
});
test("to not be enabled elsewhere", () => {
expect("https://miro.com".match(match)).toBe(null);
expect("https://realtimeboard.com".match(match)).toBe(null);
expect("https://realtimeboard.com/features".match(match)).toBe(null);
expect(
"https://realtimeboarddcom/app/board/o9J_k0fwiss=".match(match)
).toBe(null);
});
});
|
136 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/ModeAnalytics.test.ts | import ModeAnalytics from "./ModeAnalytics";
describe("ModeAnalytics", () => {
const match = ModeAnalytics.ENABLED[0];
test("to be enabled on report link", () => {
expect(
"https://modeanalytics.com/outline/reports/5aca06064f56".match(match)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://modeanalytics.com".match(match)).toBe(null);
expect("https://modeanalytics.com/outline".match(match)).toBe(null);
expect("https://modeanalytics.com/outline/reports".match(match)).toBe(null);
expect(
"https://modeanalyticsscom/outline/reports/5aca06064f56".match(match)
).toBe(null);
expect(
"https://wwwwmodeanalytics.com/outline/reports/5aca06064f56".match(match)
).toBe(null);
});
});
|
138 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Otter.test.ts | import Otter from "./Otter";
describe("Otter", () => {
const match = Otter.ENABLED[0];
test("to not be enabled for invalid urls", () => {
expect("https://otterrai/s/c9d837d74182317".match(match)).toBe(null);
});
});
|
140 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Pitch.test.ts | import Pitch from "./Pitch";
describe("Pitch", () => {
const match = Pitch.ENABLED[0];
test("to not be enabled elsewhere", () => {
expect(
"https://appppitch.com/app/presentation/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/player/c9d837d74182317".match(
match
)
).toBe(null);
expect(
"https://app.pitchhcom/app/presentation/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/player/c9d837d74182317".match(
match
)
).toBe(null);
});
});
|
142 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Prezi.test.ts | import Prezi from "./Prezi";
describe("Prezi", () => {
const match = Prezi.ENABLED[0];
test("to be enabled on share link", () => {
expect(
"https://prezi.com/view/39mn8Rn1ZkoeEKQCgk5C".match(match)
).toBeTruthy();
});
test("to be enabled on embed link", () => {
expect(
"https://prezi.com/view/39mn8Rn1ZkoeEKQCgk5C/embed".match(match)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://prezi.com".match(match)).toBe(null);
expect("https://prezi.com/pricing".match(match)).toBe(null);
expect("https://preziicom/view/39mn8Rn1ZkoeEKQCgk5C".match(match)).toBe(
null
);
});
});
|
145 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Spotify.test.ts | import Spotify from "./Spotify";
describe("Spotify", () => {
const match = Spotify.ENABLED[0];
test("to be enabled on song link", () => {
expect(
"https://open.spotify.com/track/29G1ScCUhgjgI0H72qN4DE?si=DxjEUxV2Tjmk6pSVckPDRg".match(
match
)
).toBeTruthy();
});
test("to be enabled on playlist link", () => {
expect(
"https://open.spotify.com/user/spotify/playlist/29G1ScCUhgjgI0H72qN4DE?si=DxjEUxV2Tjmk6pSVckPDRg".match(
match
)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://spotify.com".match(match)).toBe(null);
expect("https://open.spotify.com".match(match)).toBe(null);
expect("https://www.spotify.com".match(match)).toBe(null);
expect(
"https://opennspotify.com/track/29G1ScCUhgjgI0H72qN4DE?si=DxjEUxV2Tjmk6pSVckPDRg".match(
match
)
).toBe(null);
expect(
"https://open.spotifyycom/track/29G1ScCUhgjgI0H72qN4DE?si=DxjEUxV2Tjmk6pSVckPDRg".match(
match
)
).toBe(null);
});
});
|
147 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Tldraw.test.ts | import Tldraw from "./Tldraw";
describe("Tldraw", () => {
const match = Tldraw.ENABLED[0];
test("to be enabled on share link", () => {
expect(
"https://beta.tldraw.com/r/v2_c_r5WVtGaktE99D3wyFFsoL".match(match)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://wwww.tldraw.com/r/c9d837d74182317".match(match)).toBe(null);
expect("https://wwwwtldraw.com/r/c9d837d74182317".match(match)).toBe(null);
expect("https://www.tldrawwcom/r/c9d837d74182317".match(match)).toBe(null);
});
});
|
149 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Trello.test.ts | import Trello from "./Trello";
describe("Trello", () => {
const match = Trello.ENABLED[0];
test("to not be enabled for invalid urls", () => {
expect("https://trelloocom/c/c9d837d74182317".match(match)).toBe(null);
});
});
|
151 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Typeform.test.ts | import Typeform from "./Typeform";
describe("Typeform", () => {
const match = Typeform.ENABLED[0];
test("to be enabled on share link", () => {
expect(
"https://beardyman.typeform.com/to/zvlr4L".match(match)
).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://www.typeform.com".match(match)).toBe(null);
expect("https://typeform.com/to/zvlr4L".match(match)).toBe(null);
expect("https://typeform.com/features".match(match)).toBe(null);
expect("https://beardymanntypeform.com/to/zvlr4L".match(match)).toBe(null);
expect("https://beardyman.typeformmcom/to/zvlr4L".match(match)).toBe(null);
});
});
|
154 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Vimeo.test.ts | import Vimeo from "./Vimeo";
describe("Vimeo", () => {
const match = Vimeo.ENABLED[0];
test("to be enabled on video link", () => {
expect("https://vimeo.com/265045525".match(match)).toBeTruthy();
expect("https://vimeo.com/265045525/b9fefc8598".match(match)).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://vimeo.com".match(match)).toBe(null);
expect("https://www.vimeo.com".match(match)).toBe(null);
expect("https://vimeo.com/upgrade".match(match)).toBe(null);
expect("https://vimeo.com/features/video-marketing".match(match)).toBe(
null
);
expect("https://www.vimeoocom/265045525".match(match)).toBe(null);
});
});
|
156 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/Whimsical.test.ts | import Whimsical from "./Whimsical";
describe("Whimsical", () => {
const match = Whimsical.ENABLED[0];
test("to not be enabled for invalid urls", () => {
expect("https://whimsicallcom/a-c9d837d74182317".match(match)).toBe(null);
});
});
|
158 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/embeds/YouTube.test.ts | import YouTube from "./YouTube";
describe("YouTube", () => {
const match = YouTube.ENABLED[0];
test("to be enabled on video link", () => {
expect(
"https://www.youtube.com/watch?v=dQw4w9WgXcQ".match(match)
).toBeTruthy();
});
test("to be enabled on video link with timestamp", () => {
expect(
"https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=123s".match(match)
).toBeTruthy();
});
test("to be enabled on embed link", () => {
expect(
"https://www.youtube.com/embed?v=dQw4w9WgXcQ".match(match)
).toBeTruthy();
});
test("to be enabled on shortlink", () => {
expect("https://youtu.be/dQw4w9WgXcQ".match(match)).toBeTruthy();
});
test("to be enabled on shortlink with timestamp", () => {
expect("https://youtu.be/dQw4w9WgXcQ?t=123".match(match)).toBeTruthy();
});
test("to not be enabled elsewhere", () => {
expect("https://youtu.be".match(match)).toBe(null);
expect("https://youtube.com".match(match)).toBe(null);
expect("https://www.youtube.com".match(match)).toBe(null);
expect("https://www.youtube.com/logout".match(match)).toBe(null);
expect("https://www.youtube.com/feed/subscriptions".match(match)).toBe(
null
);
});
});
|
179 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/lib/emoji.test.ts | import { getNameFromEmoji, getEmojiFromName } from "./emoji";
describe("getNameFromEmoji", () => {
it("returns the correct shortcode", () => {
expect(getNameFromEmoji("🤔")).toBe("thinking_face");
});
});
describe("getEmojiFromName", () => {
it("returns the correct native character", () => {
expect(getEmojiFromName("thinking_face")).toBe("🤔");
});
});
|
181 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/lib/filterExcessSeparators.test.ts | import filterExcessSeparators from "./filterExcessSeparators";
const embedDescriptor = {
icon: () => null,
matcher: () => true,
component: () => null,
};
describe("filterExcessSeparators", () => {
test("filter hanging end separators", () => {
expect(
filterExcessSeparators([
embedDescriptor,
{ name: "separator" },
{ name: "separator" },
{ name: "separator" },
{ name: "separator" },
])
).toStrictEqual([embedDescriptor]);
});
test("filter hanging start separators", () => {
expect(
filterExcessSeparators([
{ name: "separator" },
{ name: "separator" },
{ name: "separator" },
{ name: "separator" },
embedDescriptor,
])
).toStrictEqual([embedDescriptor]);
});
test("filter surrounding separators", () => {
expect(
filterExcessSeparators([
{ name: "separator" },
embedDescriptor,
{ name: "separator" },
])
).toStrictEqual([embedDescriptor]);
});
});
|
185 | 0 | petrpan-code/outline/outline/shared/editor | petrpan-code/outline/outline/shared/editor/lib/isMarkdown.test.ts | import isMarkdown from "./isMarkdown";
test("returns false for an empty string", () => {
expect(isMarkdown("")).toBe(false);
});
test("returns false for plain text", () => {
expect(isMarkdown("plain text")).toBe(false);
});
test("returns true for bullet list", () => {
expect(
isMarkdown(`- item one
- item two
- nested item`)
).toBe(true);
});
test("returns true for numbered list", () => {
expect(
isMarkdown(`1. item one
1. item two`)
).toBe(true);
expect(
isMarkdown(`1. item one
2. item two`)
).toBe(true);
});
test("returns true for code fence", () => {
expect(
isMarkdown(`\`\`\`javascript
this is code
\`\`\``)
).toBe(true);
});
test("returns false for non-closed fence", () => {
expect(
isMarkdown(`\`\`\`
this is not code
`)
).toBe(false);
});
test("returns true for heading", () => {
expect(isMarkdown(`# Heading 1`)).toBe(true);
expect(isMarkdown(`## Heading 2`)).toBe(true);
expect(isMarkdown(`### Heading 3`)).toBe(true);
});
test("returns false for hashtag", () => {
expect(isMarkdown(`Test #hashtag`)).toBe(false);
expect(isMarkdown(` #hashtag`)).toBe(false);
});
test("returns true for absolute link", () => {
expect(isMarkdown(`[title](http://www.google.com)`)).toBe(true);
});
test("returns true for relative link", () => {
expect(isMarkdown(`[title](/doc/mydoc-234tnes)`)).toBe(true);
});
test("returns true for relative image", () => {
expect(isMarkdown(``)).toBe(true);
});
test("returns true for absolute image", () => {
expect(isMarkdown(``)).toBe(true);
});
|
313 | 0 | petrpan-code/outline/outline/shared | petrpan-code/outline/outline/shared/utils/domains.test.ts | import env from "../env";
import { parseDomain, getCookieDomain, slugifyDomain } from "./domains";
// test suite is based on subset of parse-domain module we want to support
// https://github.com/peerigon/parse-domain/blob/master/test/parseDomain.test.js
describe("#parseDomain", () => {
beforeEach(() => {
env.URL = "https://example.com";
});
it("should remove the protocol", () => {
expect(parseDomain("http://example.com")).toMatchObject({
teamSubdomain: "",
host: "example.com",
custom: false,
});
expect(parseDomain("//example.com")).toMatchObject({
teamSubdomain: "",
host: "example.com",
custom: false,
});
expect(parseDomain("https://example.com")).toMatchObject({
teamSubdomain: "",
host: "example.com",
custom: false,
});
});
it("should find team sub-domains", () => {
expect(parseDomain("myteam.example.com")).toMatchObject({
teamSubdomain: "myteam",
host: "myteam.example.com",
custom: false,
});
});
it("should ignore reserved sub-domains", () => {
expect(parseDomain("www.example.com")).toMatchObject({
teamSubdomain: "",
host: "www.example.com",
custom: false,
});
});
it("should return the same result when parsing the returned host", () => {
const customDomain = parseDomain("www.example.com");
const subDomain = parseDomain("myteam.example.com");
expect(parseDomain(customDomain.host)).toMatchObject(customDomain);
expect(parseDomain(subDomain.host)).toMatchObject(subDomain);
});
it("should remove the path", () => {
expect(parseDomain("example.com/some/path?and&query")).toMatchObject({
teamSubdomain: "",
host: "example.com",
custom: false,
});
expect(parseDomain("example.com/")).toMatchObject({
teamSubdomain: "",
host: "example.com",
custom: false,
});
});
it("should remove the query string", () => {
expect(parseDomain("www.example.com?and&query")).toMatchObject({
teamSubdomain: "",
host: "www.example.com",
custom: false,
});
});
it("should remove special characters", () => {
expect(parseDomain("http://example.com\r")).toMatchObject({
teamSubdomain: "",
host: "example.com",
custom: false,
});
});
it("should remove the port", () => {
expect(parseDomain("example.com:8080")).toMatchObject({
teamSubdomain: "",
host: "example.com",
custom: false,
});
});
it("should allow @ characters in the path", () => {
expect(parseDomain("https://medium.com/@username/")).toMatchObject({
teamSubdomain: "",
host: "medium.com",
custom: true,
});
});
it("should recognize include private domains like blogspot.com as custom", () => {
expect(parseDomain("foo.blogspot.com")).toMatchObject({
teamSubdomain: "",
host: "foo.blogspot.com",
custom: true,
});
});
it("should also work with the minimum", () => {
expect(parseDomain("example.com")).toMatchObject({
teamSubdomain: "",
host: "example.com",
custom: false,
});
});
it("should throw a TypeError if the given value is not a valid string", () => {
expect(() => parseDomain("")).toThrow(TypeError);
});
it("should also work with three-level domains like .co.uk", () => {
env.URL = "https://example.co.uk";
expect(parseDomain("myteam.example.co.uk")).toMatchObject({
teamSubdomain: "myteam",
host: "myteam.example.co.uk",
custom: false,
});
});
it("should work with custom top-level domains (eg .local)", () => {
env.URL = "mymachine.local";
expect(parseDomain("myteam.mymachine.local")).toMatchObject({
teamSubdomain: "myteam",
host: "myteam.mymachine.local",
custom: false,
});
});
it("should work with localhost", () => {
env.URL = "http://localhost:3000";
expect(parseDomain("https://localhost:3000/foo/bar?q=12345")).toMatchObject(
{
teamSubdomain: "",
host: "localhost",
custom: false,
}
);
});
it("should work with localhost subdomains", () => {
env.URL = "http://localhost:3000";
expect(parseDomain("https://www.localhost:3000")).toMatchObject({
teamSubdomain: "",
host: "www.localhost",
custom: false,
});
expect(parseDomain("https://myteam.localhost:3000")).toMatchObject({
teamSubdomain: "myteam",
host: "myteam.localhost",
custom: false,
});
});
});
describe("#slugifyDomain", () => {
it("strips the last . delineated segment from strings", () => {
expect(slugifyDomain("foo.co")).toBe("foo");
expect(slugifyDomain("foo.co.uk")).toBe("foo-co");
expect(slugifyDomain("www.foo.co.uk")).toBe("www-foo-co");
});
});
describe("#getCookieDomain", () => {
beforeEach(() => {
env.URL = "https://example.com";
});
it("returns the normalized app host when on the host domain", () => {
expect(getCookieDomain("subdomain.example.com", true)).toBe("example.com");
expect(getCookieDomain("www.example.com", true)).toBe("example.com");
expect(getCookieDomain("http://example.com:3000", true)).toBe(
"example.com"
);
expect(
getCookieDomain("myteam.example.com/document/12345?q=query", true)
).toBe("example.com");
});
it("returns the input if not on the host domain", () => {
expect(getCookieDomain("www.blogspot.com", true)).toBe("www.blogspot.com");
expect(getCookieDomain("anything else", true)).toBe("anything else");
});
it("always returns the input when not cloud hosted", () => {
expect(getCookieDomain("example.com", false)).toBe("example.com");
expect(getCookieDomain("www.blogspot.com", false)).toBe("www.blogspot.com");
expect(getCookieDomain("anything else", false)).toBe("anything else");
});
});
|
316 | 0 | petrpan-code/outline/outline/shared | petrpan-code/outline/outline/shared/utils/files.test.ts | import { bytesToHumanReadable } from "./files";
describe("bytesToHumanReadable", () => {
test("Outputs readable string", () => {
expect(bytesToHumanReadable(0)).toBe("0 Bytes");
expect(bytesToHumanReadable(500)).toBe("500 Bytes");
expect(bytesToHumanReadable(1000)).toBe("1 kB");
expect(bytesToHumanReadable(15000)).toBe("15 kB");
expect(bytesToHumanReadable(12345)).toBe("12.34 kB");
expect(bytesToHumanReadable(123456)).toBe("123.45 kB");
expect(bytesToHumanReadable(1234567)).toBe("1.23 MB");
expect(bytesToHumanReadable(undefined)).toBe("0 Bytes");
});
});
|
320 | 0 | petrpan-code/outline/outline/shared | petrpan-code/outline/outline/shared/utils/naturalSort.test.ts | import naturalSort from "./naturalSort";
describe("#naturalSort", () => {
it("should sort a list of objects by the given key", () => {
const items = [
{
name: "Joan",
},
{
name: "Pedro",
},
{
name: "Mark",
},
];
expect(naturalSort(items, "name")).toEqual([
{
name: "Joan",
},
{
name: "Mark",
},
{
name: "Pedro",
},
]);
});
it("should accept a function as the object key", () => {
const items = [
{
name: "Joan",
},
{
name: "Pedro",
},
{
name: "Mark",
},
];
expect(naturalSort(items, (item) => item.name)).toEqual([
{
name: "Joan",
},
{
name: "Mark",
},
{
name: "Pedro",
},
]);
});
it("should accept natural-sort options", () => {
const items = [
{
name: "Joan",
},
{
name: "joan",
},
{
name: "Pedro",
},
{
name: "Mark",
},
];
expect(
naturalSort(items, "name", {
direction: "desc",
caseSensitive: true,
})
).toEqual([
{
name: "joan",
},
{
name: "Pedro",
},
{
name: "Mark",
},
{
name: "Joan",
},
]);
});
it("should ignore non basic latin letters", () => {
const items = [
{
name: "Abel",
},
{
name: "Martín",
},
{
name: "Ávila",
},
];
expect(naturalSort(items, "name")).toEqual([
{
name: "Abel",
},
{
name: "Ávila",
},
{
name: "Martín",
},
]);
});
it("should ignore emojis", () => {
const items = [
{
title: "🍔 Document 2",
},
{
title: "🐻 Document 3",
},
{
title: "🙂 Document 1",
},
];
expect(naturalSort(items, "title")).toEqual([
{
title: "🙂 Document 1",
},
{
title: "🍔 Document 2",
},
{
title: "🐻 Document 3",
},
]);
});
});
|
322 | 0 | petrpan-code/outline/outline/shared | petrpan-code/outline/outline/shared/utils/parseDocumentSlug.test.ts | import parseDocumentSlug from "./parseDocumentSlug";
describe("#parseDocumentSlug", () => {
it("should work with fully qualified url", () => {
expect(
parseDocumentSlug("http://example.com/doc/my-doc-y4j4tR4UuV")
).toEqual("my-doc-y4j4tR4UuV");
});
it("should work with paths after document slug", () => {
expect(
parseDocumentSlug(
"http://mywiki.getoutline.com/doc/my-doc-y4j4tR4UuV/edit"
)
).toEqual("my-doc-y4j4tR4UuV");
});
it("should work with hash", () => {
expect(
parseDocumentSlug(
"http://mywiki.getoutline.com/doc/my-doc-y4j4tR4UuV#state"
)
).toEqual("my-doc-y4j4tR4UuV");
});
it("should work with subdomain qualified url", () => {
expect(
parseDocumentSlug("http://mywiki.getoutline.com/doc/my-doc-y4j4tR4UuV")
).toEqual("my-doc-y4j4tR4UuV");
});
it("should work with path", () => {
expect(parseDocumentSlug("/doc/my-doc-y4j4tR4UuV")).toEqual(
"my-doc-y4j4tR4UuV"
);
});
});
|
325 | 0 | petrpan-code/outline/outline/shared | petrpan-code/outline/outline/shared/utils/parseTitle.test.ts | import parseTitle from "./parseTitle";
it("should trim the title", () => {
expect(parseTitle(`# Lots of space `).title).toBe("Lots of space");
});
it("should extract first title", () => {
expect(parseTitle(`# Title one\n# Title two`).title).toBe("Title one");
});
it("should parse emoji if first character", () => {
const parsed = parseTitle(`# 😀 Title`);
expect(parsed.title).toBe("😀 Title");
expect(parsed.emoji).toBe("😀");
});
it("should not parse emoji if not first character", () => {
const parsed = parseTitle(`# Title 🌈`);
expect(parsed.title).toBe("Title 🌈");
expect(parsed.emoji).toBe(undefined);
});
|
332 | 0 | petrpan-code/outline/outline/shared | petrpan-code/outline/outline/shared/utils/urls.test.ts | import * as urlsUtils from "./urls";
import { urlRegex } from "./urls";
describe("isUrl", () => {
it("should return false for invalid url", () => {
expect(urlsUtils.isUrl("")).toBe(false);
expect(urlsUtils.isUrl("#invalidurl")).toBe(false);
expect(urlsUtils.isUrl("mailto:")).toBe(false);
expect(urlsUtils.isUrl("sms:")).toBe(false);
expect(urlsUtils.isUrl("://")).toBe(false);
});
it("should return true for valid urls", () => {
expect(urlsUtils.isUrl("http://example.com")).toBe(true);
expect(urlsUtils.isUrl("https://www.example.com")).toBe(true);
expect(urlsUtils.isUrl("seafile://openfile")).toBe(true);
expect(urlsUtils.isUrl("figma://launch")).toBe(true);
expect(urlsUtils.isUrl("outline:https://getoutline.com")).toBe(true);
});
});
describe("isBase64Url", () => {
it("should return false for invalid url", () => {
expect(urlsUtils.isBase64Url("")).toBe(false);
expect(urlsUtils.isBase64Url("#invalidurl")).toBe(false);
expect(urlsUtils.isBase64Url("http://example.com")).toBe(false);
expect(urlsUtils.isBase64Url("https://www.example.com")).toBe(false);
expect(urlsUtils.isBase64Url("seafile://openfile")).toBe(false);
expect(urlsUtils.isBase64Url("figma://launch")).toBe(false);
expect(urlsUtils.isBase64Url("outline:https://getoutline.com")).toBe(false);
expect(urlsUtils.isBase64Url("://")).toBe(false);
});
it("should return true for valid urls", () => {
expect(
urlsUtils.isBase64Url(
"data:image/png;base64,R0lGODlhPQBEAPeoAJosM//AwO/AwHVYZ/z595kzAP/s7P+goOXMv8+fhw/v739/f+8PD98fH/8mJl+fn/9ZWb8/PzWlwv///6wWGbImAPgTEMImIN9gUFCEm/gDALULDN8PAD6atYdCTX9gUNKlj8wZAKUsAOzZz+UMAOsJAP/Z2ccMDA8PD/95eX5NWvsJCOVNQPtfX/8zM8+QePLl38MGBr8JCP+zs9myn/8GBqwpAP/GxgwJCPny78lzYLgjAJ8vAP9fX/+MjMUcAN8zM/9wcM8ZGcATEL+QePdZWf/29uc/P9cmJu9MTDImIN+/r7+/vz8/P8VNQGNugV8AAF9fX8swMNgTAFlDOICAgPN"
)
).toBeTruthy();
expect(
urlsUtils.isBase64Url(
"data:image/gif;base64,npkM+fOqD6DDj1aZpITp0dtGCDhr+fVuCu3zlg49ijaokTZTo27uG7Gjn2P+hI8+PDPERoUB318bWbfAJ5sUNFcuGRTYUqV/3ogfXp1rWlMc6awJjiAAd2fm4ogXjz56aypOoIde4OE5u/F9x199dlXnnGiHZWEYbGpsAEA3QXYnHwEFliKAgswgJ8LPeiUXGwedCAKABACCN+EA1pYIIYaFlcDhytd51sGAJbo3onOpajiihlO92KHGaUXGwWjUBChjSPiWJuOO/LYIm4v1tXfE6J4gCSJEZ7YgRYUNrkji9P55sF/ogxw5ZkSqIDaZBV6aSGYq/lGZplndkckZ98xoICbTcIJGQAZc"
)
).toBeTruthy();
});
});
describe("isInternalUrl", () => {
it("should return false if empty string", () => {
expect(urlsUtils.isInternalUrl("")).toBe(false);
});
it("should return true if starting with relative path", () => {
expect(urlsUtils.isInternalUrl("/drafts")).toEqual(true);
});
});
describe("isExternalUrl", () => {
it("should return false if empty url", () => {
expect(urlsUtils.isExternalUrl("")).toBe(false);
});
it("should return false if internal url", () => {
expect(urlsUtils.isExternalUrl("/drafts")).toBe(false);
});
});
describe("sanitizeUrl", () => {
it("should return undefined if not url", () => {
expect(urlsUtils.sanitizeUrl(undefined)).toBeUndefined();
expect(urlsUtils.sanitizeUrl(null)).toBeUndefined();
expect(urlsUtils.sanitizeUrl("")).toBeUndefined();
});
it("should append https:// to non-special urls", () => {
expect(urlsUtils.sanitizeUrl("www.google.com")).toEqual(
"https://www.google.com"
);
});
describe("special urls", () => {
it("should return the url as it's if starting with /", () => {
expect(urlsUtils.sanitizeUrl("/drafts")).toEqual("/drafts");
});
it("should return the url as it's if starting with #", () => {
expect(urlsUtils.sanitizeUrl("#home")).toEqual("#home");
});
it("should return the url as it's if it's mailto:", () => {
expect(urlsUtils.sanitizeUrl("mailto:[email protected]")).toEqual(
"mailto:[email protected]"
);
});
it("should return the url as it's if it's mailto:", () => {
expect(urlsUtils.sanitizeUrl("mailto:[email protected]")).toEqual(
"mailto:[email protected]"
);
});
it("should return the url as it's if it's sms:, fax:, tel:", () => {
expect(urlsUtils.sanitizeUrl("mailto:[email protected]")).toEqual(
"mailto:[email protected]"
);
expect(urlsUtils.sanitizeUrl("tel:0123456789")).toEqual("tel:0123456789");
expect(urlsUtils.sanitizeUrl("fax:0123456789")).toEqual("fax:0123456789");
expect(urlsUtils.sanitizeUrl("sms:0123456789")).toEqual("sms:0123456789");
});
it("should return the url as it's if it's a special protocol", () => {
expect(urlsUtils.sanitizeUrl("mqtt://getoutline.com")).toEqual(
"mqtt://getoutline.com"
);
});
});
describe("Blocked protocols", () => {
it("should be sanitized", () => {
expect(urlsUtils.sanitizeUrl("file://localhost.com/outline.txt")).toEqual(
"https://file://localhost.com/outline.txt"
);
expect(urlsUtils.sanitizeUrl("javascript:whatever")).toEqual(
"https://javascript:whatever"
);
expect(
urlsUtils.sanitizeUrl("data:text/html,<script>alert('hi');</script>")
).toEqual("https://data:text/html,<script>alert('hi');</script>");
expect(urlsUtils.sanitizeUrl("vbscript:whatever")).toEqual(
"https://vbscript:whatever"
);
});
});
});
describe("#urlRegex", () => {
it("should return undefined for invalid urls", () => {
expect(urlRegex(undefined)).toBeUndefined();
expect(urlRegex(null)).toBeUndefined();
expect(urlRegex("invalid url!")).toBeUndefined();
});
it("should return corresponding regex otherwise", () => {
const regex = urlRegex("https://docs.google.com");
expect(regex?.source).toBe(/https:\/\/docs\.google\.com/.source);
});
});
|
1,764 | 0 | petrpan-code/medusajs/medusa/packages/design-system | petrpan-code/medusajs/medusa/packages/design-system/icons/setup-test.ts | import "@testing-library/jest-dom"
import { JSDOM } from "jsdom"
import ResizeObserver from "resize-observer-polyfill"
const { window } = new JSDOM()
window.ResizeObserver = ResizeObserver
global.ResizeObserver = ResizeObserver
window.Element.prototype.scrollTo = () => {
// no-op
}
window.requestAnimationFrame = (cb) => setTimeout(cb, 1000 / 60)
Object.assign(global, { window, document: window.document })
|
2,317 | 0 | petrpan-code/medusajs/medusa/packages/design-system | petrpan-code/medusajs/medusa/packages/design-system/ui/setup-test.ts | import "@testing-library/jest-dom"
import { JSDOM } from "jsdom"
import ResizeObserver from "resize-observer-polyfill"
const { window } = new JSDOM()
window.ResizeObserver = ResizeObserver
global.ResizeObserver = ResizeObserver
window.Element.prototype.scrollTo = () => {
// no-op
}
window.requestAnimationFrame = (cb) => setTimeout(cb, 1000 / 60)
Object.assign(global, { window, document: window.document })
|
2,507 | 0 | petrpan-code/medusajs/medusa/packages/gatsby-source-medusa/src | petrpan-code/medusajs/medusa/packages/gatsby-source-medusa/src/__tests__/process-node.test.ts | const { processNode } = require("../process-node.ts")
describe("helper functions", () => {
it("should return return a new node from processNode", () => {
const fieldName = "product"
const node = {
id: "prod_test_1234",
title: "Test Shirt",
description: "A test product",
unit_price: 2500,
}
const createContentDigest = jest.fn(() => "digest_string")
const processNodeResult = processNode(node, fieldName, createContentDigest)
expect(createContentDigest).toBeCalled()
expect(processNodeResult).toMatchSnapshot()
})
})
|
2,508 | 0 | petrpan-code/medusajs/medusa/packages/gatsby-source-medusa/src/__tests__ | petrpan-code/medusajs/medusa/packages/gatsby-source-medusa/src/__tests__/__snapshots__/process-node.test.ts.snap | // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`helper functions should return return a new node from processNode 1`] = `
Array [
Object {
"children": Array [],
"description": "A test product",
"id": "prod_test_1234",
"internal": Object {
"content": "{\\"id\\":\\"prod_test_1234\\",\\"title\\":\\"Test Shirt\\",\\"description\\":\\"A test product\\",\\"unit_price\\":2500}",
"contentDigest": "digest_string",
"type": "MedusaProduct",
},
"parent": null,
"title": "Test Shirt",
"unit_price": 2500,
},
]
`;
|
3,255 | 0 | petrpan-code/medusajs/medusa/packages/medusa-js/src/test | petrpan-code/medusajs/medusa/packages/medusa-js/src/test/utils/utils.test.ts | const { stringifyNullProperties } = require("../../utils")
describe("stringifyNullProperties", () => {
test("returns empty object on no props", () => {
const result = stringifyNullProperties({})
expect(result).toEqual({})
})
test("successfully stringifies null property", () => {
const result = stringifyNullProperties({ test: null })
expect(result).toEqual({ test: "null" })
})
test("successfully stringifies nested null property", () => {
const result = stringifyNullProperties({
test: { test_2: { test_3: null } },
another_test: "test",
})
expect(result).toEqual({
test: { test_2: { test_3: "null" } },
another_test: "test",
})
})
test("successfully stringifies string property", () => {
const result = stringifyNullProperties({
test: "test",
})
expect(result).toEqual({ test: "test" })
})
})
|
3,355 | 0 | petrpan-code/medusajs/medusa/packages/medusa-payment-stripe/src/core | petrpan-code/medusajs/medusa/packages/medusa-payment-stripe/src/core/__fixtures__/stripe-test.ts | import StripeBase from "../stripe-base"
import { PaymentIntentOptions } from "../../types"
export class StripeTest extends StripeBase {
constructor(_, options) {
super(_, options)
}
get paymentIntentOptions(): PaymentIntentOptions {
return {}
}
}
|
3,729 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test | petrpan-code/medusajs/medusa/packages/medusa-react/test/cart-context/cart.test.ts | import { useCart } from "../../src"
import { act, renderHook } from "@testing-library/react-hooks"
import { fixtures } from "../../mocks/data"
import { createCartWrapper } from "../utils"
import { Cart } from "../../src/types"
describe("useBag hook", () => {
describe("sets a cart", () => {
test("success", async () => {
const { result } = renderHook(() => useCart(), {
wrapper: createCartWrapper(),
})
const { setCart } = result.current
act(() => {
setCart((fixtures.get("cart") as unknown) as Cart)
})
const { cart, totalItems } = result.current
expect(cart).toEqual(fixtures.get("cart"))
expect(totalItems).toEqual(0)
})
})
describe("createCart", () => {
test("creates a cart", async () => {
const { result, waitFor } = renderHook(() => useCart(), {
wrapper: createCartWrapper(),
})
const { createCart } = result.current
act(() => {
createCart.mutate({})
})
await waitFor(() => result.current.createCart.isSuccess)
const { cart, totalItems } = result.current
expect(cart).toEqual(fixtures.get("cart"))
expect(totalItems).toEqual(0)
})
})
describe("startCheckout", () => {
test("creates a payment session and updates the cart", async () => {
const { result, waitFor } = renderHook(() => useCart(), {
wrapper: createCartWrapper(),
initialProps: {
initialCartState: ({
...fixtures.get("cart"),
id: "test-cart",
} as unknown) as Cart,
},
})
const { startCheckout } = result.current
act(() => {
startCheckout.mutate()
})
await waitFor(() => result.current.startCheckout.isSuccess)
const { cart, totalItems } = result.current
expect(cart).toEqual({
...fixtures.get("cart"),
id: "test-cart",
})
expect(totalItems).toEqual(0)
})
})
describe("updateCart", () => {
test("updates the cart", async () => {
const { result, waitFor } = renderHook(() => useCart(), {
wrapper: createCartWrapper(),
initialProps: {
initialCartState: ({
...fixtures.get("cart"),
id: "test-cart",
} as unknown) as Cart,
},
})
const { updateCart } = result.current
act(() => {
updateCart.mutate({
email: "[email protected]",
})
})
await waitFor(() => result.current.updateCart.isSuccess)
const { cart, totalItems } = result.current
expect(cart).toEqual({
...fixtures.get("cart"),
id: "test-cart",
email: "[email protected]",
})
expect(totalItems).toEqual(0)
})
})
describe("addShippingMethod", () => {
test("adds a shipping method and updates the cart", async () => {
const { result, waitFor } = renderHook(() => useCart(), {
wrapper: createCartWrapper(),
initialProps: {
initialCartState: ({
...fixtures.get("cart"),
id: "test-cart",
} as unknown) as Cart,
},
})
const { addShippingMethod } = result.current
act(() => {
addShippingMethod.mutate({
option_id: "test-option",
})
})
await waitFor(() => result.current.addShippingMethod.isSuccess)
const { cart, totalItems } = result.current
expect(cart).toEqual({
...fixtures.get("cart"),
id: "test-cart",
})
expect(totalItems).toEqual(0)
})
})
describe("pay", () => {
test("sets a payment session and updates the cart", async () => {
const { result, waitFor } = renderHook(() => useCart(), {
wrapper: createCartWrapper(),
initialProps: {
initialCartState: ({
...fixtures.get("cart"),
id: "test-cart",
} as unknown) as Cart,
},
})
const { pay } = result.current
act(() => {
pay.mutate({
provider_id: "test-provider",
})
})
await waitFor(() => result.current.pay.isSuccess)
const { cart, totalItems } = result.current
expect(cart).toEqual({
...fixtures.get("cart"),
id: "test-cart",
})
expect(totalItems).toEqual(0)
})
})
describe("completeCheckout", () => {
test("calls complete cart, does not update the cart, and returns an order", async () => {
const { result, waitFor } = renderHook(() => useCart(), {
wrapper: createCartWrapper(),
initialProps: {
initialCartState: (fixtures.get("cart") as unknown) as Cart,
},
})
const { completeCheckout } = result.current
act(() => {
completeCheckout.mutate()
})
await waitFor(() => result.current.completeCheckout.isSuccess)
const { cart, totalItems } = result.current
expect(cart).toEqual(fixtures.get("cart"))
expect(totalItems).toEqual(0)
expect(result.current.completeCheckout.data.type).toEqual("order")
expect(result.current.completeCheckout.data.data).toEqual(
fixtures.get("order")
)
})
})
})
|
3,730 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/auth/mutations.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import { useAdminDeleteSession, useAdminLogin } from "../../../../src/"
import { createWrapper } from "../../../utils"
describe("useAdminLogin hook", () => {
test("logs in a user", async () => {
const payload = {
email: "[email protected]",
password: "supersecure",
}
const { result, waitFor } = renderHook(() => useAdminLogin(), {
wrapper: createWrapper(),
})
result.current.mutate(payload)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.user).toEqual(fixtures.get("user"))
})
})
describe("useAdminDeleteSession hook", () => {
test("deletes a collection", async () => {
const { result, waitFor } = renderHook(() => useAdminDeleteSession(), {
wrapper: createWrapper(),
})
result.current.mutate()
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
})
})
|
3,731 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/auth/queries.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import { useAdminGetSession } from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminGetSession hook", () => {
test("returns the authenticated user", async () => {
const user = fixtures.get("user")
const { result, waitFor } = renderHook(() => useAdminGetSession(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.user).toEqual(user)
})
})
|
3,732 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/batch-jobs/mutations.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import {
useAdminCancelBatchJob,
useAdminConfirmBatchJob,
useAdminCreateBatchJob,
} from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminCreateBatchJob hook", () => {
test("creates a batch job and returns it", async () => {
const batch = {
type: "product_export",
dry_run: false,
context: {},
}
const { result, waitFor } = renderHook(() => useAdminCreateBatchJob(), {
wrapper: createWrapper(),
})
result.current.mutate(batch)
await waitFor(() => result.current.isSuccess)
expect(result.current.data?.response.status).toEqual(200)
expect(result.current.data?.batch_job).toEqual(
expect.objectContaining({
...fixtures.get("batch_job"),
...batch,
})
)
})
})
describe("useAdminCancelBatchJob hook", () => {
test("cancels a batch job and returns it", async () => {
const { result, waitFor } = renderHook(
() => useAdminCancelBatchJob(fixtures.get("batch_job").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate()
await waitFor(() => result.current.isSuccess)
expect(result.current.data?.response.status).toEqual(200)
expect(result.current.data?.batch_job).toEqual(
expect.objectContaining({
...fixtures.get("batch_job"),
})
)
})
})
describe("useAdminConfirmBatchJob hook", () => {
test("confirms a batch job and returns it", async () => {
const { result, waitFor } = renderHook(
() => useAdminConfirmBatchJob(fixtures.get("batch_job").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate()
await waitFor(() => result.current.isSuccess)
expect(result.current.data?.response.status).toEqual(200)
expect(result.current.data?.batch_job).toEqual(
expect.objectContaining({
...fixtures.get("batch_job"),
})
)
})
})
|
3,733 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/batch-jobs/queries.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import { useAdminBatchJob, useAdminBatchJobs } from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminBatchJobs hook", () => {
test("returns a list of batch job", async () => {
const batchJobs = fixtures.list("batch_job")
const { result, waitFor } = renderHook(() => useAdminBatchJobs(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response?.status).toEqual(200)
expect(result.current.batch_jobs).toEqual(batchJobs)
})
})
describe("useAdminBatchJob hook", () => {
test("returns a batch job", async () => {
const batchJob = fixtures.get("batch_job")
const { result, waitFor } = renderHook(
() => useAdminBatchJob(batchJob.id),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response?.status).toEqual(200)
expect(result.current.batch_job).toEqual(batchJob)
})
})
|
3,734 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/claims/mutations.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import {
useAdminCancelClaim,
useAdminCancelClaimFulfillment,
useAdminCreateClaim,
useAdminCreateClaimShipment,
useAdminFulfillClaim,
useAdminUpdateClaim,
} from "../../../../src/"
import { createWrapper } from "../../../utils"
describe("useAdminCreateClaim hook", () => {
test("creates a claim for an order", async () => {
const orderId = fixtures.get("order").id
const claim = {
type: "refund" as const,
claim_items: [
{
item_id: "test-variant",
quantity: 1,
},
],
}
const { result, waitFor } = renderHook(() => useAdminCreateClaim(orderId), {
wrapper: createWrapper(),
})
result.current.mutate(claim)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.order).toEqual(fixtures.get("order"))
})
})
describe("useAdminUpdateClaim hook", () => {
test("updates a claim for an order", async () => {
const orderId = fixtures.get("order").id
const claimId = "test-claim"
const claim = {
shipping_method: [
{
option_id: "test-so",
price: 1000,
},
],
}
const { result, waitFor } = renderHook(() => useAdminUpdateClaim(orderId), {
wrapper: createWrapper(),
})
result.current.mutate({
claim_id: claimId,
...claim,
})
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.order).toEqual(fixtures.get("order"))
})
})
describe("useAdminFulfillClaim hook", () => {
test("fulfills a claim", async () => {
const orderId = fixtures.get("order").id
const claimId = "test-claim"
const payload = {
no_notification: true,
}
const { result, waitFor } = renderHook(
() => useAdminFulfillClaim(orderId),
{
wrapper: createWrapper(),
}
)
result.current.mutate({
claim_id: claimId,
...payload,
})
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.order).toEqual(fixtures.get("order"))
})
})
describe("useAdminCreateClaimShipment hook", () => {
test("creates a claim shipment", async () => {
const orderId = fixtures.get("order").id
const claimId = "test-claim"
const payload = {
fulfillment_id: "test-id",
tracking_numbers: [],
}
const { result, waitFor } = renderHook(
() => useAdminCreateClaimShipment(orderId),
{
wrapper: createWrapper(),
}
)
result.current.mutate({
claim_id: claimId,
...payload,
})
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.order).toEqual(fixtures.get("order"))
})
})
describe("useAdminCancelClaim hook", () => {
test("cancels a claim for an order", async () => {
const orderId = fixtures.get("order").id
const claimId = "test-claim"
const { result, waitFor } = renderHook(() => useAdminCancelClaim(orderId), {
wrapper: createWrapper(),
})
result.current.mutate(claimId)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.order).toEqual(fixtures.get("order"))
})
})
describe("useAdminCancelClaimFulfillment hook", () => {
test("cancels a claim's fulfillment", async () => {
const orderId = fixtures.get("order").id
const claimId = "test-claim"
const fulfillmentId = "test-ful"
const { result, waitFor } = renderHook(
() => useAdminCancelClaimFulfillment(orderId),
{
wrapper: createWrapper(),
}
)
result.current.mutate({ claim_id: claimId, fulfillment_id: fulfillmentId })
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.order).toEqual(fixtures.get("order"))
})
})
|
3,735 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/collections/mutations.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import {
useAdminAddProductsToCollection,
useAdminCreateCollection,
useAdminDeleteCollection,
useAdminRemoveProductsFromCollection,
useAdminUpdateCollection,
} from "../../../../src/"
import { createWrapper } from "../../../utils"
describe("useAdminCreateCollection hook", () => {
test("creates a collection and returns it", async () => {
const collection = {
title: "test_collection",
}
const { result, waitFor } = renderHook(() => useAdminCreateCollection(), {
wrapper: createWrapper(),
})
result.current.mutate(collection)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.collection).toEqual(
expect.objectContaining({
...fixtures.get("product_collection"),
...collection,
})
)
})
})
describe("useAdminUpdateCollection hook", () => {
test("updates a collection and returns it", async () => {
const collection = {
title: "update_collection",
}
const { result, waitFor } = renderHook(
() => useAdminUpdateCollection(fixtures.get("product_collection").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(collection)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.collection).toEqual(
expect.objectContaining({
...fixtures.get("product_collection"),
...collection,
})
)
})
})
describe("useAdminDeleteCollection hook", () => {
test("deletes a collection", async () => {
const { result, waitFor } = renderHook(
() => useAdminDeleteCollection(fixtures.get("product_collection").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate()
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data).toEqual(
expect.objectContaining({
id: fixtures.get("product_collection").id,
deleted: true,
})
)
})
})
describe("useAdminAddProductsToCollection hook", () => {
test("add products to a collection", async () => {
const update = {
product_ids: [fixtures.get("product").id],
}
const { result, waitFor } = renderHook(
() =>
useAdminAddProductsToCollection(fixtures.get("product_collection").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(update)
await waitFor(() => result.current.isSuccess)
expect(result.current.data?.response.status).toEqual(200)
expect(result.current.data?.collection).toEqual(
expect.objectContaining({
...fixtures.get("product_collection"),
products: [fixtures.get("product")],
})
)
})
})
describe("useAdminRemoveProductsFromCollection hook", () => {
test("remove products from a collection", async () => {
const remove = {
product_ids: [fixtures.get("product").id],
}
const { result, waitFor } = renderHook(
() =>
useAdminRemoveProductsFromCollection(
fixtures.get("product_collection").id
),
{
wrapper: createWrapper(),
}
)
result.current.mutate(remove)
await waitFor(() => result.current.isSuccess)
expect(result.current.data?.response.status).toEqual(200)
expect(result.current.data).toEqual(
expect.objectContaining({
id: fixtures.get("product_collection").id,
object: "product-collection",
removed_products: remove.product_ids,
})
)
})
})
|
3,736 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/collections/queries.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import { useAdminCollection, useAdminCollections } from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminCollections hook", () => {
test("returns a list of collections", async () => {
const collections = fixtures.list("product_collection")
const { result, waitFor } = renderHook(() => useAdminCollections(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.collections).toEqual(collections)
})
})
describe("useAdminCollection hook", () => {
test("returns a collection", async () => {
const collection = fixtures.get("product_collection")
const { result, waitFor } = renderHook(
() => useAdminCollection(collection.id),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.collection).toEqual(collection)
})
})
|
3,737 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/currencies/mutation.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import { useAdminUpdateCurrency } from "../../../../src/"
import { createWrapper } from "../../../utils"
describe("useAdminUpdateCurrency hook", () => {
test("updates a currency and returns it", async () => {
const update = {
includes_tax: true,
}
const { result, waitFor } = renderHook(
() => useAdminUpdateCurrency(fixtures.get("currency").code),
{
wrapper: createWrapper(),
}
)
result.current.mutate(update)
await waitFor(() => result.current.isSuccess)
expect(result.current.data?.response.status).toEqual(200)
expect(result.current.data?.currency).toEqual(
expect.objectContaining({
...fixtures.get("currency"),
...update,
})
)
})
})
|
3,738 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/currencies/queries.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import { useAdminCurrencies } from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminCurrencies hook", () => {
test("returns a list of currencies", async () => {
const currencies = fixtures.list("currency", 1)
const { result, waitFor } = renderHook(() => useAdminCurrencies(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response?.status).toEqual(200)
expect(result.current.currencies).toEqual(currencies)
})
})
|
3,739 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/customer-groups/mutations.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import {
useAdminCreateCustomerGroup,
useAdminUpdateCustomerGroup,
} from "../../../../src/"
import { createWrapper } from "../../../utils"
describe("useAdminCreateCustomerGroup hook", () => {
test("creates a customer group and returns it", async () => {
const group = {
name: "Group 1",
}
const { result, waitFor } = renderHook(
() => useAdminCreateCustomerGroup(),
{
wrapper: createWrapper(),
}
)
result.current.mutate(group)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.customer_group).toEqual(
expect.objectContaining(group)
)
})
describe("useAdminUpdateCustomerGroup hook", () => {
test("updates a customer group and returns it", async () => {
const group = {
name: "Changeed name",
}
const { result, waitFor } = renderHook(
() => useAdminUpdateCustomerGroup(fixtures.get("customer_group").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(group)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.customer_group).toEqual(
expect.objectContaining({
...fixtures.get("customer_group"),
...group,
})
)
})
})
})
|
3,740 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/customer-groups/queries.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import {
useAdminCustomerGroup,
useAdminCustomerGroupCustomers,
useAdminCustomerGroups,
} from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminCustomerGroup hook", () => {
test("returns a customer group", async () => {
const group = fixtures.get("customer_group")
const { result, waitFor } = renderHook(
() => useAdminCustomerGroup(group.id),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.customer_group).toEqual(group)
})
test("returns a list of customer groups", async () => {
const groups = fixtures.list("customer_group")
const { result, waitFor } = renderHook(() => useAdminCustomerGroups(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.customer_groups).toEqual(groups)
})
test("returns a list of customers that belong to a group", async () => {
const groups = fixtures.list("customer_group")
const customers = fixtures.list("customer")
const { result, waitFor } = renderHook(
() => useAdminCustomerGroupCustomers(groups[0].id),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.customers).toEqual(customers)
})
})
|
3,741 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/customers/mutations.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import {
useAdminCreateCustomer,
useAdminUpdateCustomer,
} from "../../../../src/"
import { createWrapper } from "../../../utils"
describe("useAdminCreateCustomer hook", () => {
test("creates a customer and returns it", async () => {
const customer = {
email: "[email protected]",
first_name: "Lebron",
last_name: "James",
password: "password",
}
const { result, waitFor } = renderHook(() => useAdminCreateCustomer(), {
wrapper: createWrapper(),
})
result.current.mutate(customer)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.customer).toEqual(
expect.objectContaining({
...fixtures.get("customer"),
...customer,
})
)
})
})
describe("useAdminUpdateCustomer hook", () => {
test("updates a customer and returns it", async () => {
const customer = {
email: "[email protected]",
first_name: "Lebron",
last_name: "James",
password: "password",
}
const { result, waitFor } = renderHook(
() => useAdminUpdateCustomer(fixtures.get("customer").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(customer)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.customer).toEqual(
expect.objectContaining({
...fixtures.get("customer"),
...customer,
})
)
})
})
|
3,742 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/customers/queries.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import { useAdminCustomer, useAdminCustomers } from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminCustomers hook", () => {
test("returns a list of customers", async () => {
const customers = fixtures.list("customer")
const { result, waitFor } = renderHook(() => useAdminCustomers(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.customers).toEqual(customers)
})
})
describe("useAdminCustomer hook", () => {
test("returns a customer", async () => {
const customer = fixtures.get("customer")
const { result, waitFor } = renderHook(
() => useAdminCustomer(customer.id),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.customer).toEqual(customer)
})
})
|
3,743 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/discounts/mutations.test.ts | import { DiscountConditionOperator } from "@medusajs/medusa"
import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import {
useAdminAddDiscountConditionResourceBatch,
useAdminCreateDiscount,
useAdminCreateDynamicDiscountCode,
useAdminDeleteDiscount,
useAdminDeleteDiscountConditionResourceBatch,
useAdminDeleteDynamicDiscountCode,
useAdminDiscountAddRegion,
useAdminDiscountCreateCondition,
useAdminDiscountRemoveCondition,
useAdminDiscountRemoveRegion,
useAdminDiscountUpdateCondition,
useAdminUpdateDiscount,
} from "../../../../src/"
import { createWrapper } from "../../../utils"
describe("useAdminDeleteDiscountConditionResourceBatch hook", () => {
test("delete items from a discount condition and return the discount", async () => {
const resources = [
{
id: fixtures.get("product").id,
},
]
const discountId = fixtures.get("discount").id
const conditionId = fixtures.get("discount").rule.conditions[0].id
const { result, waitFor } = renderHook(
() =>
useAdminDeleteDiscountConditionResourceBatch(discountId, conditionId),
{
wrapper: createWrapper(),
}
)
result.current.mutate({
resources,
})
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.discount).toEqual(
expect.objectContaining({
...fixtures.get("discount"),
rule: {
...fixtures.get("discount").rule,
conditions: [
{
...fixtures.get("discount").rule.conditions[0],
products: [],
},
],
},
})
)
})
})
describe("useAdminAddDiscountConditionResourceBatch hook", () => {
test("add items to a discount condition and return the discount", async () => {
const resources = [
{
id: fixtures.get("product").id,
},
]
const discountId = fixtures.get("discount").id
const conditionId = fixtures.get("discount").rule.conditions[0].id
const { result, waitFor } = renderHook(
() => useAdminAddDiscountConditionResourceBatch(discountId, conditionId),
{
wrapper: createWrapper(),
}
)
result.current.mutate({ resources })
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.discount).toEqual(
expect.objectContaining({
...fixtures.get("discount"),
rule: {
...fixtures.get("discount").rule,
conditions: [
{
...fixtures.get("discount").rule.conditions[0],
products: [
...(fixtures.get("discount").rule.conditions[0]?.products ??
[]),
{ id: fixtures.get("product").id },
],
},
],
},
})
)
})
})
describe("useAdminCreateDiscount hook", () => {
test("creates a discount and returns it", async () => {
const discount = {
code: "DISC",
rule: {
type: "percentage",
value: 10,
allocation: "total",
},
is_dynamic: false,
is_disabled: false,
}
const { result, waitFor } = renderHook(() => useAdminCreateDiscount(), {
wrapper: createWrapper(),
})
result.current.mutate(discount)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.discount).toEqual(
expect.objectContaining({
...fixtures.get("discount"),
...discount,
})
)
})
})
describe("useAdminUpdateDiscount hook", () => {
test("updates a discount and returns it", async () => {
const discount = {
code: "SUMMER10",
}
const { result, waitFor } = renderHook(
() => useAdminUpdateDiscount(fixtures.get("discount").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(discount)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.discount).toEqual(
expect.objectContaining({
...fixtures.get("discount"),
...discount,
})
)
})
})
describe("useAdminDeleteDiscount hook", () => {
test("updates a discount and returns it", async () => {
const id = fixtures.get("discount").id
const { result, waitFor } = renderHook(() => useAdminDeleteDiscount(id), {
wrapper: createWrapper(),
})
result.current.mutate()
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data).toEqual(
expect.objectContaining({
id,
deleted: true,
})
)
})
})
describe("useAdminDiscountAddRegion hook", () => {
test("adds a region to the discount", async () => {
const id = fixtures.get("discount").id
const { result, waitFor } = renderHook(
() => useAdminDiscountAddRegion(id),
{
wrapper: createWrapper(),
}
)
result.current.mutate("test-region")
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.discount).toEqual(
expect.objectContaining(fixtures.get("discount"))
)
})
})
describe("useAdminCreateDynamicDiscountCode hook", () => {
test("creates a dynamic discount code", async () => {
const discount = {
code: "LUCKY10",
usage_limit: 10,
}
const { result, waitFor } = renderHook(
() => useAdminCreateDynamicDiscountCode(fixtures.get("discount").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(discount)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.discount).toEqual(
expect.objectContaining({
...fixtures.get("discount"),
...discount,
})
)
})
})
describe("useAdminDiscountRemoveRegion hook", () => {
test("adds a region to the discount", async () => {
const id = fixtures.get("discount").id
const { result, waitFor } = renderHook(
() => useAdminDiscountRemoveRegion(id),
{
wrapper: createWrapper(),
}
)
result.current.mutate("test-region")
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.discount).toEqual(
expect.objectContaining(fixtures.get("discount"))
)
})
})
describe("useAdminDeleteDynamicDiscountCode hook", () => {
test("creates a dynamic discount code", async () => {
const id = fixtures.get("discount").id
const { result, waitFor } = renderHook(
() => useAdminDeleteDynamicDiscountCode(fixtures.get("discount").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate("LUCKY10")
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.discount).toEqual(
expect.objectContaining(fixtures.get("discount"))
)
})
})
describe("useAdminDiscountCreateCondition hook", () => {
test("Creates a condition from a discount", async () => {
const id = fixtures.get("discount").id
const conditionId = fixtures.get("discount").rule.conditions[0].id
const { result, waitFor } = renderHook(
() => useAdminDiscountCreateCondition(id),
{
wrapper: createWrapper(),
}
)
result.current.mutate({
operator: DiscountConditionOperator.IN,
products: ["test-product"],
})
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.discount).toEqual(fixtures.get("discount"))
})
})
describe("useAdminDiscountUpdateCondition hook", () => {
test("Updates condition for discount", async () => {
const id = fixtures.get("discount").id
const conditionId = fixtures.get("discount").rule.conditions[0].id
const { result, waitFor } = renderHook(
() => useAdminDiscountUpdateCondition(id, conditionId),
{
wrapper: createWrapper(),
}
)
result.current.mutate({ products: ["test-product"] })
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.discount).toEqual(fixtures.get("discount"))
})
})
describe("useAdminDiscountRemoveCondition hook", () => {
test("removes a condition from a discount", async () => {
const id = fixtures.get("discount").id
const conditionId = fixtures.get("discount").rule.conditions[0].id
const { result, waitFor } = renderHook(
() => useAdminDiscountRemoveCondition(id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(conditionId)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.id).toEqual(conditionId)
})
})
|
3,744 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/discounts/queries.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import {
useAdminDiscount,
useAdminDiscounts,
useAdminGetDiscountByCode,
useAdminGetDiscountCondition,
} from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminDiscounts hook", () => {
test("returns a list of discounts", async () => {
const discounts = fixtures.list("discount")
const { result, waitFor } = renderHook(() => useAdminDiscounts(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.discounts).toEqual(discounts)
})
})
describe("useAdminGetDiscountByCode hook", () => {
test("retrieves a discount by discount code", async () => {
const discount = fixtures.get("discount")
const { result, waitFor } = renderHook(
() => useAdminGetDiscountByCode("10DISC"),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.discount).toEqual(discount)
})
})
describe("useAdminDiscount hook", () => {
test("returns a discount", async () => {
const discount = fixtures.get("discount")
const { result, waitFor } = renderHook(
() => useAdminDiscount(discount.id),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.discount).toEqual(discount)
})
})
describe("useAdminGetDiscountCondition hook", () => {
test("returns a discount condition", async () => {
const discount = fixtures.get("discount")
const { result, waitFor } = renderHook(
() =>
useAdminGetDiscountCondition(
discount.id,
discount.rule.conditions[0].id
),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.discount_condition).toEqual(
discount.rule.conditions[0]
)
})
})
|
3,745 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/draft-orders/mutations.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import {
useAdminCreateDraftOrder,
useAdminDeleteDraftOrder,
useAdminDraftOrderAddLineItem,
useAdminDraftOrderRegisterPayment,
useAdminDraftOrderRemoveLineItem,
useAdminDraftOrderUpdateLineItem,
useAdminUpdateDraftOrder,
} from "../../../../src/"
import { createWrapper } from "../../../utils"
describe("useAdminCreateDraftOrder hook", () => {
test("creates a draft order and returns it", async () => {
const draftOrder = {
email: "[email protected]",
items: [
{
variant_id: "variant_01FGKMYKJVY3DYDZWCRB2GZS0G",
quantity: 1,
},
],
shipping_methods: [
{
option_id: "opt_01FGKMYKJWQZCZANRNHR3XVRN3",
price: 0,
},
],
region_id: "reg_01FGKMYKKG6ACZANRNHR3XVRN3",
}
const { result, waitFor } = renderHook(() => useAdminCreateDraftOrder(), {
wrapper: createWrapper(),
})
result.current.mutate(draftOrder)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.draft_order).toEqual(
expect.objectContaining({
...fixtures.get("draft_order"),
...draftOrder,
})
)
})
})
describe("useAdminUpdateDraftOrder hook", () => {
test("updates a draft order and returns it", async () => {
const id = fixtures.get("draft_order").id
const draftOrder = {
country_code: "dk",
}
const { result, waitFor } = renderHook(() => useAdminUpdateDraftOrder(id), {
wrapper: createWrapper(),
})
result.current.mutate(draftOrder)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.draft_order).toEqual(
expect.objectContaining({
...fixtures.get("draft_order"),
...draftOrder,
})
)
})
})
describe("useAdminDeleteDraftOrder hook", () => {
test("deletes a draft order", async () => {
const id = fixtures.get("draft_order").id
const { result, waitFor } = renderHook(() => useAdminDeleteDraftOrder(id), {
wrapper: createWrapper(),
})
result.current.mutate()
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data).toEqual(
expect.objectContaining({
id,
deleted: true,
})
)
})
})
describe("useAdminDraftOrderAddLineItem hook", () => {
test("adds a line item to a draft order", async () => {
const id = fixtures.get("draft_order").id
const lineItem = {
quantity: 2,
variant_id: "test-variant",
}
const { result, waitFor } = renderHook(
() => useAdminDraftOrderAddLineItem(id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(lineItem)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.draft_order).toEqual(fixtures.get("draft_order"))
})
})
describe("useAdminDraftOrderUpdateLineItem hook", () => {
test("updates a draft order's line item", async () => {
const id = fixtures.get("draft_order").id
const lineItemId = "test-li"
const newLineItem = {
quantity: 1,
variant_id: "test-variant",
}
const { result, waitFor } = renderHook(
() => useAdminDraftOrderUpdateLineItem(id),
{
wrapper: createWrapper(),
}
)
result.current.mutate({
item_id: lineItemId,
...newLineItem,
})
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.draft_order).toEqual(fixtures.get("draft_order"))
})
})
describe("useAdminDraftOrderRemoveLineItem hook", () => {
test("delete a draft order's line item", async () => {
const id = fixtures.get("draft_order").id
const lineItemId = "test-li"
const { result, waitFor } = renderHook(
() => useAdminDraftOrderRemoveLineItem(id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(lineItemId)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.draft_order).toEqual(fixtures.get("draft_order"))
})
})
describe("useAdminDraftOrderRegisterPayment hook", () => {
test("marks a draft order as paid", async () => {
const id = fixtures.get("draft_order").id
const { result, waitFor } = renderHook(
() => useAdminDraftOrderRegisterPayment(id),
{
wrapper: createWrapper(),
}
)
result.current.mutate()
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.order).toEqual(fixtures.get("order"))
})
})
|
3,746 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/draft-orders/queries.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import { useAdminDraftOrder, useAdminDraftOrders } from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminDraftOrders hook", () => {
test("returns a list of draft orders", async () => {
const draftOrders = fixtures.list("draft_order")
const { result, waitFor } = renderHook(() => useAdminDraftOrders(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.draft_orders).toEqual(draftOrders)
})
})
describe("useAdminDraftOrder hook", () => {
test("returns a draft order", async () => {
const draftOrder = fixtures.get("draft_order")
const { result, waitFor } = renderHook(
() => useAdminDraftOrder(draftOrder.id),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.draft_order).toEqual(draftOrder)
})
})
|
3,747 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/gift-cards/mutations.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import {
useAdminCreateGiftCard,
useAdminDeleteGiftCard,
useAdminUpdateGiftCard,
} from "../../../../src/"
import { createWrapper } from "../../../utils"
describe("useAdminCreateGiftCard hook", () => {
test("creates a gift card and returns it", async () => {
const gc = {
value: 1000,
region_id: "test-id",
}
const { result, waitFor } = renderHook(() => useAdminCreateGiftCard(), {
wrapper: createWrapper(),
})
result.current.mutate(gc)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.gift_card).toEqual(
expect.objectContaining({
...fixtures.get("gift_card"),
...gc,
})
)
})
})
describe("useAdminUpdateGiftCard hook", () => {
test("updates a gift card and returns it", async () => {
const gc = {
value: 2000,
region_id: "test-region",
}
const { result, waitFor } = renderHook(
() => useAdminUpdateGiftCard(fixtures.get("gift_card").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(gc)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.gift_card).toEqual(
expect.objectContaining({
...fixtures.get("gift_card"),
...gc,
})
)
})
})
describe("useAdminDeleteGiftCard hook", () => {
test("deletes a gift card", async () => {
const { result, waitFor } = renderHook(
() => useAdminDeleteGiftCard(fixtures.get("gift_card").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate()
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data).toEqual(
expect.objectContaining({
id: fixtures.get("gift_card").id,
deleted: true,
})
)
})
})
|
3,748 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/gift-cards/queries.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import { useAdminGiftCard, useAdminGiftCards } from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminGiftCards hook", () => {
test("returns a list of giftCards", async () => {
const giftCards = fixtures.list("gift_card")
const { result, waitFor } = renderHook(() => useAdminGiftCards(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.gift_cards).toEqual(giftCards)
})
})
describe("useAdminGiftCard hook", () => {
test("returns a giftCard", async () => {
const giftCard = fixtures.get("gift_card")
const { result, waitFor } = renderHook(
() => useAdminGiftCard(giftCard.id),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.gift_card).toEqual(giftCard)
})
})
|
3,749 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/inventory-items/mutations.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import {
useAdminCreateLocationLevel,
useAdminDeleteInventoryItem,
useAdminDeleteLocationLevel,
useAdminUpdateInventoryItem,
useAdminUpdateLocationLevel,
} from "../../../../src/"
import { createWrapper } from "../../../utils"
describe("useAdminUpdateInventoryItem hook", () => {
test("updates an inventory item", async () => {
const payload = {
sku: "test-sku",
}
const { result, waitFor } = renderHook(
() => useAdminUpdateInventoryItem("inventory-item-id"),
{
wrapper: createWrapper(),
}
)
result.current.mutate(payload)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.inventory_item).toEqual(
expect.objectContaining({
id: "inventory-item-id",
sku: "test-sku",
})
)
})
})
describe("useAdminDeleteInventoryItem hook", () => {
test("Deletes an inventory item", async () => {
const { result, waitFor } = renderHook(
() => useAdminDeleteInventoryItem("inventory-item-id"),
{
wrapper: createWrapper(),
}
)
result.current.mutate()
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data).toEqual(
expect.objectContaining({
id: "inventory-item-id",
deleted: true,
})
)
})
})
describe("useAdminUpdateLocationLevel hook", () => {
test("Updates a location level", async () => {
const payload = {
incoming_quantity: 10,
}
const { result, waitFor } = renderHook(
() => useAdminUpdateLocationLevel("inventory-item-id"),
{
wrapper: createWrapper(),
}
)
result.current.mutate({ ...payload, stockLocationId: "location_id" })
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.inventory_item).toEqual(
expect.objectContaining({
id: "inventory-item-id",
location_levels: [
expect.objectContaining({
incoming_quantity: 10,
}),
],
})
)
})
})
describe("useAdminDeleteLocationLevel hook", () => {
test("removes a location level", async () => {
const { result, waitFor } = renderHook(
() => useAdminDeleteLocationLevel("inventory-item-id"),
{
wrapper: createWrapper(),
}
)
result.current.mutate("location_id")
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.inventory_item).toEqual(
expect.objectContaining({
id: "inventory-item-id",
location_levels: [],
})
)
})
})
describe("useAdminCreateLocationLevel hook", () => {
test("creates a location level", async () => {
const payload = {
location_id: "loc_1",
incoming_quantity: 10,
stocked_quantity: 10,
}
const { result, waitFor } = renderHook(
() => useAdminCreateLocationLevel("inventory-item-id"),
{
wrapper: createWrapper(),
}
)
result.current.mutate(payload)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.inventory_item).toEqual(
expect.objectContaining({
id: "inventory-item-id",
location_levels: expect.arrayContaining([
expect.objectContaining({ ...payload }),
]),
})
)
})
})
|
3,750 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/inventory-items/queries.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import {
useAdminInventoryItem,
useAdminInventoryItemLocationLevels,
useAdminInventoryItems,
useAdminPriceList,
} from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminInventoryItems hook", () => {
test("returns a list of inventory items", async () => {
const inventoryItems = fixtures.list("inventory_item")
const { result, waitFor } = renderHook(() => useAdminInventoryItems(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.inventory_items).toEqual(inventoryItems)
})
})
describe("useAdminInventoryItem hook", () => {
test("returns a single inventory item", async () => {
const inventoryItem = fixtures.get("inventory_item")
const { result, waitFor } = renderHook(
() => useAdminInventoryItem(inventoryItem.id),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.inventory_item).toEqual(inventoryItem)
})
})
describe("useAdminInventoryItem hook", () => {
test("returns a location levels for an inventory item", async () => {
const inventoryItem = fixtures.get("inventory_item")
const { result, waitFor } = renderHook(
() => useAdminInventoryItemLocationLevels(inventoryItem.id),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.inventory_item).toEqual(inventoryItem)
})
})
describe("useAdminPriceList hook", () => {
test("returns a price list", async () => {
const priceList = fixtures.get("price_list")
const { result, waitFor } = renderHook(
() => useAdminPriceList(priceList.id),
{
wrapper: createWrapper(),
}
)
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.price_list).toEqual(priceList)
})
})
|
3,751 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/invites/mutations.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import {
useAdminAcceptInvite,
useAdminCreateInvite,
useAdminDeleteInvite,
useAdminResendInvite,
} from "../../../../src/"
import { createWrapper } from "../../../utils"
describe("useAdminAcceptInvite hook", () => {
test("accepts an invite", async () => {
const payload = {
token: "test-token",
user: {
first_name: "zak",
last_name: "medusa",
password: "test-password",
},
}
const { result, waitFor } = renderHook(() => useAdminAcceptInvite(), {
wrapper: createWrapper(),
})
result.current.mutate(payload)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
})
})
describe("useAdminCreateInvite hook", () => {
test("creates an invite", async () => {
const payload = {
user: "test-id",
role: "admin" as const,
}
const { result, waitFor } = renderHook(() => useAdminCreateInvite(), {
wrapper: createWrapper(),
})
result.current.mutate(payload)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
})
})
describe("useAdminDeleteInvite hook", () => {
test("deletes an invite", async () => {
const { result, waitFor } = renderHook(
() => useAdminDeleteInvite("test-invite"),
{
wrapper: createWrapper(),
}
)
result.current.mutate()
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data).toEqual(
expect.objectContaining({
id: "test-invite",
deleted: true,
})
)
})
})
describe("useAdminResend hook", () => {
test("resends an invite", async () => {
const { result, waitFor } = renderHook(
() => useAdminResendInvite("test-invite"),
{
wrapper: createWrapper(),
}
)
result.current.mutate()
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
})
})
|
3,752 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/invites/queries.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import { useAdminInvites } from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminInvites hook", () => {
test("returns a list of invites", async () => {
const invites = fixtures.list("invite")
const { result, waitFor } = renderHook(() => useAdminInvites(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.invites).toEqual(invites)
})
})
|
3,753 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/notes/mutations.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import {
useAdminCreateNote,
useAdminDeleteNote,
useAdminUpdateNote,
} from "../../../../src/"
import { createWrapper } from "../../../utils"
describe("useAdminCreateNote hook", () => {
test("creates a note and returns it", async () => {
const note = {
value: "talked to customer",
resource_id: "test-swap",
resource_type: "swap",
}
const { result, waitFor } = renderHook(() => useAdminCreateNote(), {
wrapper: createWrapper(),
})
result.current.mutate(note)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.note).toEqual(
expect.objectContaining({
...fixtures.get("note"),
...note,
})
)
})
})
describe("useAdminUpdateNote hook", () => {
test("updates a note and returns it", async () => {
const note = {
value: "problem with the supplier",
resource_id: "test-return",
resource_type: "return",
}
const { result, waitFor } = renderHook(
() => useAdminUpdateNote(fixtures.get("note").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate(note)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.note).toEqual(
expect.objectContaining({
...fixtures.get("note"),
...note,
})
)
})
})
describe("useAdminDeleteNote hook", () => {
test("deletes a note", async () => {
const { result, waitFor } = renderHook(
() => useAdminDeleteNote(fixtures.get("note").id),
{
wrapper: createWrapper(),
}
)
result.current.mutate()
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data).toEqual(
expect.objectContaining({
id: fixtures.get("note").id,
deleted: true,
})
)
})
})
|
3,754 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/notes/queries.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import { useAdminNote, useAdminNotes } from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminNotes hook", () => {
test("returns a list of notes", async () => {
const notes = fixtures.list("note")
const { result, waitFor } = renderHook(() => useAdminNotes(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.notes).toEqual(notes)
})
})
describe("useAdminNote hook", () => {
test("returns a note", async () => {
const note = fixtures.get("note")
const { result, waitFor } = renderHook(() => useAdminNote(note.id), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.note).toEqual(note)
})
})
|
3,755 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/notifications/mutations.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import { useAdminResendNotification } from "../../../../src/"
import { createWrapper } from "../../../utils"
describe("useAdminResendNotification hook", () => {
test("resends a notification", async () => {
const notif = {
to: "[email protected]",
}
const { result, waitFor } = renderHook(
() => useAdminResendNotification("test-notification"),
{
wrapper: createWrapper(),
}
)
result.current.mutate(notif)
await waitFor(() => result.current.isSuccess)
expect(result.current.data.response.status).toEqual(200)
expect(result.current.data.notification).toEqual(
expect.objectContaining({
...fixtures.get("notification"),
...notif,
id: "test-notification",
})
)
})
})
|
3,756 | 0 | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin | petrpan-code/medusajs/medusa/packages/medusa-react/test/hooks/admin/notifications/queries.test.ts | import { renderHook } from "@testing-library/react-hooks/dom"
import { fixtures } from "../../../../mocks/data"
import { useAdminNotifications } from "../../../../src"
import { createWrapper } from "../../../utils"
describe("useAdminNotifications hook", () => {
test("returns a list of notifications", async () => {
const notifications = fixtures.list("notification")
const { result, waitFor } = renderHook(() => useAdminNotifications(), {
wrapper: createWrapper(),
})
await waitFor(() => result.current.isSuccess)
expect(result.current.response.status).toEqual(200)
expect(result.current.notifications).toEqual(notifications)
})
})
|
Subsets and Splits