import 'package:flutter_test/flutter_test.dart'; import 'package:yx_only_office_flutter/src/onlyoffice_config.dart'; import 'package:yx_only_office_flutter/src/onlyoffice_html_builder.dart'; void main() { group('OnlyOfficeHtmlBuilder', () { test('normalizes server URL and injects config JSON', () { final config = OnlyOfficeConfig( document: const OnlyOfficeDocument( fileType: 'docx', key: 'abc', title: 'demo', url: 'https://example.com/demo.docx', ), documentType: 'text', editorConfig: const OnlyOfficeEditorConfig(mode: 'view', lang: 'zh-CN'), type: 'mobile', token: 'token', ); final html = OnlyOfficeHtmlBuilder.build( serverUrl: 'https://document.23544.com/', config: config, ); expect( html.contains( 'src="https://document.23544.com/web-apps/apps/api/documents/api.js"', ), isTrue, ); expect(html.contains(config.toJsonString()), isTrue); expect(html.contains('OnlyOfficeChannel'), isTrue); }); test('wraps user-defined events instead of overwriting them', () { final config = OnlyOfficeConfig( document: const OnlyOfficeDocument( fileType: 'pptx', key: 'k', title: 'slides', url: 'https://example.com/slides.pptx', ), documentType: 'presentation', editorConfig: const OnlyOfficeEditorConfig(), type: 'desktop', extra: const { 'events': {'onError': 'noop'}, }, ); final html = OnlyOfficeHtmlBuilder.build( serverUrl: 'https://doc.example.com', config: config, ); expect(html.contains('var userEvents = config.events || {};'), isTrue); expect(html.contains('wrapEvent(userEvents.onError'), isTrue); expect( html.contains("Object.assign({}, userEvents, bridgeEvents)"), isTrue, ); }); test('trims whitespace when normalizing URLs', () { expect( OnlyOfficeHtmlBuilder.normalizeServerUrl( ' https://document.23544.com/ ', ), equals('https://document.23544.com'), ); }); }); }