blob: 34d2cc74e3816c7e5e130c6ce250f91c4e92ac76 [file] [log] [blame] [raw]
import { RouteAPI } from '../lib/handlers/route-api';
import { fs } from './utils';
describe('Basic unfurls', () => {
const router = null;
let config;
let routeApi;
before(() => {
config = {
ceProps: () => {},
clientOptionsHandler: {
options: {
urlShortenService: 'memory',
},
},
storageHandler: {
expandId: async (id) => {
const json = await fs.readFile('test/state/' + id + '.json');
return {
config: json,
};
},
incrementViewCount: async () => {},
},
};
});
it('Too much editors to meta', async () => {
const prom = new Promise((resolve, reject) => {
config.renderGoldenLayout = (config, metadata) => {
resolve({metadata});
};
routeApi = new RouteAPI(router, config);
routeApi.apiHandler = {
languages: {
'c++': {
name: 'C++',
},
},
compilers: [],
};
routeApi.storedStateHandler({ params: { id: '../example-states/default-state' }}, null, () => { reject('Error in test'); });
});
const res = await prom;
res.metadata.should.deep.equal({
ogAuthor: null,
ogDescription: '',
ogTitle: 'Compiler Explorer',
});
});
it('Just one editor', async () => {
const prom = new Promise((resolve, reject) => {
config.renderGoldenLayout = (config, metadata) => {
resolve({metadata});
};
routeApi = new RouteAPI(router, config);
routeApi.apiHandler = {
languages: {
'c++': {
name: 'C++',
},
},
compilers: [],
};
routeApi.storedStateHandler({ params: { id: 'andthekitchensink' }}, null, () => { reject('Error in test'); });
});
const res = await prom;
res.metadata.should.deep.equal({
ogAuthor: null,
ogDescription: '\ntemplate<typename T>\nconcept TheSameAndAddable = requires(T a, T b) {\n {a+b} -> T;\n};\n\ntemplate<TheSameAndAddable T>\nT sum(T x, T y) {\n return x + y;\n}\n\n#include <string>\n\nint main() {\n int z = 0;\n int w;\n\n return sum(z, w);\n}\n',
ogTitle: 'Compiler Explorer - C++',
});
});
it('Tree things', async () => {
const prom = new Promise((resolve, reject) => {
config.renderGoldenLayout = (config, metadata) => {
resolve({metadata});
};
routeApi = new RouteAPI(router, config);
routeApi.apiHandler = {
languages: {
'c++': {
name: 'C++',
},
},
compilers: [],
};
routeApi.storedStateHandler({ params: { id: 'tree-gl' }}, null, () => { reject('Error in test'); });
});
const res = await prom;
res.metadata.should.deep.equal({
ogAuthor: null,
ogDescription: 'project(hello)\n\nadd_executable(output.s\n example.cpp\n square.cpp)\n',
ogTitle: 'Compiler Explorer - C++',
});
});
});