|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import assert from 'node:assert/strict'; |
| 21 | +import { test } from 'node:test'; |
| 22 | +import { |
| 23 | + aboutChannelFacts, |
| 24 | + aboutUpdateStatusDetail, |
| 25 | +} from '../../renderer/settings/about-update-status.js'; |
| 26 | +import { getSettingsPreferencesCopy } from '../../renderer/locales/settings-preferences-copy.js'; |
| 27 | + |
| 28 | +const copy = getSettingsPreferencesCopy('zh').about; |
| 29 | + |
| 30 | +test('a packaged nightly is tokened Nightly, never 正式版', () => { |
| 31 | + const facts = aboutChannelFacts({ buildMode: 'packaged', updateChannel: 'nightly' }, copy); |
| 32 | + assert.deepEqual(facts.token, { label: 'Nightly', color: 'orange' }); |
| 33 | + assert.match(facts.summary, /会覆盖正式版安装/); |
| 34 | +}); |
| 35 | + |
| 36 | +test('a packaged release wears no token — it is the default state', () => { |
| 37 | + const facts = aboutChannelFacts({ buildMode: 'packaged', updateChannel: 'release' }, copy); |
| 38 | + assert.equal(facts.token, null); |
| 39 | + assert.equal(facts.summary, '正式发布版,自动接收稳定更新。'); |
| 40 | +}); |
| 41 | + |
| 42 | +test('buildMode decides before updateChannel, whose dev value is a placeholder', () => { |
| 43 | + const facts = aboutChannelFacts({ buildMode: 'dev', updateChannel: 'nightly' }, copy); |
| 44 | + assert.deepEqual(facts.token, { label: '本地开发版', color: 'gray' }); |
| 45 | + assert.equal(facts.summary, '本地开发构建,不检查更新。'); |
| 46 | +}); |
| 47 | + |
| 48 | +test('the nightly steady states each read as themselves', () => { |
| 49 | + const detail = (status: Parameters<typeof aboutUpdateStatusDetail>[0]) => |
| 50 | + aboutUpdateStatusDetail(status, copy); |
| 51 | + |
| 52 | + assert.equal( |
| 53 | + detail({ |
| 54 | + state: 'downloading', |
| 55 | + currentVersion: '0.2.0-dev.11.20260831', |
| 56 | + latestVersion: '0.2.0-dev.12.20260901', |
| 57 | + progress: { percent: 42.4, bytesPerSecond: 1, transferred: 1, total: 2 }, |
| 58 | + }), |
| 59 | + '正在下载 v0.2.0-dev.12.20260901(42%)…', |
| 60 | + ); |
| 61 | + assert.equal( |
| 62 | + detail({ |
| 63 | + state: 'verifying', |
| 64 | + currentVersion: '0.2.0-dev.11.20260831', |
| 65 | + latestVersion: '0.2.0-dev.12.20260901', |
| 66 | + }), |
| 67 | + '正在验证 v0.2.0-dev.12.20260901 的发布来源…', |
| 68 | + ); |
| 69 | + assert.equal( |
| 70 | + detail({ |
| 71 | + state: 'downloaded', |
| 72 | + currentVersion: '0.2.0-dev.11.20260831', |
| 73 | + latestVersion: '0.2.0-dev.12.20260901', |
| 74 | + }), |
| 75 | + 'v0.2.0-dev.12.20260901 已下载,可在侧栏选择重启安装。', |
| 76 | + ); |
| 77 | +}); |
0 commit comments